fix(@wallet): send to only operable account

fixes #12509
This commit is contained in:
Anthony Laibe 2023-10-30 10:50:27 +01:00
parent 04b6fb54c3
commit a5aba6e4e2
7 changed files with 36 additions and 9 deletions

View File

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

View File

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

View File

@ -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()

View File

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

View File

@ -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]) =

View File

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

View File

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