From da5c7877400cc35cb6ca3d551084429824355113 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sat, 18 Jul 2026 11:48:16 -0300 Subject: [PATCH] fix(liquidity): refresh confirmation after quote change --- apps/amm/qml/state/NewPositionFlow.qml | 39 ++++++++++++------ apps/amm/tests/qml/tst_LiquidityPage.qml | 51 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/apps/amm/qml/state/NewPositionFlow.qml b/apps/amm/qml/state/NewPositionFlow.qml index cb06ddf..0f0ddc9 100644 --- a/apps/amm/qml/state/NewPositionFlow.qml +++ b/apps/amm/qml/state/NewPositionFlow.qml @@ -209,19 +209,9 @@ QtObject { root.newPositionQuote = result.schema === "new-position.v2" ? result : root.quoteError("unsupported_schema") if (root.pendingConfirmationSnapshot) { - var snapshot = root.pendingConfirmationSnapshot + var snapshot = root.refreshConfirmationSnapshot( + root.pendingConfirmationSnapshot, root.newPositionQuote) root.pendingConfirmationSnapshot = null - snapshot.quoteHash = String(root.newPositionQuote.quoteHash || "") - snapshot.expectedLpText = String(root.newPositionQuote.expectedLpRaw || "") - + " raw LP" - snapshot.instruction = String(root.newPositionQuote.instruction || "") - snapshot.lpHoldingOptions = root.newPositionQuote.lpHoldingOptions || [] - snapshot.selectedLpHoldingId = String( - root.newPositionQuote.selectedLpHoldingId || "") - snapshot.createFreshLp = root.newPositionQuote.requiresFreshLp === true - snapshot.lpDestinationRequired = - root.newPositionQuote.lpDestinationRequired === true - snapshot.quoteReady = root.newPositionQuote.canSubmit === true root.confirmationQuoteReady(snapshot) } } @@ -281,14 +271,37 @@ QtObject { root.newPositionQuote = result.quote root.quoteLoading = false root.quoteStale = false + if (Object.keys(root.pendingSubmitSnapshot || {}).length > 0) { + var snapshot = root.refreshConfirmationSnapshot( + root.pendingSubmitSnapshot, result.quote) + root.pendingSubmitSnapshot = snapshot + root.confirmationQuoteReady(snapshot) + } } - root.flowErrorCode = result && result.code + root.flowErrorCode = hasFreshQuote && result.code === "quote_changed" + ? "" + : result && result.code ? result.code : "wallet_submission_failed" root.submitFailed() if (!hasFreshQuote) root.scheduleQuote(true, root.pendingQuoteRequest) } + function refreshConfirmationSnapshot(snapshot, quote) { + var refreshed = {} + for (var field in snapshot) + refreshed[field] = snapshot[field] + refreshed.quoteHash = String(quote.quoteHash || "") + refreshed.expectedLpText = String(quote.expectedLpRaw || "") + " raw LP" + refreshed.instruction = String(quote.instruction || "") + refreshed.lpHoldingOptions = quote.lpHoldingOptions || [] + refreshed.selectedLpHoldingId = String(quote.selectedLpHoldingId || "") + refreshed.createFreshLp = quote.requiresFreshLp === true + refreshed.lpDestinationRequired = quote.lpDestinationRequired === true + refreshed.quoteReady = quote.canSubmit === true + return refreshed + } + function watchPoolCreation(request, deadlineMs) { const key = root.pairKey(request) let deadline = Number(deadlineMs) diff --git a/apps/amm/tests/qml/tst_LiquidityPage.qml b/apps/amm/tests/qml/tst_LiquidityPage.qml index dfba297..1cc4862 100644 --- a/apps/amm/tests/qml/tst_LiquidityPage.qml +++ b/apps/amm/tests/qml/tst_LiquidityPage.qml @@ -272,6 +272,57 @@ TestCase { compare(dialog.confirmationPending, false) } + function test_quoteChangedRefreshesOpenConfirmation() { + var backend = createTemporaryObject(backendComponent, testCase, { + "deferSubmitResult": true + }) + var page = createTemporaryObject(pageComponent, testCase, { + "backend": backend, + "visible": true + }) + verify(page) + + var dialog = findChild(page, "liquidityConfirmationDialog") + verify(dialog) + dialog.openWithSnapshot({ + "quoteReady": true, + "request": ({ "schema": "new-position.v2" }), + "quoteHash": "sha256:stale", + "expectedLpText": "10 raw LP", + "instruction": "AddLiquidity" + }) + tryCompare(dialog, "opened", true) + + dialog.confirm() + tryCompare(page.flow, "submitting", true) + + backend.newPositionSubmitResult = { + "schema": "new-position.v2", + "status": "error", + "code": "quote_changed", + "quote": { + "schema": "new-position.v2", + "status": "ok", + "canSubmit": true, + "quoteHash": "sha256:fresh", + "expectedLpRaw": "20", + "instruction": "AddLiquidity", + "lpHoldingOptions": [], + "selectedLpHoldingId": "", + "requiresFreshLp": true, + "lpDestinationRequired": false + }, + "requestId": page.flow.submitRequestId + } + + tryCompare(page.flow, "submitting", false) + tryCompare(dialog, "opened", true) + compare(dialog.snapshot.quoteHash, "sha256:fresh") + compare(dialog.snapshot.expectedLpText, "20 raw LP") + compare(dialog.snapshot.quoteReady, true) + compare(page.flow.flowErrorCode, "") + } + function test_destinationRequoteUsesQuoteBusyText() { var backend = createTemporaryObject(backendComponent, testCase) var page = createTemporaryObject(pageComponent, testCase, {