From ee23cce575fcc3fcff48c7362537a536077f7591 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 28 Mar 2024 19:47:49 +0200 Subject: [PATCH] fix(SendModal): fix various issues with SendModal - Fix errors when switching between assets and collectibles tabs - Fix by controlling the order of instantiation between model and delegates not to mix models and delegates from different sources - Fix size errors - Various improvements Updates: #14212 --- ui/StatusQ/src/StatusQ/Core/LocaleUtils.qml | 1 + ui/imports/shared/popups/send/SendModal.qml | 17 ++++++--- .../controls/TokenBalancePerChainDelegate.qml | 6 ++++ .../send/controls/WalletAccountListItem.qml | 4 +-- .../popups/send/panels/HoldingSelector.qml | 22 +++++++++--- .../send/views/NetworkCardsComponent.qml | 3 +- .../popups/send/views/NetworkSelector.qml | 10 ++++-- .../popups/send/views/TokenListView.qml | 35 ++++++++++++++----- 8 files changed, 76 insertions(+), 22 deletions(-) diff --git a/ui/StatusQ/src/StatusQ/Core/LocaleUtils.qml b/ui/StatusQ/src/StatusQ/Core/LocaleUtils.qml index c19ec2b1f5..d598c2510a 100644 --- a/ui/StatusQ/src/StatusQ/Core/LocaleUtils.qml +++ b/ui/StatusQ/src/StatusQ/Core/LocaleUtils.qml @@ -62,6 +62,7 @@ QtObject { return 0 } + console.assert(typeof num !== "undefined", "passed number should not be undefined") return num.toString().split('.')[1].length } diff --git a/ui/imports/shared/popups/send/SendModal.qml b/ui/imports/shared/popups/send/SendModal.qml index c36dd070f7..13412dc999 100644 --- a/ui/imports/shared/popups/send/SendModal.qml +++ b/ui/imports/shared/popups/send/SendModal.qml @@ -328,7 +328,8 @@ StatusDialog { maxInputBalance: d.maxInputBalance currentCurrency: d.currencyStore.currentCurrency - multiplierIndex: d.isSelectedHoldingValidAsset + // Collectibles do not have decimals + multiplierIndex: d.isSelectedHoldingValidAsset && !!holdingSelector.selectedItem && !!holdingSelector.selectedItem.decimals ? holdingSelector.selectedItem.decimals : 0 @@ -402,8 +403,8 @@ StatusDialog { collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null networksModel: popup.store.flatNetworksModel onlyAssets: holdingSelector.onlyAssets - onTokenSelected: { - d.setSelectedHoldingId(symbol, holdingType) + onTokenSelected: function (symbolOrTokenKey, holdingType) { + d.setSelectedHoldingId(symbolOrTokenKey, holdingType) } onTokenHovered: { if(hovered) { @@ -502,7 +503,15 @@ StatusDialog { if (!!d.selectedHolding && !!d.selectedHolding.marketDetails && !!d.selectedHolding.marketDetails.currencyPrice) totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * d.selectedHolding.marketDetails.currencyPrice.amount d.totalFeesInFiat = d.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat - d.totalAmountToReceive = popup.store.getWei2Eth(txRoutes.amountToReceive, d.selectedHolding.decimals) + + if (!!d.selectedHolding.type && (d.selectedHolding.type === Constants.TokenType.ERC20 + || d.selectedHolding.type === Constants.TokenType.ETH)) { + // If assets + d.totalAmountToReceive = popup.store.getWei2Eth(txRoutes.amountToReceive, d.selectedHolding.decimals) + } else { + // If collectible + d.totalAmountToReceive = txRoutes.amountToReceive + } networkSelector.toNetworksList = txRoutes.toNetworksModel popup.isLoading = false } diff --git a/ui/imports/shared/popups/send/controls/TokenBalancePerChainDelegate.qml b/ui/imports/shared/popups/send/controls/TokenBalancePerChainDelegate.qml index b9e305e89f..7ef6803f11 100644 --- a/ui/imports/shared/popups/send/controls/TokenBalancePerChainDelegate.qml +++ b/ui/imports/shared/popups/send/controls/TokenBalancePerChainDelegate.qml @@ -12,6 +12,12 @@ import utils 1.0 StatusListItem { id: root + required property var model + required property string name + required property string symbol + required property int decimals + required property var balances + signal tokenSelected(var selectedToken) signal tokenHovered(var selectedToken, bool hovered) property var formatCurrentCurrencyAmount: function(balance){} diff --git a/ui/imports/shared/popups/send/controls/WalletAccountListItem.qml b/ui/imports/shared/popups/send/controls/WalletAccountListItem.qml index 7291ac340f..e8e2e7f891 100644 --- a/ui/imports/shared/popups/send/controls/WalletAccountListItem.qml +++ b/ui/imports/shared/popups/send/controls/WalletAccountListItem.qml @@ -56,13 +56,13 @@ StatusListItem { width: !!icon ? 15: 0 height: !!icon ? 15 : 0 color: Theme.palette.directColor1 - icon: modelData.walletType === Constants.watchWalletType ? "show" : "" + icon: !!modelData && modelData.walletType === Constants.watchWalletType ? "show" : "" } StatusIcon { width: !!icon ? 15: 0 height: !!icon ? 15 : 0 color: Theme.palette.directColor1 - icon: modelData.migratedToKeycard ? "keycard" : "" + icon: !!modelData && modelData.migratedToKeycard ? "keycard" : "" } } }, diff --git a/ui/imports/shared/popups/send/panels/HoldingSelector.qml b/ui/imports/shared/popups/send/panels/HoldingSelector.qml index a4e076eda6..b7340dfe87 100644 --- a/ui/imports/shared/popups/send/panels/HoldingSelector.qml +++ b/ui/imports/shared/popups/send/panels/HoldingSelector.qml @@ -226,15 +226,29 @@ Item { property var groupName: model.groupName property var isGroup: model.isGroup property var count: model.count - - sourceComponent: d.isCurrentBrowsingTypeAsset ? assetComboBoxDelegate : collectibleComboBoxDelegate } } + // Switch models and delegate in the right order not to mix different models and delegates + function updateComponents() { + holdingItemSelector.comboBoxModel = [] + sourceComponent: d.isCurrentBrowsingTypeAsset ? assetComboBoxDelegate : collectibleComboBoxDelegate + holdingItemSelector.comboBoxModel = d.isCurrentBrowsingTypeAsset + ? root.assetsModel + : d.collectibleComboBoxModel + } + Component.onCompleted: updateComponents() + Connections { + target: d + function onIsCurrentBrowsingTypeAssetChanged() { + holdingItemSelector.updateComponents() + } + } + comboBoxModel: null + comboBoxPopupHeader: headerComponent itemTextFn: d.isCurrentBrowsingTypeAsset ? d.assetTextFn : d.collectibleTextFn itemIconSourceFn: d.isCurrentBrowsingTypeAsset ? d.assetIconSourceFn : d.collectibleIconSourceFn - comboBoxModel: d.isCurrentBrowsingTypeAsset ? root.assetsModel : d.collectibleComboBoxModel onComboBoxModelChanged: updateHasCommunityTokens() function updateHasCommunityTokens() { @@ -348,7 +362,7 @@ Item { rightModel: root.networksModel joinRole: "chainId" } - onTokenSelected: { + onTokenSelected: function (selectedToken) { holdingItemSelector.selectedItem = selectedToken d.currentHoldingType = Constants.TokenType.ERC20 root.itemSelected(selectedToken.symbol, Constants.TokenType.ERC20) diff --git a/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml b/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml index 22f30b82a8..de045360b6 100644 --- a/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml +++ b/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml @@ -33,7 +33,8 @@ Item { QtObject { id: d property double customAmountToSend: 0 - readonly property string selectedSymbol: !!selectedAsset ? selectedAsset.symbol : "" + // Collectibles don't have a symbol + readonly property string selectedSymbol: !!selectedAsset && !!selectedAsset.symbol ? selectedAsset.symbol : "" function resetAllSetValues() { for(var i = 0; i