Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions storybook/qmlTests/tests/tst_SwapModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,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 @@ -1815,5 +1815,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)
Khushboo-dev-cpp marked this conversation as resolved.
Show resolved Hide resolved
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