diff --git a/storybook/qmlTests/tests/tst_SwapModal.qml b/storybook/qmlTests/tests/tst_SwapModal.qml index c5e4b4df0b..6b5dfc4f6f 100644 --- a/storybook/qmlTests/tests/tst_SwapModal.qml +++ b/storybook/qmlTests/tests/tst_SwapModal.qml @@ -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) + } } } diff --git a/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml b/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml index 06c3b9400d..a928a2a880 100644 --- a/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml +++ b/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml @@ -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() } }