Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions apps/amm/qml/components/swap/TokenListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ Item {
property string tokenName: ""
property string tokenSymbol: ""
property string tokenDefinitionId: ""
// When true, the token is already selected on the other side of the swap,
// so it's shown dimmed and can't be picked (a pool needs two distinct
// tokens — picking the same one both sides panics amm_core's pool PDA).
property bool disabled: false

signal clicked()

implicitHeight: 56
opacity: root.disabled ? 0.35 : 1.0

Rectangle {
anchors.fill: parent
radius: 12
color: hoverArea.containsMouse ? theme.colors.panelBg : "transparent"
color: (!root.disabled && hoverArea.containsMouse) ? theme.colors.panelBg : "transparent"
Behavior on color { ColorAnimation { duration: 120 } }

RowLayout {
Expand Down Expand Up @@ -62,13 +67,21 @@ Item {
}
}
}

Text {
visible: root.disabled
text: qsTr("Selected")
color: theme.colors.textSecondary
font.pixelSize: 12
}
}

MouseArea {
id: hoverArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
enabled: !root.disabled
hoverEnabled: !root.disabled
cursorShape: root.disabled ? Qt.ArrowCursor : Qt.PointingHandCursor
onClicked: root.clicked()
}
}
Expand Down
18 changes: 15 additions & 3 deletions apps/amm/qml/components/swap/TokenSelectorModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Item {
property var theme
property var tokens: []
property string searchText: ""
// definitionId of the token already chosen on the other side of the swap.
// That token is shown disabled here so the two sides can never match (a
// same-token pool has no PDA — it panics amm_core).
property string disabledDefinitionId: ""

signal tokenSelected(var token)

Expand Down Expand Up @@ -115,12 +119,17 @@ Item {
Repeater {
model: root.tokens.slice(0, 5)
delegate: Rectangle {
id: pill
readonly property bool isDisabled:
root.disabledDefinitionId !== "" &&
modelData.definitionId === root.disabledDefinitionId
height: 40
radius: 20
color: pillHover.containsMouse ? theme.colors.panelHoverBg : theme.colors.panelBg
color: (!pill.isDisabled && pillHover.containsMouse) ? theme.colors.panelHoverBg : theme.colors.panelBg
border.color: theme.colors.border
border.width: 1
width: pillRow.implicitWidth + 24
opacity: pill.isDisabled ? 0.35 : 1.0
Behavior on color { ColorAnimation { duration: 120 } }
RowLayout {
id: pillRow
Expand All @@ -136,8 +145,9 @@ Item {
MouseArea {
id: pillHover
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
enabled: !pill.isDisabled
hoverEnabled: !pill.isDisabled
cursorShape: pill.isDisabled ? Qt.ArrowCursor : Qt.PointingHandCursor
onClicked: root.tokenSelected(modelData)
}
}
Expand All @@ -164,6 +174,8 @@ Item {
tokenName: modelData.name
tokenSymbol: modelData.symbol
tokenDefinitionId: modelData.definitionId
disabled: root.disabledDefinitionId !== "" &&
modelData.definitionId === root.disabledDefinitionId
onClicked: root.tokenSelected(modelData)
}
}
Expand Down
4 changes: 4 additions & 0 deletions apps/amm/qml/pages/SwapPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Item {

onRequestTokenSelect: function(side) {
tokenModal.targetSide = side
// Disable the token already picked on the opposite side so the
// two sides can't match (a same-token pool panics amm_core).
var other = side === "sell" ? swapCard.buyToken : swapCard.sellToken
tokenModal.disabledDefinitionId = other ? other.definitionId : ""
tokenModal.open()
}

Expand Down