From 29629a3d6d708b0c400772bc2a8f0a01bb6e54a1 Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Mon, 25 Sep 2023 14:39:54 +0200 Subject: [PATCH] fix(@desktop/wallet): Send Modal Improvements & missing features fixes #12243 --- .../wallet_section/send/network_model.nim | 28 +++++++++++-------- .../modules/main/wallet_section/send/view.nim | 2 ++ storybook/pages/SendModalPage.qml | 2 +- .../src/StatusQ/Components/StatusCard.qml | 6 +--- ui/imports/shared/popups/send/SendModal.qml | 5 +--- .../popups/send/controls/GasValidator.qml | 16 +++++------ .../shared/popups/send/views/FeesView.qml | 3 +- .../send/views/NetworkCardsComponent.qml | 15 ++-------- .../popups/send/views/SendModalFooter.qml | 3 +- 9 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/app/modules/main/wallet_section/send/network_model.nim b/src/app/modules/main/wallet_section/send/network_model.nim index 697dabe8a8..1a85816673 100644 --- a/src/app/modules/main/wallet_section/send/network_model.nim +++ b/src/app/modules/main/wallet_section/send/network_model.nim @@ -166,30 +166,36 @@ QtObject: proc updateFromNetworks*(self: NetworkModel, path: SuggestedRouteItem, hasGas: bool) = for i in 0 ..< self.items.len: - let index = self.createIndex(i, 0, nil) - defer: index.delete - self.items[i].amountIn = "" - self.items[i].resetToNetworks - self.items[i].hasGas = true - self.items[i].locked = false if path.getfromNetwork() == self.items[i].getChainId(): + let index = self.createIndex(i, 0, nil) + defer: index.delete self.items[i].amountIn = path.getAmountIn() self.items[i].toNetworks = path.getToNetwork() self.items[i].hasGas = hasGas self.items[i].locked = path.getAmountInLocked() - self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.Locked.int]) + self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.Locked.int]) proc updateToNetworks*(self: NetworkModel, path: SuggestedRouteItem) = for i in 0 ..< self.items.len: - let index = self.createIndex(i, 0, nil) - defer: index.delete - self.items[i].amountOut = "" if path.getToNetwork() == self.items[i].getChainId(): + let index = self.createIndex(i, 0, nil) + defer: index.delete if self.items[i].getAmountOut().len != 0: self.items[i].amountOut = $(parseInt(self.items[i].getAmountOut()) + parseInt(path.getAmountOut())) else: self.items[i].amountOut = path.getAmountOut() - self.dataChanged(index, index, @[ModelRole.AmountOut.int]) + self.dataChanged(index, index, @[ModelRole.AmountOut.int]) + + proc resetPathData*(self: NetworkModel) = + for i in 0 ..< self.items.len: + let index = self.createIndex(i, 0, nil) + defer: index.delete + self.items[i].amountIn = "" + self.items[i].resetToNetworks() + self.items[i].hasGas = true + self.items[i].locked = false + self.items[i].amountOut = "" + self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.Locked.int, ModelRole.AmountOut.int]) proc getRouteDisabledNetworkChainIds*(self: NetworkModel): seq[int] = var disbaledChains: seq[int] = @[] diff --git a/src/app/modules/main/wallet_section/send/view.nim b/src/app/modules/main/wallet_section/send/view.nim index 9986de31c4..254972827f 100644 --- a/src/app/modules/main/wallet_section/send/view.nim +++ b/src/app/modules/main/wallet_section/send/view.nim @@ -252,6 +252,8 @@ QtObject: return self.selectedSenderAccount.address() proc updatedNetworksWithRoutes*(self: View, paths: seq[SuggestedRouteItem], totalFeesInEth: float) = + self.fromNetworksModel.resetPathData() + self.toNetworksModel.resetPathData() for path in paths: let fromChainId = path.getfromNetwork() let hasGas = self.selectedSenderAccount.getAssets().hasGas(fromChainId, self.fromNetworksModel.getNetworkNativeGasSymbol(fromChainId), totalFeesInEth) diff --git a/storybook/pages/SendModalPage.qml b/storybook/pages/SendModalPage.qml index 820faa5794..51d437ad98 100644 --- a/storybook/pages/SendModalPage.qml +++ b/storybook/pages/SendModalPage.qml @@ -59,7 +59,7 @@ SplitView { } } - function splitAndFormatAddressPrefix(textAddrss, isBridgeTx) { + function splitAndFormatAddressPrefix(textAddrss, updateInStore) { return textAddrss } diff --git a/ui/StatusQ/src/StatusQ/Components/StatusCard.qml b/ui/StatusQ/src/StatusQ/Components/StatusCard.qml index caac8bb2da..0b4d748743 100644 --- a/ui/StatusQ/src/StatusQ/Components/StatusCard.qml +++ b/ui/StatusQ/src/StatusQ/Components/StatusCard.qml @@ -226,11 +226,7 @@ Rectangle { acceptedButtons: Qt.LeftButton hoverEnabled: true enabled: root.clickable && root.state !== "unavailable" - onClicked: { - if(!advancedMode) - disabled = !disabled - root.clicked() - } + onClicked: root.clicked() } ColumnLayout { diff --git a/ui/imports/shared/popups/send/SendModal.qml b/ui/imports/shared/popups/send/SendModal.qml index 33310fd2ab..523dbd0f05 100644 --- a/ui/imports/shared/popups/send/SendModal.qml +++ b/ui/imports/shared/popups/send/SendModal.qml @@ -129,8 +129,6 @@ StatusDialog { } width: 556 - topMargin: 64 + header.height - bottomPadding: footer.visible ? footer.height : 32 padding: 0 background: StatusDialogBackground { @@ -187,7 +185,6 @@ StatusDialog { } } - ColumnLayout { id: group1 @@ -344,7 +341,6 @@ StatusDialog { implicitHeight: scrollView.implicitHeight clipTopMargin: 40 - clipBottomMargin: popup.bottomPadding StatusScrollView { id: scrollView @@ -479,6 +475,7 @@ StatusDialog { } footer: SendModalFooter { + width: parent.width nextButtonText: d.isBridgeTx ? qsTr("Bridge") : qsTr("Send") maxFiatFees: popup.isLoading ? "..." : popup.currencyStore.formatCurrencyAmount(d.totalFeesInFiat, popup.currencyStore.currentCurrency) totalTimeEstimate: popup.isLoading? "..." : d.totalTimeEstimate diff --git a/ui/imports/shared/popups/send/controls/GasValidator.qml b/ui/imports/shared/popups/send/controls/GasValidator.qml index 6a2adc6c16..22a15de79f 100644 --- a/ui/imports/shared/popups/send/controls/GasValidator.qml +++ b/ui/imports/shared/popups/send/controls/GasValidator.qml @@ -10,7 +10,7 @@ import utils 1.0 import shared.panels 1.0 -Column { +ColumnLayout { id: root property int errorType: Constants.NoError @@ -25,29 +25,29 @@ Column { spacing: 5 StatusIcon { - anchors.horizontalCenter: parent.horizontalCenter - height: 20 - width: 20 + Layout.alignment: Qt.AlignHCenter + Layout.preferredHeight: 20 + Layout.preferredWidth: 20 icon: "cancel" color: Theme.palette.dangerColor1 visible: !d.isValid && !isLoading } StyledText { id: txtValidationError - anchors.horizontalCenter: parent.horizontalCenter + Layout.alignment: Qt.AlignHCenter + Layout.preferredHeight: 18 text: errorType === Constants.SendAmountExceedsBalance ? qsTr("Balance exceeded") : qsTr("No route found") verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter font.pixelSize: 13 - height: 18 color: Style.current.danger visible: !isLoading } Loader { id: loadingComponent - height: 32 - width: root.width - Style.current.xlPadding + Layout.preferredHeight: 32 + Layout.preferredWidth: root.width - Style.current.xlPadding active: isLoading && d.isValid sourceComponent: LoadingComponent { radius: 4 } } diff --git a/ui/imports/shared/popups/send/views/FeesView.qml b/ui/imports/shared/popups/send/views/FeesView.qml index 581ff4d897..8f99e0550b 100644 --- a/ui/imports/shared/popups/send/views/FeesView.qml +++ b/ui/imports/shared/popups/send/views/FeesView.qml @@ -24,7 +24,7 @@ Rectangle { radius: 13 color: Theme.palette.indirectColor1 - height: text.height + gasSelector.height + gasValidator.height + Style.current.xlPadding + height: columnLayout.height + feesIcon.height RowLayout { id: feesLayout @@ -41,6 +41,7 @@ Rectangle { asset.color: Theme.palette.directColor1 } Column { + id: columnLayout Layout.alignment: Qt.AlignTop | Qt.AlignHCenter Layout.preferredWidth: root.width - feesIcon.width - Style.current.xlPadding spacing: isLoading ? 4 : 0 diff --git a/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml b/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml index 2a844aa37d..22f30b82a8 100644 --- a/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml +++ b/ui/imports/shared/popups/send/views/NetworkCardsComponent.qml @@ -116,16 +116,13 @@ Item { clickable: root.interactive onClicked: { store.toggleFromDisabledChains(model.chainId) - // only recalculate if the a best route was disabled - if(!!model.toNetworks || !disabled) - root.reCalculateSuggestedRoute() + root.reCalculateSuggestedRoute() } onLockCard: { let amount = lock ? (advancedInputCurrencyAmount * Math.pow(10, root.selectedAsset.decimals)).toString(16) : "" store.lockCard(model.chainId, amount, lock) d.calculateCustomAmounts() - if(!locked || (d.customAmountToSend <= root.amountToSend && advancedInput.valid)) - root.reCalculateSuggestedRoute() + root.reCalculateSuggestedRoute() } } } @@ -187,13 +184,7 @@ Item { loading: root.isLoading onClicked: { store.toggleToDisabledChains(model.chainId) - // only recalculate if the a best route was disabled - if(root.weiToEth(model.amountOut) > 0 || !disabled) - root.reCalculateSuggestedRoute() - } - onOpacityChanged: { - if(opacity === 0 && root.weiToEth(model.amountOut) > 0) - root.reCalculateSuggestedRoute() + root.reCalculateSuggestedRoute() } } } diff --git a/ui/imports/shared/popups/send/views/SendModalFooter.qml b/ui/imports/shared/popups/send/views/SendModalFooter.qml index dbfd522c11..53db2b9658 100644 --- a/ui/imports/shared/popups/send/views/SendModalFooter.qml +++ b/ui/imports/shared/popups/send/views/SendModalFooter.qml @@ -20,8 +20,7 @@ Rectangle { signal nextButtonClicked() - width: parent.width - height: 82 + implicitHeight: 82 radius: 8 color: Theme.palette.baseColor3