diff --git a/Shared/Wallets/WalletsManager.swift b/Shared/Wallets/WalletsManager.swift index e3d73378..2dab083f 100644 --- a/Shared/Wallets/WalletsManager.swift +++ b/Shared/Wallets/WalletsManager.swift @@ -197,7 +197,11 @@ final class WalletsManager { } } - func update(wallet: TokenaryWallet, coinDerivations: [CoinDerivation]) throws { + func update(wallet: TokenaryWallet, enabledAccounts: [Account]) throws { + // TODO: implement + } + + func deprecatedupdate(wallet: TokenaryWallet, coinDerivations: [CoinDerivation]) throws { guard let password = keychain.password else { throw Error.keychainAccessFailure } for account in wallet.accounts { diff --git a/Tokenary macOS/Screens/EditAccountsViewController.swift b/Tokenary macOS/Screens/EditAccountsViewController.swift index 0bd933e7..30a717d6 100644 --- a/Tokenary macOS/Screens/EditAccountsViewController.swift +++ b/Tokenary macOS/Screens/EditAccountsViewController.swift @@ -20,6 +20,7 @@ class EditAccountsViewController: NSViewController { private var page = 1 private var requestedPreviewFor: Int? private var lastPreviewDate = Date() + private var toggledIndexes = Set() @IBOutlet weak var tableView: RightClickTableView! { didSet { @@ -43,23 +44,17 @@ class EditAccountsViewController: NSViewController { } @IBAction func okButtonTapped(_ sender: Any) { - let newAccounts: [Account] = cellModels.compactMap { model in - if model.isEnabled { - return model.account - } else { - return nil - } - } - let accountsChanged = false // TODO: implement - if accountsChanged { - do { - // TODO: update accounts - showAccountsList() - } catch { - Alert.showWithMessage(Strings.somethingWentWrong, style: .informational) - } - } else { + guard !toggledIndexes.isEmpty else { showAccountsList() + return + } + + let newAccounts: [Account] = cellModels.compactMap { $0.isEnabled ? $0.account : nil } + do { + try walletsManager.update(wallet: wallet, enabledAccounts: newAccounts) + showAccountsList() + } catch { + Alert.showWithMessage(Strings.somethingWentWrong, style: .informational) } } @@ -73,6 +68,11 @@ class EditAccountsViewController: NSViewController { private func toggleCoinDerivation(row: Int) { cellModels[row].isEnabled.toggle() okButton.isEnabled = cellModels.contains(where: { $0.isEnabled }) + if toggledIndexes.contains(row) { + toggledIndexes.remove(row) + } else { + toggledIndexes.insert(row) + } } private func previewMoreAccountsIfNeeded() {