fix(amm): label sample swaps as previews

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 20:40:45 -03:00
parent 8023195ec8
commit a94731881f
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
3 changed files with 71 additions and 36 deletions

View File

@ -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())
}
}
}

View File

@ -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 <font color='" + pageTheme.colors.textPrimary + "'>LEZ</font>."
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))
}
}
}
}

View File

@ -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")
}
}
}