Files
lez-programs/apps/amm/qml/components/swap/SwapConfirmationSummary.qml
r4bbit 4363f13912 feat(apps/amm): submit exact-output swaps and drop client-side swap math
Wire the Buy direction to submit: AmmUiBackend gains a swapExactOutput slot
(guarded like swapExactInput), SwapCard.executeSwap branches on direction —
sell -> swapExactInput(minReceivedRaw), buy -> swapExactOutput(maxInRaw) — and
canSubmit/submitButtonText/buildSnapshot handle both. The confirmation dialog
switches wording by mode ("You pay at most" / "You receive exactly" for exact
output). The Buy field is now digitsOnly since its value is submitted as a raw
base-units integer.

With both directions priced and oriented by the module, the client no longer
needs any pool math. Remove the reserve-orientation chain (sellIsPoolA,
buy/sellReserveNum, poolReserveA/B, poolDefAHex) — resolvePool now reports only
existence and fee — and the now-dead helpers (formatBaseUnits/formatAmountValue,
DummySwapState.amountInFor/minReceived/priceImpactPercent/maxSent). The
impossible-swap guard moves from a client reserve compare to the module's
output_exceeds_liquidity error, surfaced as "Insufficient liquidity".
2026-08-06 23:15:02 +02:00

95 lines
3.0 KiB
QML

import QtQuick
import QtQuick.Layouts
ColumnLayout {
id: root
property var theme
property var snapshot: ({})
// Exact output guarantees the received amount and caps the spent amount;
// exact input is the reverse. The wording and which value is the bound flip
// accordingly.
readonly property bool isExactOut: (root.snapshot.swapMode || "") === "swap-exact-output"
spacing: 10
Rectangle {
Layout.fillWidth: true
color: root.theme.colors.inputBg
radius: 8
implicitHeight: payColumn.implicitHeight + 24
ColumnLayout {
id: payColumn
anchors.fill: parent
anchors.margins: 12
spacing: 4
Text {
Layout.fillWidth: true
text: root.isExactOut ? qsTr("You pay at most") : qsTr("You pay")
color: root.theme.colors.textSecondary
font.pixelSize: 12
}
Text {
Layout.fillWidth: true
text: qsTr("%1 %2")
.arg((root.isExactOut ? root.snapshot.boundValue : root.snapshot.sellAmount) || "")
.arg(root.snapshot.sellToken || "")
color: root.theme.colors.textPrimary
font.bold: true
font.pixelSize: 18
elide: Text.ElideRight
}
}
}
Rectangle {
Layout.fillWidth: true
color: root.theme.colors.inputBg
radius: 8
implicitHeight: receiveColumn.implicitHeight + 24
ColumnLayout {
id: receiveColumn
anchors.fill: parent
anchors.margins: 12
spacing: 4
Text {
Layout.fillWidth: true
text: root.isExactOut ? qsTr("You receive exactly") : qsTr("You receive at least")
color: root.theme.colors.textSecondary
font.pixelSize: 12
}
Text {
Layout.fillWidth: true
text: qsTr("%1 %2")
.arg((root.isExactOut ? root.snapshot.buyAmount : root.snapshot.boundValue) || "")
.arg(root.snapshot.buyToken || "")
color: root.theme.colors.textPrimary
font.bold: true
font.pixelSize: 18
elide: Text.ElideRight
}
}
}
SwapSummary {
Layout.fillWidth: true
theme: root.theme
swapModeText: root.snapshot.swapModeText || ""
feeText: root.snapshot.feeAmount || ""
priceImpactText: root.snapshot.priceImpactPercent || ""
priceImpactPercent: Number(root.snapshot.priceImpactPercentValue) || 0
slippageText: root.snapshot.slippageTolerance || ""
boundLabel: root.isExactOut ? qsTr("Maximum sent") : qsTr("Min received")
boundText: qsTr("%1 %2")
.arg(root.snapshot.boundValue || "")
.arg((root.isExactOut ? root.snapshot.sellToken : root.snapshot.buyToken) || "")
}
}