diff --git a/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift b/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift index 23bb29a134..5aebe9dc68 100644 --- a/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift +++ b/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift @@ -182,6 +182,37 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate { } } + @MainActor + func handlePairingTwoSeparateAccounts(recoveryKey: SyncCode.RecoveryKey) { + let alertController = UIAlertController( + title: UserText.syncAlertSwitchAccountTitle, + message: UserText.syncAlertSwitchAccountMessage, + preferredStyle: .alert) + alertController.addAction(title: UserText.syncAlertSwitchAccountButton, style: .default) { [weak self] in + Task { [weak self] in + do { + try await self?.syncService.disconnect() + } catch { + // TODO: Send sync_user_switched_logout_error pixel + } + + do { + try await self?.loginAndShowDeviceConnected(recoveryKey: recoveryKey) + } catch { + // TODO: Send sync_user_switched_login_error pixel + } + // TODO: Send sync_user_switched_account_pixel + } + } + alertController.addAction(title: UserText.actionCancel, style: .cancel) + // Gives time to the is syncing view to appear + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in + self?.dismissPresentedViewController { [weak self] in + self?.present(alertController, animated: true, completion: nil) + } + } + } + private func getErrorType(from errorString: String?) -> AsyncErrorType? { guard let errorString = errorString else { return nil diff --git a/DuckDuckGo/SyncSettingsViewController.swift b/DuckDuckGo/SyncSettingsViewController.swift index 925b291897..083573db36 100644 --- a/DuckDuckGo/SyncSettingsViewController.swift +++ b/DuckDuckGo/SyncSettingsViewController.swift @@ -361,7 +361,7 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate { return true } catch { if self.rootView.model.isSyncEnabled { - handleError(.unableToMergeTwoAccounts, error: error, event: .syncLoginExistingAccountError) + handlePairingTwoSeparateAccounts(recoveryKey: recoveryKey) } else { handleError(.unableToSyncToServer, error: error, event: .syncLoginError) } diff --git a/DuckDuckGo/UserText.swift b/DuckDuckGo/UserText.swift index 86a2337975..f0e8764ae4 100644 --- a/DuckDuckGo/UserText.swift +++ b/DuckDuckGo/UserText.swift @@ -961,6 +961,9 @@ But if you *do* want a peek under the hood, you can find more information about static let unknownErrorTryAgainMessage = NSLocalizedString("error.unknown.try.again", value: "An unknown error has occurred", comment: "Generic error message on a dialog for when the cause is not known.") public static let syncPausedAlertOkButton = NSLocalizedString("alert.sync-paused-alert-ok-button", value: "OK", comment: "Confirmation button in alert") public static let syncPausedAlertLearnMoreButton = NSLocalizedString("alert.sync-paused-alert-learn-more-button", value: "Learn More", comment: "Learn more button in alert") + public static let syncAlertSwitchAccountTitle = NSLocalizedString("alert.sync-switch-account-button", value: "Switch to a different Sync?", comment: "Switch account title in alert") + public static let syncAlertSwitchAccountMessage = NSLocalizedString("alert.sync-switch-account-message", value: "This device is already synced, are you sure you want to sync it with a different back up or device? Switching won't remove any data already synced to this.", comment: "Description for switching sync accounts when there's two") + public static let syncAlertSwitchAccountButton = NSLocalizedString("alert.sync-switch-account-button", value: "Switch Account", comment: "Switch account button in alert") public static let syncErrorAlertTitle = NSLocalizedString("alert.sync-error", value: "Sync & Backup Error", comment: "Title for sync error alert") public static let unableToSyncToServerDescription = NSLocalizedString("alert.unable-to-sync-to-server-description", value: "Unable to connect to the server.", comment: "Description for unable to sync to server error") public static let unableToSyncWithOtherDeviceDescription = NSLocalizedString("alert.unable-to-sync-with-other-device-description", value: "Unable to Sync with another device.", comment: "Description for unable to sync with another device error") diff --git a/DuckDuckGo/en.lproj/Localizable.strings b/DuckDuckGo/en.lproj/Localizable.strings index d1bf6015ea..e638685034 100644 --- a/DuckDuckGo/en.lproj/Localizable.strings +++ b/DuckDuckGo/en.lproj/Localizable.strings @@ -200,6 +200,13 @@ /* Title for alert shown when sync paused for an error */ "alert.sync-paused-title" = "Sync is Paused"; +/* Switch account button in alert + Switch account title in alert */ +"alert.sync-switch-account-button" = "Switch to a different Sync?"; + +/* Description for switching sync accounts when there's two */ +"alert.sync-switch-account-message" = "This device is already synced, are you sure you want to sync it with a different back up or device? Switching won't remove any data already synced to this."; + /* Description for alert shown when sync error occurs because of too many requests */ "alert.sync-too-many-requests-error-description" = "Sync & Backup is temporarily unavailable.";