From fed45fe662cb010d494da8eefad61493e9f4d534 Mon Sep 17 00:00:00 2001 From: Graeme Arthur Date: Tue, 17 Dec 2024 10:51:44 +0100 Subject: [PATCH] Don't prompt to switch when 1 device --- ...cSettingsViewController+SyncDelegate.swift | 34 +++++++++++-------- DuckDuckGo/SyncSettingsViewController.swift | 6 +++- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift b/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift index 5aebe9dc68..70a8635dcb 100644 --- a/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift +++ b/DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift @@ -183,26 +183,13 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate { } @MainActor - func handlePairingTwoSeparateAccounts(recoveryKey: SyncCode.RecoveryKey) { + func promptToSwitchAccounts(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 - } + self?.switchAccounts(recoveryKey: recoveryKey) } alertController.addAction(title: UserText.actionCancel, style: .cancel) // Gives time to the is syncing view to appear @@ -213,6 +200,23 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate { } } + func switchAccounts(recoveryKey: SyncCode.RecoveryKey) { + 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 + } + } + 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 083573db36..09104e42c7 100644 --- a/DuckDuckGo/SyncSettingsViewController.swift +++ b/DuckDuckGo/SyncSettingsViewController.swift @@ -361,7 +361,11 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate { return true } catch { if self.rootView.model.isSyncEnabled { - handlePairingTwoSeparateAccounts(recoveryKey: recoveryKey) + if rootView.model.devices.count > 1 { + promptToSwitchAccounts(recoveryKey: recoveryKey) + } else { + switchAccounts(recoveryKey: recoveryKey) + } } else { handleError(.unableToSyncToServer, error: error, event: .syncLoginError) }