fix(@desktop/wallet): Swap "Approve" button becomes enabled before Approve Tx succeeds/fails

fixes #15784
This commit is contained in:
Khushboo Mehta 2024-07-25 12:23:00 +02:00 committed by Khushboo-dev-cpp
parent 0e0b264f4d
commit 354f2e4359
2 changed files with 52 additions and 5 deletions

View File

@ -1768,8 +1768,8 @@ Item {
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
root.swapFormData.selectedNetworkChainId = 11155111
root.swapFormData.fromTokensKey = "ETH"
// for testing making it 1.5 seconds so as to not make tests running too long
root.swapFormData.autoRefreshTime = 1500
// for testing making it 1.2 seconds so as to not make tests running too long
root.swapFormData.autoRefreshTime = 1200
// Launch popup
launchAndVerfyModal()
@ -1818,5 +1818,49 @@ Item {
compare(amountToSendInput.input.text, expectedAmount)
}
}
function test_no_auto_refresh_when_proposalLoading_or_approvalPending() {
fetchSuggestedRoutesCalled.clear()
root.swapFormData.fromTokenAmount = "0.0001"
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
root.swapFormData.selectedNetworkChainId = 11155111
root.swapFormData.fromTokensKey = "ETH"
// for testing making it 1.2 seconds so as to not make tests running too long
root.swapFormData.autoRefreshTime = 1200
// Launch popup
launchAndVerfyModal()
// check if fetchSuggestedRoutes called
tryCompare(fetchSuggestedRoutesCalled, "count", 1)
// no new calls to fetch new proposal should be made as the proposal is still loading
wait(root.swapFormData.autoRefreshTime*2)
compare(fetchSuggestedRoutesCalled.count, 1)
// emit routes ready
let txHasRouteApproval = root.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded
txHasRouteApproval.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txHasRouteApproval, "", "")
// now refresh can occur as no propsal or signing is pending
tryCompare(fetchSuggestedRoutesCalled, "count", 2)
// emit routes ready
txHasRouteApproval.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txHasRouteApproval, "", "")
verify(root.swapAdaptor.swapOutputData.approvalNeeded)
verify(!root.swapAdaptor.approvalPending)
// sign approval and check that auto refresh doesnt occur
root.swapAdaptor.sendApproveTx()
// no new calls to fetch new proposal should be made as the approval is pending
verify(root.swapAdaptor.swapOutputData.approvalNeeded)
verify(root.swapAdaptor.approvalPending)
wait(root.swapFormData.autoRefreshTime*2)
compare(fetchSuggestedRoutesCalled.count, 2)
}
}
}

View File

@ -42,7 +42,11 @@ StatusDialog {
interval: root.swapInputParamsForm.autoRefreshTime
running: false
repeat: false
onTriggered: d.fetchSuggestedRoutes()
onTriggered: {
if(!root.swapAdaptor.swapProposalLoading && !root.swapAdaptor.approvalPending) {
d.fetchSuggestedRoutes()
}
}
}
function fetchSuggestedRoutes() {
@ -83,8 +87,7 @@ StatusDialog {
}
}
function onSuggestedRoutesReady() {
if(!root.swapAdaptor.swapProposalLoading)
d.autoRefreshTimer.restart()
d.autoRefreshTimer.restart()
}
}