Skip to content

Commit

Permalink
fix(@desktop/wallet): Swap "Approve" button becomes enabled before Ap…
Browse files Browse the repository at this point in the history
…prove Tx succeeds/fails

fixes #15784
  • Loading branch information
Khushboo-dev-cpp committed Jul 29, 2024
1 parent 0e0b264 commit 354f2e4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
48 changes: 46 additions & 2 deletions storybook/qmlTests/tests/tst_SwapModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
}
9 changes: 6 additions & 3 deletions ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -83,8 +87,7 @@ StatusDialog {
}
}
function onSuggestedRoutesReady() {
if(!root.swapAdaptor.swapProposalLoading)
d.autoRefreshTimer.restart()
d.autoRefreshTimer.restart()
}
}

Expand Down

0 comments on commit 354f2e4

Please sign in to comment.