fix(swap): invalidate old uuid and route when a new route request is made
Fixes #16574
This commit is contained in:
parent
9e5a172632
commit
1c378cc9ae
|
@ -1866,5 +1866,61 @@ Item {
|
||||||
// wait(root.swapFormData.autoRefreshTime*2)
|
// wait(root.swapFormData.autoRefreshTime*2)
|
||||||
// compare(fetchSuggestedRoutesCalled.count, 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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,13 @@ StatusDialog {
|
||||||
})
|
})
|
||||||
|
|
||||||
function fetchSuggestedRoutes() {
|
function fetchSuggestedRoutes() {
|
||||||
|
root.swapAdaptor.invalidateSuggestedRoute()
|
||||||
if (root.swapInputParamsForm.isFormFilledCorrectly()) {
|
if (root.swapInputParamsForm.isFormFilledCorrectly()) {
|
||||||
root.swapAdaptor.swapProposalLoading = true
|
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 !== ""
|
readonly property bool isError: root.swapAdaptor.errorMessage !== ""
|
||||||
|
@ -440,9 +439,7 @@ StatusDialog {
|
||||||
feesLoading: root.swapAdaptor.swapProposalLoading
|
feesLoading: root.swapAdaptor.swapProposalLoading
|
||||||
|
|
||||||
fromTokenSymbol: root.swapAdaptor.fromToken.symbol
|
fromTokenSymbol: root.swapAdaptor.fromToken.symbol
|
||||||
fromTokenAmount: SQUtils.AmountsArithmetic.div(
|
fromTokenAmount: root.swapInputParamsForm.fromTokenAmount
|
||||||
SQUtils.AmountsArithmetic.fromString(root.swapAdaptor.swapOutputData.approvalAmountRequired),
|
|
||||||
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.fromToken.decimals ?? 18)).toFixed()
|
|
||||||
fromTokenContractAddress: SQUtils.ModelUtils.getByKey(root.swapAdaptor.fromToken.addressPerChain,
|
fromTokenContractAddress: SQUtils.ModelUtils.getByKey(root.swapAdaptor.fromToken.addressPerChain,
|
||||||
"chainId", root.swapInputParamsForm.selectedNetworkChainId,
|
"chainId", root.swapInputParamsForm.selectedNetworkChainId,
|
||||||
"address")
|
"address")
|
||||||
|
|
|
@ -274,6 +274,7 @@ QObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
|
d.uuid = ""
|
||||||
root.swapFormData.resetFormData()
|
root.swapFormData.resetFormData()
|
||||||
root.swapOutputData.reset()
|
root.swapOutputData.reset()
|
||||||
root.validSwapProposalReceived = false
|
root.validSwapProposalReceived = false
|
||||||
|
@ -302,6 +303,14 @@ QObject {
|
||||||
return disabledChainIds.join(":")
|
return disabledChainIds.join(":")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invalidateSuggestedRoute() {
|
||||||
|
d.uuid = ""
|
||||||
|
root.validSwapProposalReceived = false
|
||||||
|
root.approvalPending = false
|
||||||
|
root.approvalSuccessful = false
|
||||||
|
root.swapOutputData.resetPathInfoAndError()
|
||||||
|
}
|
||||||
|
|
||||||
function fetchSuggestedRoutes(cryptoValueInRaw) {
|
function fetchSuggestedRoutes(cryptoValueInRaw) {
|
||||||
root.swapFormData.toTokenAmount = ""
|
root.swapFormData.toTokenAmount = ""
|
||||||
if (root.swapFormData.isFormFilledCorrectly() && !!cryptoValueInRaw) {
|
if (root.swapFormData.isFormFilledCorrectly() && !!cryptoValueInRaw) {
|
||||||
|
|
Loading…
Reference in New Issue