mirror of
https://github.com/lil-org/tokenary.git
synced 2025-01-07 14:10:28 +03:00
Scroll to the preselected account when account selection appears
This commit is contained in:
parent
f488fbadf6
commit
e6a5cbac19
@ -82,6 +82,10 @@ class AccountsListViewController: NSViewController {
|
||||
updateBottomButtons()
|
||||
updateCellModels()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(walletsChanged), name: Notification.Name.walletsChanged, object: nil)
|
||||
|
||||
if let preselectedAccount = accountSelectionConfiguration?.selectedAccounts.first {
|
||||
scrollTo(specificWalletAccount: preselectedAccount)
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidAppear() {
|
||||
@ -274,6 +278,27 @@ class AccountsListViewController: NSViewController {
|
||||
view.window?.contentViewController = importViewController
|
||||
}
|
||||
|
||||
private func scrollTo(specificWalletAccount: SpecificWalletAccount) {
|
||||
guard let specificWalletIndex = wallets.firstIndex(where: { $0.id == specificWalletAccount.walletId }),
|
||||
let specificAccountIndex = wallets[specificWalletIndex].accounts.firstIndex(where: { $0 == specificWalletAccount.account })
|
||||
else { return }
|
||||
|
||||
let row = cellModels.firstIndex { cellModel in
|
||||
switch cellModel {
|
||||
case let .mnemonicAccount(walletIndex, accountIndex):
|
||||
return walletIndex == specificWalletIndex && accountIndex == specificAccountIndex
|
||||
case let .privateKeyAccount(walletIndex):
|
||||
return walletIndex == specificWalletIndex
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if let row = row {
|
||||
tableView.scrollRowToVisible(row)
|
||||
}
|
||||
}
|
||||
|
||||
private func walletForRow(_ row: Int) -> TokenaryWallet? {
|
||||
guard row >= 0 else { return nil }
|
||||
let item = cellModels[row]
|
||||
|
Loading…
Reference in New Issue
Block a user