From f34050a5bcb178b62f8c13eefffbfdfabe36e611 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Tue, 22 Oct 2024 12:24:54 -0300 Subject: [PATCH] fix(wallet): debounce send modal route requests and assign new uuid on each fetch --- storybook/pages/SendModalPage.qml | 3 +- ui/imports/shared/popups/send/SendModal.qml | 50 ++++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/storybook/pages/SendModalPage.qml b/storybook/pages/SendModalPage.qml index 3777706b8a..09cc95cbda 100644 --- a/storybook/pages/SendModalPage.qml +++ b/storybook/pages/SendModalPage.qml @@ -212,12 +212,11 @@ SplitView { preSelectedHoldingID: loader.preSelectedHoldingID preSelectedHoldingType: loader.preSelectedHoldingType showCustomRoutingMode: ctrlShowCustomMode.checked - generateUuid: () => { return "12345" } sendTransaction: () => { if (!showSendErrorCheckBox.checked) return - txStore.walletSectionSendInst.transactionSent(1, "0x123", generateUuid(), "Send error, please ignore") + txStore.walletSectionSendInst.transactionSent(1, "0x123", uuid, "Send error, please ignore") } } Component.onCompleted: loader.active = true diff --git a/ui/imports/shared/popups/send/SendModal.qml b/ui/imports/shared/popups/send/SendModal.qml index 9e7f4cea0a..6a4acd932a 100644 --- a/ui/imports/shared/popups/send/SendModal.qml +++ b/ui/imports/shared/popups/send/SendModal.qml @@ -73,17 +73,7 @@ StatusDialog { popup.store.authenticateAndTransfer(d.uuid) } - property var recalculateRoutesAndFees: Backpressure.debounce(popup, 600, function() { - if(!!popup.selectedAccount && !!popup.selectedAccount.address && !!holdingSelector.selectedItem - && recipientInputLoader.ready && (amountToSend.ready || d.isCollectiblesTransfer)) { - popup.isLoading = true - d.routerError = "" - d.routerErrorDetails = "" - popup.store.suggestedRoutes(d.uuid, d.isCollectiblesTransfer ? "1" : amountToSend.amount, "0", d.extraParamsJson) - } - }) - - property var generateUuid: () => { return Utils.uuid() } + readonly property string uuid: d.uuid QtObject { id: d @@ -131,7 +121,7 @@ StatusDialog { property string sendError: "" - readonly property string uuid: popup.generateUuid() + property string uuid: Utils.uuid() property bool isPendingTx: false property string totalTimeEstimate property double totalFeesInFiat @@ -172,6 +162,27 @@ StatusDialog { function addMetricsEvent(subEventName) { Global.addCentralizedMetricIfEnabled(d.isBridgeTx ? "bridge" : "send", {subEvent: subEventName}) } + + function areInputParametersValid() { + return !!popup.selectedAccount && !!popup.selectedAccount.address && !!holdingSelector.selectedItem + && recipientInputLoader.ready && (amountToSend.ready || d.isCollectiblesTransfer) + } + + property var debounceRecalculateRoutesAndFees: Backpressure.debounce(popup, 1000, function() { + if(d.areInputParametersValid()) { + popup.store.suggestedRoutes(d.uuid, d.isCollectiblesTransfer ? "1" : amountToSend.amount, "0", d.extraParamsJson) + } + }) + + function recalculateRoutesAndFees() { + if(d.areInputParametersValid()) { + popup.isLoading = true + } + d.uuid = Utils.uuid() + d.routerError = "" + d.routerErrorDetails = "" + debounceRecalculateRoutesAndFees() + } } LeftJoinModel { @@ -315,7 +326,7 @@ StatusDialog { d.selectedHolding.tokensKey) } - popup.recalculateRoutesAndFees() + d.recalculateRoutesAndFees() } } } @@ -530,12 +541,12 @@ StatusDialog { onValidChanged: { d.sendError = "" - popup.recalculateRoutesAndFees() + d.recalculateRoutesAndFees() } onAmountChanged: { d.sendError = "" - popup.recalculateRoutesAndFees() + d.recalculateRoutesAndFees() } } @@ -584,7 +595,7 @@ StatusDialog { onIsLoading: popup.isLoading = true onRecalculateRoutesAndFees: { d.sendError = "" - popup.recalculateRoutesAndFees() + d.recalculateRoutesAndFees() } onAddressTextChanged: store.setSelectedRecipient(addressText) } @@ -670,7 +681,7 @@ StatusDialog { selectedAsset: d.selectedHolding onReCalculateSuggestedRoute: { d.sendError = "" - popup.recalculateRoutesAndFees() + d.recalculateRoutesAndFees() } errorType: d.errorType isLoading: popup.isLoading @@ -749,6 +760,11 @@ StatusDialog { Connections { target: popup.store.walletSectionSendInst function onSuggestedRoutesReady(txRoutes, errCode, errDescription) { + if (txRoutes.uuid !== d.uuid) { + // Suggested routes for a different fetch, ignore + return + } + popup.bestRoutes = txRoutes.suggestedRoutes d.routerError = WalletUtils.getRouterErrorBasedOnCode(errCode)