fix(swap): invalidate old uuid and route when a new route request is made

Fixes #16574
This commit is contained in:
Dario Gabriel Lipicar 2024-10-28 18:38:14 -03:00 committed by Anthony Laibe
parent 9e5a172632
commit 1c378cc9ae
3 changed files with 70 additions and 8 deletions

View File

@ -1866,5 +1866,61 @@ Item {
// wait(root.swapFormData.autoRefreshTime*2)
// compare(fetchSuggestedRoutesCalled.count, 2)
}
function test_uuid_change() {
root.swapFormData.fromTokenAmount = "0.0001"
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
root.swapFormData.selectedNetworkChainId = 11155111
root.swapFormData.fromTokensKey = "ETH"
root.swapFormData.toTokenKey = "STT"
// Launch popup
launchAndVerfyModal()
const payPanel = findChild(controlUnderTest, "payPanel")
verify(!!payPanel)
const receivePanel = findChild(controlUnderTest, "receivePanel")
verify(!!receivePanel)
waitForItemPolished(controlUnderTest.contentItem)
// check if fetchSuggestedRoutes called
fetchSuggestedRoutesCalled.wait()
// emit routes ready
let txHasRouteNoApproval = root.dummySwapTransactionRoutes.txHasRouteNoApproval
txHasRouteNoApproval.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
let lastUuid = root.swapAdaptor.uuid
// edit some params to retry swap
root.swapFormData.fromTokenAmount = "0.00011"
waitForRendering(receivePanel)
formValuesChanged.wait()
// verify loading state was set and no errors currently
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// uuid changed
verify(root.swapAdaptor.uuid !== lastUuid)
// emit event with route that needs no approval for previous uuid
txHasRouteNoApproval.uuid = lastUuid
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
// route with old uuid should have been ignored
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit routes ready
txHasRouteNoApproval.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
// verify loading state removed and data is displayed as expected on the Modal
verify(root.swapAdaptor.validSwapProposalReceived)
verify(!root.swapAdaptor.swapProposalLoading)
closeAndVerfyModal()
}
}
}

View File

@ -40,14 +40,13 @@ StatusDialog {
})
function fetchSuggestedRoutes() {
root.swapAdaptor.invalidateSuggestedRoute()
if (root.swapInputParamsForm.isFormFilledCorrectly()) {
root.swapAdaptor.swapProposalLoading = true
debounceFetchSuggestedRoutes()
} else {
root.swapAdaptor.swapProposalLoading = false
}
root.swapAdaptor.validSwapProposalReceived = false
root.swapAdaptor.approvalPending = false
root.swapAdaptor.approvalSuccessful = false
root.swapAdaptor.swapOutputData.resetPathInfoAndError()
debounceFetchSuggestedRoutes()
}
readonly property bool isError: root.swapAdaptor.errorMessage !== ""
@ -440,9 +439,7 @@ StatusDialog {
feesLoading: root.swapAdaptor.swapProposalLoading
fromTokenSymbol: root.swapAdaptor.fromToken.symbol
fromTokenAmount: SQUtils.AmountsArithmetic.div(
SQUtils.AmountsArithmetic.fromString(root.swapAdaptor.swapOutputData.approvalAmountRequired),
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.fromToken.decimals ?? 18)).toFixed()
fromTokenAmount: root.swapInputParamsForm.fromTokenAmount
fromTokenContractAddress: SQUtils.ModelUtils.getByKey(root.swapAdaptor.fromToken.addressPerChain,
"chainId", root.swapInputParamsForm.selectedNetworkChainId,
"address")

View File

@ -274,6 +274,7 @@ QObject {
}
function reset() {
d.uuid = ""
root.swapFormData.resetFormData()
root.swapOutputData.reset()
root.validSwapProposalReceived = false
@ -302,6 +303,14 @@ QObject {
return disabledChainIds.join(":")
}
function invalidateSuggestedRoute() {
d.uuid = ""
root.validSwapProposalReceived = false
root.approvalPending = false
root.approvalSuccessful = false
root.swapOutputData.resetPathInfoAndError()
}
function fetchSuggestedRoutes(cryptoValueInRaw) {
root.swapFormData.toTokenAmount = ""
if (root.swapFormData.isFormFilledCorrectly() && !!cryptoValueInRaw) {