Skip to content

Commit

Permalink
fix(@wallet): send to only operable account
Browse files Browse the repository at this point in the history
fixes #12509
  • Loading branch information
alaibe committed Oct 31, 2023
1 parent 04b6fb5 commit a5aba6e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/app/modules/main/wallet_section/overview/item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type
isWatchOnlyAccount: bool
isAllAccounts: bool
colorIds: seq[string]
canSend: bool

proc initItem*(
name: string = "",
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/app/modules/main/wallet_section/overview/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ 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,
walletAccount.ens,
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)

Expand Down
11 changes: 11 additions & 0 deletions src/app/modules/main/wallet_section/overview/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ QtObject:
isAllAccounts: bool
colorIds: string
isWatchOnlyAccount: bool
canSend: bool

proc setup(self: View) =
self.QObject.setup
Expand Down Expand Up @@ -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()
Expand All @@ -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()
11 changes: 9 additions & 2 deletions src/app/modules/main/wallet_section/send/account_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +22,8 @@ QtObject:
position: int,
areTestNetworksEnabled: bool,
prodPreferredChainIds: string,
testPreferredChainIds: string
testPreferredChainIds: string,
canSend: bool
) =
self.QObject.setup
self.WalletAccountItem.setup(name,
Expand All @@ -39,6 +41,7 @@ QtObject:
testPreferredChainIds)
self.assets = assets
self.currencyBalance = currencyBalance
self.canSend = canSend

proc delete*(self: AccountItem) =
self.QObject.delete
Expand All @@ -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("
Expand All @@ -83,3 +87,6 @@ QtObject:
QtProperty[QVariant] currencyBalance:
read = getCurrencyBalanceAsQVariant
notify = currencyBalanceChanged

proc canSend*(self: AccountItem): bool =
return self.canSend
4 changes: 2 additions & 2 deletions src/app/modules/main/wallet_section/send/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]) =
Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/shared/wallet_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
4 changes: 2 additions & 2 deletions ui/app/AppLayouts/Wallet/panels/WalletFooter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit a5aba6e

Please sign in to comment.