fix(wallet): debounce send modal route requests and assign new uuid on each fetch

This commit is contained in:
Dario Gabriel Lipicar 2024-10-22 12:24:54 -03:00 committed by Anthony Laibe
parent 4370e26dfe
commit 8372ffd62f
2 changed files with 34 additions and 19 deletions

View File

@ -212,12 +212,11 @@ SplitView {
preSelectedHoldingID: loader.preSelectedHoldingID preSelectedHoldingID: loader.preSelectedHoldingID
preSelectedHoldingType: loader.preSelectedHoldingType preSelectedHoldingType: loader.preSelectedHoldingType
showCustomRoutingMode: ctrlShowCustomMode.checked showCustomRoutingMode: ctrlShowCustomMode.checked
generateUuid: () => { return "12345" }
sendTransaction: () => { sendTransaction: () => {
if (!showSendErrorCheckBox.checked) if (!showSendErrorCheckBox.checked)
return 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 Component.onCompleted: loader.active = true

View File

@ -72,17 +72,7 @@ StatusDialog {
popup.store.authenticateAndTransfer(d.uuid) popup.store.authenticateAndTransfer(d.uuid)
} }
property var recalculateRoutesAndFees: Backpressure.debounce(popup, 600, function() { readonly property string uuid: d.uuid
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() }
QtObject { QtObject {
id: d id: d
@ -130,7 +120,7 @@ StatusDialog {
property string sendError: "" property string sendError: ""
readonly property string uuid: popup.generateUuid() property string uuid: Utils.uuid()
property bool isPendingTx: false property bool isPendingTx: false
property string totalTimeEstimate property string totalTimeEstimate
property double totalFeesInFiat property double totalFeesInFiat
@ -171,6 +161,27 @@ StatusDialog {
function addMetricsEvent(subEventName) { function addMetricsEvent(subEventName) {
Global.addCentralizedMetricIfEnabled(d.isBridgeTx ? "bridge" : "send", {subEvent: 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 { LeftJoinModel {
@ -314,7 +325,7 @@ StatusDialog {
d.selectedHolding.tokensKey) d.selectedHolding.tokensKey)
} }
popup.recalculateRoutesAndFees() d.recalculateRoutesAndFees()
} }
} }
} }
@ -529,12 +540,12 @@ StatusDialog {
onValidChanged: { onValidChanged: {
d.sendError = "" d.sendError = ""
popup.recalculateRoutesAndFees() d.recalculateRoutesAndFees()
} }
onAmountChanged: { onAmountChanged: {
d.sendError = "" d.sendError = ""
popup.recalculateRoutesAndFees() d.recalculateRoutesAndFees()
} }
} }
@ -583,7 +594,7 @@ StatusDialog {
onIsLoading: popup.isLoading = true onIsLoading: popup.isLoading = true
onRecalculateRoutesAndFees: { onRecalculateRoutesAndFees: {
d.sendError = "" d.sendError = ""
popup.recalculateRoutesAndFees() d.recalculateRoutesAndFees()
} }
onAddressTextChanged: store.setSelectedRecipient(addressText) onAddressTextChanged: store.setSelectedRecipient(addressText)
} }
@ -669,7 +680,7 @@ StatusDialog {
selectedAsset: d.selectedHolding selectedAsset: d.selectedHolding
onReCalculateSuggestedRoute: { onReCalculateSuggestedRoute: {
d.sendError = "" d.sendError = ""
popup.recalculateRoutesAndFees() d.recalculateRoutesAndFees()
} }
errorType: d.errorType errorType: d.errorType
isLoading: popup.isLoading isLoading: popup.isLoading
@ -748,6 +759,11 @@ StatusDialog {
Connections { Connections {
target: popup.store.walletSectionSendInst target: popup.store.walletSectionSendInst
function onSuggestedRoutesReady(txRoutes, errCode, errDescription) { function onSuggestedRoutesReady(txRoutes, errCode, errDescription) {
if (txRoutes.uuid !== d.uuid) {
// Suggested routes for a different fetch, ignore
return
}
popup.bestRoutes = txRoutes.suggestedRoutes popup.bestRoutes = txRoutes.suggestedRoutes
d.routerError = WalletUtils.getRouterErrorBasedOnCode(errCode) d.routerError = WalletUtils.getRouterErrorBasedOnCode(errCode)