pass enabled accounts to wallet manager

This commit is contained in:
ivan grachev 2023-12-05 01:31:25 +03:00
parent fbe1396c9f
commit 4f2c55bddc
2 changed files with 21 additions and 17 deletions

View File

@ -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 {

View File

@ -20,6 +20,7 @@ class EditAccountsViewController: NSViewController {
private var page = 1
private var requestedPreviewFor: Int?
private var lastPreviewDate = Date()
private var toggledIndexes = Set<Int>()
@IBOutlet weak var tableView: RightClickTableView! {
didSet {
@ -43,24 +44,18 @@ class EditAccountsViewController: NSViewController {
}
@IBAction func okButtonTapped(_ sender: Any) {
let newAccounts: [Account] = cellModels.compactMap { model in
if model.isEnabled {
return model.account
} else {
return nil
guard !toggledIndexes.isEmpty else {
showAccountsList()
return
}
}
let accountsChanged = false // TODO: implement
if accountsChanged {
let newAccounts: [Account] = cellModels.compactMap { $0.isEnabled ? $0.account : nil }
do {
// TODO: update accounts
try walletsManager.update(wallet: wallet, enabledAccounts: newAccounts)
showAccountsList()
} catch {
Alert.showWithMessage(Strings.somethingWentWrong, style: .informational)
}
} else {
showAccountsList()
}
}
private func showAccountsList() {
@ -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() {