summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift16
1 files changed, 15 insertions, 1 deletions
diff --git a/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift b/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift
index c7d3b7dbc7..fd5b8a5c55 100644
--- a/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift
+++ b/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift
@@ -43,7 +43,7 @@ struct StoredAccountData: Codable, Equatable {
/// Account expiry.
var expiry: Date
- /// be set `true` when account is created and be flipped to `false` when user adds more credit
+ /// Set to `true` when the account is created and flipped to `false` when the user adds more credit.
var isNew = false
/// Returns `true` if account has expired.
@@ -52,6 +52,20 @@ struct StoredAccountData: Codable, Equatable {
}
}
+extension StoredAccountData {
+ init(from decoder: Decoder) throws {
+ let container = try decoder.container(keyedBy: CodingKeys.self)
+ self.identifier = try container.decode(String.self, forKey: .identifier)
+ self.number = try container.decode(String.self, forKey: .number)
+ self.expiry = try container.decode(Date.self, forKey: .expiry)
+
+ // When the app is upgraded from 2023.3 or below, this field won't exist, and the auto synthesized init will fail.
+ // This leads to a reset of the settings. If the key isn't present, consider the account not new to avoid the issue.
+ let isNewAccount = try? container.decode(Bool.self, forKey: .isNew)
+ self.isNew = isNewAccount ?? false
+ }
+}
+
enum DeviceState: Codable, Equatable {
case loggedIn(StoredAccountData, StoredDeviceData)
case loggedOut