fix(amm): complete repeated context refreshes

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 19:54:44 -03:00
parent 1d1db9ba4e
commit a66ffddfe4
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
2 changed files with 22 additions and 1 deletions

View File

@ -165,8 +165,10 @@ void AmmUiBackend::refreshNewPositionContext(QVariantMap request)
m_newPosition->contextAsync(
request, m_network.snapshot(), isWalletOpen(), refreshWalletAccounts,
[this, generation](QVariantMap result) {
if (generation == m_contextGeneration)
if (generation == m_contextGeneration) {
result.insert(QStringLiteral("requestId"), generation);
setNewPositionContext(std::move(result));
}
});
}

View File

@ -35,6 +35,7 @@ TestCase {
"feeTiers": []
})
property int contextRefreshCalls: 0
property int contextRequestId: 0
property int submitCalls: 0
property var lastContextRefreshRequest: ({})
@ -54,6 +55,9 @@ TestCase {
function refreshNewPositionContext(request) {
++contextRefreshCalls
lastContextRefreshRequest = request
var result = JSON.parse(JSON.stringify(newPositionContext))
result.requestId = ++contextRequestId
newPositionContext = result
}
}
}
@ -112,6 +116,21 @@ TestCase {
compare(page.flow.contextHints(true).refreshWalletAccounts, true)
}
function test_repeatedIdenticalContextCompletesRefresh() {
var backend = createTemporaryObject(backendComponent, testCase)
var page = createTemporaryObject(pageComponent, testCase, { "backend": backend })
verify(page)
page.flow.refreshContext(false)
tryCompare(page.flow, "contextLoading", false)
compare(backend.contextRequestId, 1)
page.flow.refreshContext(false)
tryCompare(page.flow, "contextLoading", false)
compare(backend.contextRequestId, 2)
compare(page.flow.newPositionContext.status, "ready")
}
function test_submitFailureKeepsReturnedFreshQuoteWithoutRequery() {
var backend = createTemporaryObject(backendComponent, testCase)
var page = createTemporaryObject(pageComponent, testCase, { "backend": backend })