mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-25 14:11:09 +00:00
fix(liquidity): refresh confirmation after quote change
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user