stop migrating v1

This commit is contained in:
ivan grachev 2023-10-26 14:54:54 +03:00
parent a760c1e6f7
commit e289cc555a
6 changed files with 1 additions and 81 deletions

View File

@ -15,24 +15,6 @@ struct Defaults {
}
}
static var shouldPromptSafariForLegacyUsers: Bool {
get {
return userDefaults.bool(forKey: "shouldPromptSafariForLegacyUsers")
}
set {
userDefaults.set(newValue, forKey: "shouldPromptSafariForLegacyUsers")
}
}
static var didMigrateKeychainFromTokenaryV1: Bool {
get {
return userDefaults.bool(forKey: "didMigrateKeychainFromTokenaryV1")
}
set {
userDefaults.set(newValue, forKey: "didMigrateKeychainFromTokenaryV1")
}
}
static var reviewRequestsGoodMomentsCount: Int {
get {
return userDefaults.integer(forKey: "reviewRequestsGoodMomentsCount")

View File

@ -15,14 +15,12 @@ struct Keychain {
private enum ItemKey {
case password
case wallet(id: String)
case legacyPassword
case raw(key: String)
private static let commonPrefix = "io.tokenary.macos."
private static let walletPrefix = "wallet."
private static let fullWalletPrefix = commonPrefix + walletPrefix
private static let fullWalletPrefixCount = fullWalletPrefix.count
private static let legacyWalletPrefix = "io.tokenary.accountstorage."
var stringValue: String {
switch self {
@ -30,8 +28,6 @@ struct Keychain {
return ItemKey.commonPrefix + "password"
case let .wallet(id: id):
return ItemKey.commonPrefix + ItemKey.walletPrefix + id
case .legacyPassword:
return "io.tokenary.local.passphrase"
case let .raw(key: key):
return key
}
@ -42,10 +38,6 @@ struct Keychain {
return String(key.dropFirst(fullWalletPrefixCount))
}
static func isLegacyWallet(key: String) -> Bool {
return key.hasPrefix(legacyWalletPrefix)
}
}
var password: String? {
@ -91,20 +83,6 @@ struct Keychain {
}
}
// MARK: - Migration
func getLegacyKeystores() -> [Data] {
return allStoredItemsKeys().filter { ItemKey.isLegacyWallet(key: $0) }.compactMap { get(key: .raw(key: $0)) }
}
var legacyPassword: String? {
if let data = get(key: .legacyPassword), let password = String(data: data, encoding: .utf8) {
return password
} else {
return nil
}
}
// MARK: - Private
private func update(data: Data, key: ItemKey) throws {

View File

@ -25,26 +25,6 @@ final class WalletsManager {
try? loadWalletsFromKeychain()
}
#if os(macOS)
func migrateFromLegacyIfNeeded() {
guard !Defaults.didMigrateKeychainFromTokenaryV1 else { return }
let legacyKeystores = keychain.getLegacyKeystores()
if !legacyKeystores.isEmpty, let legacyPassword = keychain.legacyPassword {
keychain.save(password: legacyPassword)
for keystore in legacyKeystores {
_ = try? importJSON(keystore,
name: defaultWalletName,
password: legacyPassword,
newPassword: legacyPassword,
coin: .ethereum,
onlyToKeychain: true)
}
Defaults.shouldPromptSafariForLegacyUsers = true
}
Defaults.didMigrateKeychainFromTokenaryV1 = true
}
#endif
func validateWalletInput(_ input: String) -> InputValidationResult {
if Mnemonic.isValid(mnemonic: input) {
return .valid

View File

@ -30,9 +30,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
processInput(url: event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue)
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
walletsManager.migrateFromLegacyIfNeeded()
func applicationDidFinishLaunching(_ aNotification: Notification) {
agent.start()
gasService.start()
priceService.start()

View File

@ -98,7 +98,6 @@ class AccountsListViewController: NSViewController {
getBackToRectIfNeeded()
blinkNewWalletCellIfNeeded()
view.window?.delegate = self
promptSafariForLegacyUsersIfNeeded()
if !didAppear {
didAppear = true
@ -108,12 +107,6 @@ class AccountsListViewController: NSViewController {
}
}
private func promptSafariForLegacyUsersIfNeeded() {
guard Defaults.shouldPromptSafariForLegacyUsers else { return }
Defaults.shouldPromptSafariForLegacyUsers = false
Alert.showSafariPrompt()
}
private func callCompletion(specificWalletAccounts: [SpecificWalletAccount]?) {
if !didCallCompletion {
didCallCompletion = true

View File

@ -20,15 +20,4 @@ class Alert: NSAlert {
_ = alert.runModal()
}
static func showSafariPrompt() {
let alert = Alert()
alert.messageText = "Tokenary now works great in Safari."
alert.alertStyle = .informational
alert.addButton(withTitle: "Enable Safari extension")
alert.addButton(withTitle: Strings.ok)
if alert.runModal() == .alertFirstButtonReturn {
Agent.shared.enableSafariExtension()
}
}
}