From a94731881fb8844728ebe9ba291428c0e3c9dc7b Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Fri, 17 Jul 2026 20:40:45 -0300 Subject: [PATCH] fix(amm): label sample swaps as previews --- apps/amm/qml/components/swap/SwapCard.qml | 13 ++---- apps/amm/qml/pages/SwapPage.qml | 37 ++++----------- apps/amm/tests/qml/tst_SwapPage.qml | 57 +++++++++++++++++++++++ 3 files changed, 71 insertions(+), 36 deletions(-) create mode 100644 apps/amm/tests/qml/tst_SwapPage.qml diff --git a/apps/amm/qml/components/swap/SwapCard.qml b/apps/amm/qml/components/swap/SwapCard.qml index 5a3f601..4583099 100644 --- a/apps/amm/qml/components/swap/SwapCard.qml +++ b/apps/amm/qml/components/swap/SwapCard.qml @@ -22,19 +22,13 @@ Rectangle { } signal requestTokenSelect(string side) - signal submitRequested(var snapshot) + signal previewRequested(var snapshot) function setToken(side, token) { if (side === "sell") root.sellToken = token else root.buyToken = token } - function resetAmounts() { - root.sellInput = "" - root.buyInput = "" - root.editingSide = "sell" - } - readonly property real sellReserve: sellToken ? (sellToken.reserve || 0) : 0 readonly property real buyReserve: buyToken ? (buyToken.reserve || 0) : 0 @@ -73,7 +67,7 @@ Rectangle { if (!hasAmount || !tokensSelected) return qsTr("Enter an amount") if (insufficientBalance) return qsTr("Insufficient balance") if (insufficientLiquidity) return qsTr("Insufficient liquidity") - return qsTr("Swap") + return qsTr("Preview swap") } function formatAmountValue(val) { @@ -235,6 +229,7 @@ Rectangle { Rectangle { id: ctaBox + objectName: "swapPreviewButton" Layout.fillWidth: true Layout.topMargin: 8 Layout.bottomMargin: 8 @@ -262,7 +257,7 @@ Rectangle { enabled: root.canSubmit cursorShape: root.canSubmit ? Qt.PointingHandCursor : Qt.ArrowCursor onClicked: { - if (root.canSubmit) root.submitRequested(root.buildSnapshot()) + if (root.canSubmit) root.previewRequested(root.buildSnapshot()) } } } diff --git a/apps/amm/qml/pages/SwapPage.qml b/apps/amm/qml/pages/SwapPage.qml index f4aca1a..df872f4 100644 --- a/apps/amm/qml/pages/SwapPage.qml +++ b/apps/amm/qml/pages/SwapPage.qml @@ -93,6 +93,7 @@ Item { SwapCard { id: swapCard + objectName: "swapCard" Layout.alignment: Qt.AlignHCenter theme: pageTheme tokens: root.tokens @@ -103,18 +104,20 @@ Item { tokenModal.open() } - onSubmitRequested: function(snapshot) { + onPreviewRequested: function(snapshot) { swapConfirmationDialog.openWithSnapshot(snapshot) } } Text { + objectName: "swapPreviewNotice" Layout.alignment: Qt.AlignHCenter - text: "Buy and sell crypto on LEZ." - textFormat: Text.RichText + Layout.maximumWidth: Math.max(0, Math.min(480, root.width - 32)) + text: qsTr("Preview only — sample data. No swap will be submitted.") color: pageTheme.colors.textSecondary font.pixelSize: 15 horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap } } @@ -133,18 +136,6 @@ Item { } } - SuccessToast { - id: swapToast - - width: Math.max(0, Math.min(380, parent.width - 32)) - - anchors { - bottom: parent.bottom - bottomMargin: 24 - horizontalCenter: parent.horizontalCenter - } - } - Component { id: swapConfirmationSummary @@ -155,19 +146,11 @@ Item { TransactionConfirmationDialog { id: swapConfirmationDialog - title: qsTr("Confirm swap") - confirmText: qsTr("Confirm swap") + objectName: "swapPreviewDialog" + title: qsTr("Swap preview") + cancelText: qsTr("Back") + confirmText: qsTr("Done") summary: swapConfirmationSummary - - onConfirmed: function(snapshot) { - swapCard.resetAmounts() - swapToast.show(qsTr("Swap submitted"), - qsTr("%1 %2 → %3 %4") - .arg(snapshot.sellAmount) - .arg(snapshot.sellToken) - .arg(snapshot.minReceived) - .arg(snapshot.buyToken)) - } } } } diff --git a/apps/amm/tests/qml/tst_SwapPage.qml b/apps/amm/tests/qml/tst_SwapPage.qml new file mode 100644 index 0000000..bd6f66b --- /dev/null +++ b/apps/amm/tests/qml/tst_SwapPage.qml @@ -0,0 +1,57 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import QtTest + +import "../../qml/pages" as Pages + +Item { + id: root + + width: 800 + height: 700 + + Component { + id: pageComponent + + Pages.SwapPage { + width: root.width + height: root.height + } + } + + TestCase { + name: "SwapPage" + when: windowShown + + function test_tradeIsExplicitPreviewAndPreservesDraft() { + const page = createTemporaryObject(pageComponent, root) + verify(page) + + const notice = findChild(page, "swapPreviewNotice") + const card = findChild(page, "swapCard") + const dialog = findChild(page, "swapPreviewDialog") + verify(notice) + verify(card) + verify(dialog) + verify(notice.text.indexOf("Preview only") >= 0) + verify(notice.text.indexOf("No swap will be submitted") >= 0) + + card.setToken("sell", page.tokens[0]) + card.setToken("buy", page.tokens[1]) + card.sellInput = "1" + card.editingSide = "sell" + tryCompare(card, "canSubmit", true) + compare(card.submitButtonText, "Preview swap") + + card.previewRequested(card.buildSnapshot()) + tryCompare(dialog, "opened", true) + compare(dialog.title, "Swap preview") + compare(findChild(dialog, "transactionConfirmButton").text, "Done") + + dialog.confirm() + tryCompare(dialog, "opened", false) + compare(card.sellInput, "1") + } + } +}