fix(@wallet): Copy viewed account details (#14161)
This commit is contained in:
parent
e937dfb56c
commit
fae7e82e0a
|
@ -3,6 +3,8 @@ import NimQml, sequtils, strutils
|
|||
import ./io_interface
|
||||
import ./model
|
||||
import app/modules/shared_models/keypair_model
|
||||
import app/modules/shared_models/keypair_item
|
||||
import app/modules/shared_models/keypair_account_item
|
||||
import app/modules/shared_models/wallet_account_item
|
||||
import app/modules/shared_models/currency_amount
|
||||
|
||||
|
@ -13,6 +15,8 @@ QtObject:
|
|||
accounts: Model
|
||||
accountsVariant: QVariant
|
||||
keyPairModel: KeyPairModel
|
||||
selectedKeyPair: KeyPairItem
|
||||
selectedAccount: KeyPairAccountItem
|
||||
|
||||
proc delete*(self: View) =
|
||||
self.accounts.delete
|
||||
|
@ -28,6 +32,40 @@ QtObject:
|
|||
result.accountsVariant = newQVariant(result.accounts)
|
||||
result.keyPairModel = newKeyPairModel()
|
||||
|
||||
proc getSelectedKeyPair*(self: View): QVariant {.slot.} =
|
||||
if self.selectedKeyPair.isNil:
|
||||
return newQVariant()
|
||||
return newQVariant(self.selectedKeyPair)
|
||||
|
||||
proc selectedKeyPairChanged(self: View) {.signal.}
|
||||
|
||||
QtProperty[QVariant] selectedKeyPair:
|
||||
read = getSelectedKeyPair
|
||||
notify = selectedKeyPairChanged
|
||||
|
||||
proc getSelectedAccount*(self: View): QVariant {.slot.} =
|
||||
if self.selectedAccount.isNil:
|
||||
return newQVariant()
|
||||
return newQVariant(self.selectedAccount)
|
||||
|
||||
proc selectedAccountChanged(self: View) {.signal.}
|
||||
|
||||
QtProperty[QVariant] selectedAccount:
|
||||
read = getSelectedAccount
|
||||
notify = selectedAccountChanged
|
||||
|
||||
proc setSelectedAccount*(self: View, address: string) {.slot.} =
|
||||
let (selectedKeyPair, selectedAccount) = self.keyPairModel.findKeyPairAndAccountByAddresss(address)
|
||||
self.selectedKeyPair = selectedKeyPair
|
||||
self.selectedAccount = selectedAccount
|
||||
self.selectedKeyPairChanged()
|
||||
self.selectedAccountChanged()
|
||||
|
||||
proc refreshSelectedAccount(self: View) =
|
||||
if self.selectedAccount.isNil:
|
||||
return
|
||||
self.setSelectedAccount(self.selectedAccount.getAddress())
|
||||
|
||||
proc load*(self: View) =
|
||||
self.delegate.viewDidLoad()
|
||||
|
||||
|
@ -49,15 +87,19 @@ QtObject:
|
|||
proc onUpdatedAccount*(self: View, account: WalletAccountItem) =
|
||||
self.accounts.onUpdatedAccount(account)
|
||||
self.keyPairModel.onUpdatedAccount(account.keyUid, account.address, account.name, account.colorId, account.emoji)
|
||||
self.refreshSelectedAccount()
|
||||
|
||||
proc onUpdatedKeypairOperability*(self: View, keyUid, operability: string) =
|
||||
self.keyPairModel.onUpdatedKeypairOperability(keyUid, operability)
|
||||
self.refreshSelectedAccount()
|
||||
|
||||
proc onPreferredSharingChainsUpdated*(self: View, keyUid, address, prodPreferredChainIds, testPreferredChainIds: string) =
|
||||
self.keyPairModel.onPreferredSharingChainsUpdated(keyUid, address, prodPreferredChainIds, testPreferredChainIds)
|
||||
self.refreshSelectedAccount()
|
||||
|
||||
proc onHideFromTotalBalanceUpdated*(self: View, keyUid, address: string, hideFromTotalBalance: bool) =
|
||||
self.keyPairModel.onHideFromTotalBalanceUpdated(keyUid, address, hideFromTotalBalance)
|
||||
self.refreshSelectedAccount()
|
||||
|
||||
proc deleteAccount*(self: View, address: string) {.slot.} =
|
||||
self.delegate.deleteAccount(address)
|
||||
|
@ -78,6 +120,7 @@ QtObject:
|
|||
proc setKeyPairModelItems*(self: View, items: seq[KeyPairItem]) =
|
||||
self.keyPairModel.setItems(items)
|
||||
self.keyPairModelChanged()
|
||||
self.refreshSelectedAccount()
|
||||
|
||||
proc keypairNameExists*(self: View, name: string): bool {.slot.} =
|
||||
return self.keyPairModel.keypairNameExists(name)
|
||||
|
@ -99,6 +142,7 @@ QtObject:
|
|||
|
||||
proc setBalanceForKeyPairs*(self: View, address: string, balance: CurrencyAmount) =
|
||||
self.keyPairModel.setBalanceForAddress(address, balance)
|
||||
self.refreshSelectedAccount()
|
||||
|
||||
proc updateWatchAccountHiddenFromTotalBalance*(self: View, address: string, hideFromTotalBalance: bool) {.slot.} =
|
||||
self.delegate.updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance)
|
||||
|
|
|
@ -98,6 +98,12 @@ QtObject:
|
|||
return newKeyPairAccountItem()
|
||||
return self.items[index]
|
||||
|
||||
proc getItemByAddress*(self: KeyPairAccountModel, address: string): KeyPairAccountItem =
|
||||
for it in self.items:
|
||||
if cmpIgnoreCase(it.getAddress(), address) == 0:
|
||||
return it
|
||||
return nil
|
||||
|
||||
proc removeItemAtIndex*(self: KeyPairAccountModel, index: int) =
|
||||
if (index < 0 or index >= self.items.len):
|
||||
return
|
||||
|
|
|
@ -96,6 +96,9 @@ QtObject:
|
|||
accounts: {$self.accounts},
|
||||
]"""
|
||||
|
||||
proc getAccountByAddress*(self: KeyPairItem, address: string): KeyPairAccountItem =
|
||||
return self.accounts.getItemByAddress(address)
|
||||
|
||||
proc keyUidChanged*(self: KeyPairItem) {.signal.}
|
||||
proc getKeyUid*(self: KeyPairItem): string {.slot.} =
|
||||
return self.keyUid
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import NimQml, Tables, stew/shims/strformat, sequtils, sugar
|
||||
import keypair_item
|
||||
import keypair_account_item
|
||||
import ./currency_amount
|
||||
|
||||
export keypair_item
|
||||
|
@ -76,6 +77,13 @@ QtObject:
|
|||
return self.items[i]
|
||||
return nil
|
||||
|
||||
proc findKeyPairAndAccountByAddresss*(self: KeyPairModel, address: string): (KeyPairItem, KeyPairAccountItem) =
|
||||
for i in 0 ..< self.items.len:
|
||||
let account = self.items[i].getAccountByAddress(address)
|
||||
if not account.isNil:
|
||||
return (self.items[i], account)
|
||||
return (nil, nil)
|
||||
|
||||
proc onUpdatedAccount*(self: KeyPairModel, keyUid, address, name, colorId, emoji: string) =
|
||||
for item in self.items:
|
||||
if keyUid == item.getKeyUid():
|
||||
|
|
|
@ -71,6 +71,10 @@ QtObject {
|
|||
root.accountsModule.moveAccountFinally(from, to)
|
||||
}
|
||||
|
||||
function setSelectedAccount(address) {
|
||||
root.accountsModule.setSelectedAccount(address)
|
||||
}
|
||||
|
||||
function getAllNetworksChainIds() {
|
||||
return networksModule.getAllNetworksChainIds()
|
||||
}
|
||||
|
|
|
@ -204,8 +204,10 @@ SettingsContentBase {
|
|||
if (!!account && !!account.address) {
|
||||
root.rootStore.addressWasShown(account.address)
|
||||
}
|
||||
root.walletStore.selectedAccount = account
|
||||
accountView.keyPair = keypair
|
||||
|
||||
root.walletStore.setSelectedAccount(account.address)
|
||||
root.walletStore.selectedAccount = Qt.binding(function() { return root.walletStore.accountsModule.selectedAccount })
|
||||
accountView.keyPair = Qt.binding(function() { return root.walletStore.accountsModule.selectedKeyPair })
|
||||
stackContainer.currentIndex = accountViewIndex
|
||||
}
|
||||
|
||||
|
@ -286,7 +288,12 @@ SettingsContentBase {
|
|||
emojiPopup: root.emojiPopup
|
||||
userProfilePublicKey: walletStore.userProfilePublicKey
|
||||
onGoBack: stackContainer.currentIndex = mainViewIndex
|
||||
onVisibleChanged: if(!visible) root.walletStore.selectedAccount = null
|
||||
onVisibleChanged: {
|
||||
if (!visible) {
|
||||
root.walletStore.selectedAccount = null
|
||||
keyPair = null
|
||||
}
|
||||
}
|
||||
onRunRenameKeypairFlow: {
|
||||
renameKeypairPopup.keyUid = keyPair.keyUid
|
||||
renameKeypairPopup.name = keyPair.name
|
||||
|
|
|
@ -23,7 +23,7 @@ Column {
|
|||
|
||||
signal goToNetworksView()
|
||||
signal goToAccountOrderView()
|
||||
signal goToAccountView(var account, var keypair)
|
||||
signal goToAccountView(var account)
|
||||
signal goToDappPermissionsView()
|
||||
signal goToManageTokensView()
|
||||
signal goToSavedAddressesView()
|
||||
|
@ -267,7 +267,7 @@ Column {
|
|||
hasPairedDevices: root.walletStore.walletModule.hasPairedDevices
|
||||
getNetworkShortNames: walletStore.getNetworkShortNames
|
||||
userProfilePublicKey: walletStore.userProfilePublicKey
|
||||
onGoToAccountView: root.goToAccountView(account, keyPair)
|
||||
onGoToAccountView: root.goToAccountView(account)
|
||||
onRunRenameKeypairFlow: root.runRenameKeypairFlow(model)
|
||||
onRunRemoveKeypairFlow: root.runRemoveKeypairFlow(model)
|
||||
onRunImportViaSeedPhraseFlow: {
|
||||
|
|
Loading…
Reference in New Issue