Skip to content

Commit

Permalink
Improve readability of SyncErrorMessage assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Jan 2, 2024
1 parent 4910953 commit bbd1be5
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions DuckDuckGo/Preferences/Model/SyncPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ final class SyncPreferences: ObservableObject, SyncUI.ManagementViewModel {
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncBookmarksPaused.rawValue)
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncCredentialsPaused.rawValue)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
}
}
}
Expand Down Expand Up @@ -361,8 +360,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncBookmarksPaused.rawValue)
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncCredentialsPaused.rawValue)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
}
}
}
Expand All @@ -375,8 +373,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
managementDialogModel.endFlow()
mapDevices(devices)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToUpdateDeviceName, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToUpdateDeviceName, description: error.localizedDescription)
}
}
}
Expand Down Expand Up @@ -416,8 +413,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
Pixel.fire(.syncSignupDirect)
presentDialog(for: .saveRecoveryCode(recoveryCode ?? ""))
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToServer, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToSyncToServer, description: error.localizedDescription)
}
}
}
Expand All @@ -443,11 +439,15 @@ extension SyncPreferences: ManagementDialogModelDelegate {
} catch {
if syncService.account == nil {
if isRecovery {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToServer, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(
type: .unableToSyncToServer,
description: error.localizedDescription
)
} else {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToOtherDevice, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(
type: .unableToSyncToOtherDevice,
description: error.localizedDescription
)
}
}
}
Expand All @@ -462,17 +462,15 @@ extension SyncPreferences: ManagementDialogModelDelegate {
func recoverDevice(recoveryCode: String, fromRecoveryScreen: Bool) {
Task { @MainActor in
guard let syncCode = try? SyncCode.decodeBase64String(recoveryCode) else {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .invalidCode, description: "")
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .invalidCode, description: "")
return
}
presentDialog(for: .prepareToSync)
if let recoveryKey = syncCode.recovery {
do {
try await loginAndShowPresentedDialog(recoveryKey, isRecovery: fromRecoveryScreen)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToMergeTwoAccounts, description: "")
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToMergeTwoAccounts, description: "")
}
} else if let connectKey = syncCode.connect {
do {
Expand All @@ -494,12 +492,13 @@ extension SyncPreferences: ManagementDialogModelDelegate {
}.store(in: &cancellables)
// The UI will update when the devices list changes.
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToOtherDevice, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(
type: .unableToSyncToOtherDevice,
description: error.localizedDescription
)
}
} else {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .invalidCode, description: "")
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .invalidCode, description: "")
return
}
}
Expand Down Expand Up @@ -530,8 +529,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
do {
try data.writeFileWithProgress(to: location)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableCreateRecoveryPDF, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableCreateRecoveryPDF, description: error.localizedDescription)
}
}

Expand All @@ -545,8 +543,8 @@ extension SyncPreferences: ManagementDialogModelDelegate {
refreshDevices()
managementDialogModel.endFlow()
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToRemoveDevice, description: error.localizedDescription) }
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToRemoveDevice, description: error.localizedDescription)
}
}
}

Expand Down

0 comments on commit bbd1be5

Please sign in to comment.