Skip to content

Commit

Permalink
Don't prompt to switch when 1 device
Browse files Browse the repository at this point in the history
  • Loading branch information
graeme committed Dec 17, 2024
1 parent b904c68 commit 67ffec9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
14 changes: 11 additions & 3 deletions DuckDuckGo/Preferences/Model/SyncPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,12 @@ extension SyncPreferences: ManagementDialogModelDelegate {
try await loginAndShowPresentedDialog(recoveryKey, isRecovery: fromRecoveryScreen)
} catch {
if case SyncError.accountAlreadyExists = error {
managementDialogModel.shouldShowSwitchAccountsMessage = true
if devices.count > 1 {
managementDialogModel.shouldShowSwitchAccountsMessage = true
} else {
switchAccounts(recoveryKey: recoveryKey)
managementDialogModel.endFlow()
}
PixelKit.fire(DebugEvent(GeneralPixel.syncLoginExistingAccountError(error: error)))
} else {
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToSyncToOtherDevice)
Expand Down Expand Up @@ -760,10 +765,14 @@ extension SyncPreferences: ManagementDialogModelDelegate {
recoverDevice(recoveryCode: code, fromRecoveryScreen: fromRecoveryScreen)
}

func switchSync(recoveryCode: String) {
func switchAccounts(recoveryCode: String) {
guard let recoveryKey = try? SyncCode.decodeBase64String(recoveryCode).recovery else {
return
}
switchAccounts(recoveryKey: recoveryKey)
}

func switchAccounts(recoveryKey: SyncCode.RecoveryKey) {
Task { [weak self] in
guard let self else { return }
do {
Expand All @@ -782,5 +791,4 @@ extension SyncPreferences: ManagementDialogModelDelegate {
// TODO: Send sync_user_switched_account_pixel
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol ManagementDialogModelDelegate: AnyObject {
func enterRecoveryCodePressed()
func copyCode()
func openSystemPasswordSettings()
func switchSync(recoveryCode: String)
func switchAccounts(recoveryCode: String)
}

public final class ManagementDialogModel: ObservableObject {
Expand Down Expand Up @@ -64,9 +64,9 @@ public final class ManagementDialogModel: ObservableObject {
currentDialog = nil
}

public func switchSyncAccounts(recoveryCode: String) {
public func switchAccounts(recoveryCode: String) {
shouldShowSwitchAccountsMessage = false
delegate?.switchSync(recoveryCode: recoveryCode)
delegate?.switchAccounts(recoveryCode: recoveryCode)
endFlow()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public struct ManagementDialog: View {
title: Text(UserText.syncAlertSwitchAccountTitle),
message: Text(UserText.syncAlertSwitchAccountMessage),
primaryButton: .default(Text(UserText.syncAlertSwitchAccountButton)) {
model.switchSyncAccounts(recoveryCode: recoveryCodeModel.recoveryCode)
model.switchAccounts(recoveryCode: recoveryCodeModel.recoveryCode)
},
secondaryButton: .cancel {
model.endFlow()
Expand Down

0 comments on commit 67ffec9

Please sign in to comment.