From a5aba6e4e258e65fe8f5f3e7363db77eccf13a22 Mon Sep 17 00:00:00 2001 From: Anthony Laibe <491074+alaibe@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:50:27 +0100 Subject: [PATCH] fix(@wallet): send to only operable account fixes #12509 --- src/app/modules/main/wallet_section/overview/item.nim | 8 +++++++- .../modules/main/wallet_section/overview/module.nim | 4 +++- src/app/modules/main/wallet_section/overview/view.nim | 11 +++++++++++ .../modules/main/wallet_section/send/account_item.nim | 11 +++++++++-- src/app/modules/main/wallet_section/send/view.nim | 4 ++-- src/app/modules/shared/wallet_utils.nim | 3 ++- ui/app/AppLayouts/Wallet/panels/WalletFooter.qml | 4 ++-- 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/app/modules/main/wallet_section/overview/item.nim b/src/app/modules/main/wallet_section/overview/item.nim index 4851f078c4..63ea8f712b 100644 --- a/src/app/modules/main/wallet_section/overview/item.nim +++ b/src/app/modules/main/wallet_section/overview/item.nim @@ -11,6 +11,7 @@ type isWatchOnlyAccount: bool isAllAccounts: bool colorIds: seq[string] + canSend: bool proc initItem*( name: string = "", @@ -21,7 +22,8 @@ proc initItem*( emoji: string, isWatchOnlyAccount: bool=false, isAllAccounts: bool = false, - colorIds: seq[string] = @[] + colorIds: seq[string] = @[], + canSend: bool = true, ): Item = result.name = name result.mixedCaseAddress = mixedCaseAddress @@ -32,6 +34,7 @@ proc initItem*( result.isAllAccounts = isAllAccounts result.colorIds = colorIds result.isWatchOnlyAccount = isWatchOnlyAccount + result.canSend = canSend proc `$`*(self: Item): string = result = fmt"""OverviewItem( @@ -72,3 +75,6 @@ proc getColorIds*(self: Item): string = proc getIsWatchOnlyAccount*(self: Item): bool = return self.isWatchOnlyAccount + +proc getCanSend*(self: Item): bool = + return self.canSend diff --git a/src/app/modules/main/wallet_section/overview/module.nim b/src/app/modules/main/wallet_section/overview/module.nim index dfb3953ea0..235948d237 100644 --- a/src/app/modules/main/wallet_section/overview/module.nim +++ b/src/app/modules/main/wallet_section/overview/module.nim @@ -82,6 +82,7 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int], self.view.setData(item) else: let walletAccount = walletAccounts[0] + let isWatchOnlyAccount = walletAccount.walletType == "watch" let item = initItem( walletAccount.name, walletAccount.mixedCaseAddress, @@ -89,7 +90,8 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int], walletAccount.assetsLoading, walletAccount.colorId, walletAccount.emoji, - isWatchOnlyAccount=walletAccount.walletType == "watch" + isWatchOnlyAccount=isWatchOnlyAccount, + canSend=not isWatchOnlyAccount and (walletAccount.operable==AccountFullyOperable or walletAccount.operable==AccountPartiallyOperable) ) self.view.setData(item) diff --git a/src/app/modules/main/wallet_section/overview/view.nim b/src/app/modules/main/wallet_section/overview/view.nim index f7fd76d085..3b9b38f30b 100644 --- a/src/app/modules/main/wallet_section/overview/view.nim +++ b/src/app/modules/main/wallet_section/overview/view.nim @@ -19,6 +19,7 @@ QtObject: isAllAccounts: bool colorIds: string isWatchOnlyAccount: bool + canSend: bool proc setup(self: View) = self.QObject.setup @@ -112,6 +113,13 @@ QtObject: read = getIsWatchOnlyAccount notify = isWatchOnlyAccountChanged + proc getCanSend(self: View): bool {.slot.} = + return self.canSend + proc canSendChanged(self: View) {.signal.} + QtProperty[bool] canSend: + read = getCanSend + notify = canSendChanged + proc setData*(self: View, item: Item) = if(self.name != item.getName()): self.name = item.getName() @@ -136,6 +144,9 @@ QtObject: if(self.isWatchOnlyAccount != item.getIsWatchOnlyAccount()): self.isWatchOnlyAccount = item.getIsWatchOnlyAccount() self.isWatchOnlyAccountChanged() + if(self.canSend != item.getCanSend()): + self.canSend = item.getCanSend() + self.canSendChanged() if(self.isAllAccounts != item.getIsAllAccounts()): self.isAllAccounts = item.getIsAllAccounts() self.isAllAccountsChanged() diff --git a/src/app/modules/main/wallet_section/send/account_item.nim b/src/app/modules/main/wallet_section/send/account_item.nim index d53a9fea59..0501750edf 100644 --- a/src/app/modules/main/wallet_section/send/account_item.nim +++ b/src/app/modules/main/wallet_section/send/account_item.nim @@ -9,6 +9,7 @@ QtObject: type AccountItem* = ref object of WalletAccountItem assets: token_model.Model currencyBalance: CurrencyAmount + canSend: bool proc setup*(self: AccountItem, name: string, @@ -21,7 +22,8 @@ QtObject: position: int, areTestNetworksEnabled: bool, prodPreferredChainIds: string, - testPreferredChainIds: string + testPreferredChainIds: string, + canSend: bool ) = self.QObject.setup self.WalletAccountItem.setup(name, @@ -39,6 +41,7 @@ QtObject: testPreferredChainIds) self.assets = assets self.currencyBalance = currencyBalance + self.canSend = canSend proc delete*(self: AccountItem) = self.QObject.delete @@ -55,9 +58,10 @@ QtObject: prodPreferredChainIds: string = "", testPreferredChainIds: string = "", position: int = 0, + canSend: bool = true, ): AccountItem = new(result, delete) - result.setup(name, address, colorId, emoji, walletType, assets, currencyBalance, position, areTestNetworksEnabled, prodPreferredChainIds, testPreferredChainIds) + result.setup(name, address, colorId, emoji, walletType, assets, currencyBalance, position, areTestNetworksEnabled, prodPreferredChainIds, testPreferredChainIds, canSend) proc `$`*(self: AccountItem): string = result = "WalletSection-Send-Item(" @@ -83,3 +87,6 @@ QtObject: QtProperty[QVariant] currencyBalance: read = getCurrencyBalanceAsQVariant notify = currencyBalanceChanged + + proc canSend*(self: AccountItem): bool = + return self.canSend \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/send/view.nim b/src/app/modules/main/wallet_section/send/view.nim index 047d940bf5..2b2a299f09 100644 --- a/src/app/modules/main/wallet_section/send/view.nim +++ b/src/app/modules/main/wallet_section/send/view.nim @@ -184,8 +184,8 @@ QtObject: self.accounts.setItems(items) self.accountsChanged() - # need to remove watch only accounts as a user cant send a tx with a watch only account - self.senderAccounts.setItems(items.filter(a => a.walletType() != WalletTypeWatch)) + # need to remove watch only accounts as a user cant send a tx with a watch only account + remove not operable account + self.senderAccounts.setItems(items.filter(a => a.canSend())) self.senderAccountsChanged() proc setNetworkItems*(self: View, fromNetworks: seq[NetworkItem], toNetworks: seq[NetworkItem]) = diff --git a/src/app/modules/shared/wallet_utils.nim b/src/app/modules/shared/wallet_utils.nim index f8a8cda146..a478d42b54 100644 --- a/src/app/modules/shared/wallet_utils.nim +++ b/src/app/modules/shared/wallet_utils.nim @@ -119,5 +119,6 @@ proc walletAccountToWalletSendAccountItem*(w: WalletAccountDto, tokens: seq[Wall currencyAmountToItem(currencyBalance, currencyFormat), areTestNetworksEnabled, w.prodPreferredChainIds, - w.testPreferredChainIds + w.testPreferredChainIds, + canSend=w.walletType != "watch" and (w.operable==AccountFullyOperable or w.operable==AccountPartiallyOperable) ) diff --git a/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml b/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml index 8236fb9fd5..3009c63a47 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml @@ -46,7 +46,7 @@ Rectangle { interactive: networkConnectionStore.sendBuyBridgeEnabled onClicked: root.launchSendModal() tooltipText: networkConnectionStore.sendBuyBridgeToolTipText - visible: !walletStore.overview.isWatchOnlyAccount + visible: !walletStore.overview.isWatchOnlyAccount && walletStore.overview.canSend } StatusFlatButton { @@ -64,7 +64,7 @@ Rectangle { interactive: networkConnectionStore.sendBuyBridgeEnabled onClicked: root.launchBridgeModal() tooltipText: networkConnectionStore.sendBuyBridgeToolTipText - visible: !walletStore.overview.isWatchOnlyAccount && !root.isCommunityOwnershipTransfer + visible: !walletStore.overview.isWatchOnlyAccount && !root.isCommunityOwnershipTransfer && walletStore.overview.canSend } StatusFlatButton {