Skip to content

Commit

Permalink
Switch sync accounts UI
Browse files Browse the repository at this point in the history
  • Loading branch information
graeme committed Dec 17, 2024
1 parent c065764 commit 82d1e4b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
31 changes: 31 additions & 0 deletions DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/SyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions DuckDuckGo/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

Expand Down

0 comments on commit 82d1e4b

Please sign in to comment.