qml: add max amount option in invoice dialog and show in invoice delegate
This commit is contained in:
@@ -26,6 +26,8 @@ ElDialog {
|
||||
color: "#aa000000"
|
||||
}
|
||||
|
||||
property bool _canMax: invoice.invoiceType == Invoice.OnchainInvoice
|
||||
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
@@ -172,6 +174,16 @@ ElDialog {
|
||||
columns: 2
|
||||
|
||||
Label {
|
||||
visible: invoice.amount.isMax
|
||||
Layout.columnSpan: 2
|
||||
font.pixelSize: constants.fontSizeXLarge
|
||||
font.bold: true
|
||||
Layout.fillWidth: true
|
||||
text: qsTr('All on-chain funds')
|
||||
}
|
||||
|
||||
Label {
|
||||
visible: !invoice.amount.isMax
|
||||
font.pixelSize: constants.fontSizeXLarge
|
||||
font.family: FixedFont
|
||||
font.bold: true
|
||||
@@ -179,6 +191,7 @@ ElDialog {
|
||||
}
|
||||
|
||||
Label {
|
||||
visible: !invoice.amount.isMax
|
||||
Layout.fillWidth: true
|
||||
text: Config.baseUnit
|
||||
color: Material.accentColor
|
||||
@@ -187,14 +200,14 @@ ElDialog {
|
||||
|
||||
Label {
|
||||
id: fiatValue
|
||||
visible: Daemon.fx.enabled
|
||||
visible: Daemon.fx.enabled && !invoice.amount.isMax
|
||||
text: Daemon.fx.fiatValue(invoice.amount, false)
|
||||
font.pixelSize: constants.fontSizeMedium
|
||||
color: constants.mutedForeground
|
||||
}
|
||||
|
||||
Label {
|
||||
visible: Daemon.fx.enabled
|
||||
visible: Daemon.fx.enabled && !invoice.amount.isMax
|
||||
Layout.fillWidth: true
|
||||
text: Daemon.fx.fiatCurrency
|
||||
font.pixelSize: constants.fontSizeMedium
|
||||
@@ -209,6 +222,7 @@ ElDialog {
|
||||
icon.color: 'transparent'
|
||||
onClicked: {
|
||||
amountBtc.text = invoice.amount.satsInt == 0 ? '' : Config.formatSats(invoice.amount)
|
||||
amountMax.checked = invoice.amount.isMax
|
||||
amountContainer.editmode = true
|
||||
amountBtc.focus = true
|
||||
}
|
||||
@@ -216,26 +230,42 @@ ElDialog {
|
||||
GridLayout {
|
||||
visible: amountContainer.editmode
|
||||
Layout.fillWidth: true
|
||||
columns: 2
|
||||
columns: 3
|
||||
BtcField {
|
||||
id: amountBtc
|
||||
fiatfield: amountFiat
|
||||
enabled: !amountMax.checked
|
||||
}
|
||||
|
||||
Label {
|
||||
text: Config.baseUnit
|
||||
color: Material.accentColor
|
||||
Layout.fillWidth: amountMax.visible ? false : true
|
||||
Layout.columnSpan: amountMax.visible ? 1 : 2
|
||||
}
|
||||
Switch {
|
||||
id: amountMax
|
||||
text: qsTr('Max')
|
||||
visible: _canMax
|
||||
Layout.fillWidth: true
|
||||
checked: invoice.amount.isMax
|
||||
onCheckedChanged: {
|
||||
if (activeFocus) {
|
||||
invoice.amount.isMax = checked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FiatField {
|
||||
id: amountFiat
|
||||
btcfield: amountBtc
|
||||
visible: Daemon.fx.enabled
|
||||
visible: Daemon.fx.enabled && !amountMax.checked
|
||||
enabled: !amountMax.checked
|
||||
}
|
||||
|
||||
Label {
|
||||
visible: Daemon.fx.enabled
|
||||
Layout.columnSpan: 2
|
||||
visible: Daemon.fx.enabled && !amountMax.checked
|
||||
text: Daemon.fx.fiatCurrency
|
||||
color: Material.accentColor
|
||||
}
|
||||
@@ -247,7 +277,7 @@ ElDialog {
|
||||
icon.color: 'transparent'
|
||||
onClicked: {
|
||||
amountContainer.editmode = false
|
||||
invoice.amount = Config.unitsToSats(amountBtc.text)
|
||||
invoice.amount = amountMax.checked ? MAX : Config.unitsToSats(amountBtc.text)
|
||||
}
|
||||
}
|
||||
ToolButton {
|
||||
@@ -315,7 +345,7 @@ ElDialog {
|
||||
if (invoice_key != '') {
|
||||
invoice.initFromKey(invoice_key)
|
||||
}
|
||||
if (invoice.amount.satsInt == 0)
|
||||
if (invoice.amount.isEmpty)
|
||||
amountContainer.editmode = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,17 @@ ItemDelegate {
|
||||
|
||||
Label {
|
||||
id: amount
|
||||
text: model.amount.isEmpty ? '' : Config.formatSats(model.amount)
|
||||
text: model.amount.isEmpty
|
||||
? ''
|
||||
: model.amount.isMax
|
||||
? 'MAX'
|
||||
: Config.formatSats(model.amount)
|
||||
font.pixelSize: constants.fontSizeMedium
|
||||
font.family: FixedFont
|
||||
}
|
||||
|
||||
Label {
|
||||
text: model.amount.isEmpty ? '' : Config.baseUnit
|
||||
text: model.amount.isEmpty || model.amount.isMax ? '' : Config.baseUnit
|
||||
font.pixelSize: constants.fontSizeMedium
|
||||
color: Material.accentColor
|
||||
}
|
||||
@@ -105,14 +109,14 @@ ItemDelegate {
|
||||
}
|
||||
Label {
|
||||
id: fiatValue
|
||||
visible: Daemon.fx.enabled
|
||||
visible: Daemon.fx.enabled && !model.amount.isMax
|
||||
Layout.alignment: Qt.AlignRight
|
||||
text: model.amount.isEmpty ? '' : Daemon.fx.fiatValue(model.amount, false)
|
||||
font.family: FixedFont
|
||||
font.pixelSize: constants.fontSizeSmall
|
||||
}
|
||||
Label {
|
||||
visible: Daemon.fx.enabled
|
||||
visible: Daemon.fx.enabled && !model.amount.isMax
|
||||
Layout.alignment: Qt.AlignRight
|
||||
text: model.amount.isEmpty ? '' : Daemon.fx.fiatCurrency
|
||||
font.pixelSize: constants.fontSizeSmall
|
||||
|
||||
@@ -182,7 +182,7 @@ class QEInvoiceParser(QEInvoice):
|
||||
def amount(self, new_amount):
|
||||
self._logger.debug(f'set new amount {repr(new_amount)}')
|
||||
if self._effectiveInvoice:
|
||||
self._effectiveInvoice.amount_msat = int(new_amount.satsInt * 1000)
|
||||
self._effectiveInvoice.amount_msat = '!' if new_amount.isMax else int(new_amount.satsInt * 1000)
|
||||
|
||||
self.determine_can_pay()
|
||||
self.invoiceChanged.emit()
|
||||
|
||||
Reference in New Issue
Block a user