From bbd1be51f42bfa98d11923a1620d17ed7880b62b Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Tue, 2 Jan 2024 13:52:39 +0100 Subject: [PATCH] Improve readability of SyncErrorMessage assignments --- .../Preferences/Model/SyncPreferences.swift | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/DuckDuckGo/Preferences/Model/SyncPreferences.swift b/DuckDuckGo/Preferences/Model/SyncPreferences.swift index bf32f49d6f..efdb7eed5c 100644 --- a/DuckDuckGo/Preferences/Model/SyncPreferences.swift +++ b/DuckDuckGo/Preferences/Model/SyncPreferences.swift @@ -211,8 +211,7 @@ final class SyncPreferences: ObservableObject, SyncUI.ManagementViewModel { UserDefaults.standard.set(false, forKey: UserDefaultsWrapper.Key.syncBookmarksPaused.rawValue) UserDefaults.standard.set(false, forKey: UserDefaultsWrapper.Key.syncCredentialsPaused.rawValue) } catch { - managementDialogModel.syncErrorMessage - = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription) + managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription) } } } @@ -361,8 +360,7 @@ extension SyncPreferences: ManagementDialogModelDelegate { UserDefaults.standard.set(false, forKey: UserDefaultsWrapper.Key.syncBookmarksPaused.rawValue) UserDefaults.standard.set(false, forKey: UserDefaultsWrapper.Key.syncCredentialsPaused.rawValue) } catch { - managementDialogModel.syncErrorMessage - = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription) + managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription) } } } @@ -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) } } } @@ -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) } } } @@ -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 + ) } } } @@ -462,8 +462,7 @@ 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) @@ -471,8 +470,7 @@ extension SyncPreferences: ManagementDialogModelDelegate { 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 { @@ -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 } } @@ -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) } } @@ -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) + } } }