Browse Source

qml: add max amount option in invoice dialog and show in invoice delegate

patch-4
Sander van Grieken 2 years ago
parent
commit
65250e69d8
  1. 44
      electrum/gui/qml/components/InvoiceDialog.qml
  2. 12
      electrum/gui/qml/components/controls/InvoiceDelegate.qml
  3. 2
      electrum/gui/qml/qeinvoice.py

44
electrum/gui/qml/components/InvoiceDialog.qml

@ -26,6 +26,8 @@ ElDialog {
color: "#aa000000" color: "#aa000000"
} }
property bool _canMax: invoice.invoiceType == Invoice.OnchainInvoice
ColumnLayout { ColumnLayout {
width: parent.width width: parent.width
height: parent.height height: parent.height
@ -172,6 +174,16 @@ ElDialog {
columns: 2 columns: 2
Label { 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.pixelSize: constants.fontSizeXLarge
font.family: FixedFont font.family: FixedFont
font.bold: true font.bold: true
@ -179,6 +191,7 @@ ElDialog {
} }
Label { Label {
visible: !invoice.amount.isMax
Layout.fillWidth: true Layout.fillWidth: true
text: Config.baseUnit text: Config.baseUnit
color: Material.accentColor color: Material.accentColor
@ -187,14 +200,14 @@ ElDialog {
Label { Label {
id: fiatValue id: fiatValue
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && !invoice.amount.isMax
text: Daemon.fx.fiatValue(invoice.amount, false) text: Daemon.fx.fiatValue(invoice.amount, false)
font.pixelSize: constants.fontSizeMedium font.pixelSize: constants.fontSizeMedium
color: constants.mutedForeground color: constants.mutedForeground
} }
Label { Label {
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && !invoice.amount.isMax
Layout.fillWidth: true Layout.fillWidth: true
text: Daemon.fx.fiatCurrency text: Daemon.fx.fiatCurrency
font.pixelSize: constants.fontSizeMedium font.pixelSize: constants.fontSizeMedium
@ -209,6 +222,7 @@ ElDialog {
icon.color: 'transparent' icon.color: 'transparent'
onClicked: { onClicked: {
amountBtc.text = invoice.amount.satsInt == 0 ? '' : Config.formatSats(invoice.amount) amountBtc.text = invoice.amount.satsInt == 0 ? '' : Config.formatSats(invoice.amount)
amountMax.checked = invoice.amount.isMax
amountContainer.editmode = true amountContainer.editmode = true
amountBtc.focus = true amountBtc.focus = true
} }
@ -216,26 +230,42 @@ ElDialog {
GridLayout { GridLayout {
visible: amountContainer.editmode visible: amountContainer.editmode
Layout.fillWidth: true Layout.fillWidth: true
columns: 2 columns: 3
BtcField { BtcField {
id: amountBtc id: amountBtc
fiatfield: amountFiat fiatfield: amountFiat
enabled: !amountMax.checked
} }
Label { Label {
text: Config.baseUnit text: Config.baseUnit
color: Material.accentColor 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 Layout.fillWidth: true
checked: invoice.amount.isMax
onCheckedChanged: {
if (activeFocus) {
invoice.amount.isMax = checked
}
}
} }
FiatField { FiatField {
id: amountFiat id: amountFiat
btcfield: amountBtc btcfield: amountBtc
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && !amountMax.checked
enabled: !amountMax.checked
} }
Label { Label {
visible: Daemon.fx.enabled Layout.columnSpan: 2
visible: Daemon.fx.enabled && !amountMax.checked
text: Daemon.fx.fiatCurrency text: Daemon.fx.fiatCurrency
color: Material.accentColor color: Material.accentColor
} }
@ -247,7 +277,7 @@ ElDialog {
icon.color: 'transparent' icon.color: 'transparent'
onClicked: { onClicked: {
amountContainer.editmode = false amountContainer.editmode = false
invoice.amount = Config.unitsToSats(amountBtc.text) invoice.amount = amountMax.checked ? MAX : Config.unitsToSats(amountBtc.text)
} }
} }
ToolButton { ToolButton {
@ -315,7 +345,7 @@ ElDialog {
if (invoice_key != '') { if (invoice_key != '') {
invoice.initFromKey(invoice_key) invoice.initFromKey(invoice_key)
} }
if (invoice.amount.satsInt == 0) if (invoice.amount.isEmpty)
amountContainer.editmode = true amountContainer.editmode = true
} }
} }

12
electrum/gui/qml/components/controls/InvoiceDelegate.qml

@ -67,13 +67,17 @@ ItemDelegate {
Label { Label {
id: amount 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.pixelSize: constants.fontSizeMedium
font.family: FixedFont font.family: FixedFont
} }
Label { Label {
text: model.amount.isEmpty ? '' : Config.baseUnit text: model.amount.isEmpty || model.amount.isMax ? '' : Config.baseUnit
font.pixelSize: constants.fontSizeMedium font.pixelSize: constants.fontSizeMedium
color: Material.accentColor color: Material.accentColor
} }
@ -105,14 +109,14 @@ ItemDelegate {
} }
Label { Label {
id: fiatValue id: fiatValue
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && !model.amount.isMax
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: model.amount.isEmpty ? '' : Daemon.fx.fiatValue(model.amount, false) text: model.amount.isEmpty ? '' : Daemon.fx.fiatValue(model.amount, false)
font.family: FixedFont font.family: FixedFont
font.pixelSize: constants.fontSizeSmall font.pixelSize: constants.fontSizeSmall
} }
Label { Label {
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && !model.amount.isMax
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: model.amount.isEmpty ? '' : Daemon.fx.fiatCurrency text: model.amount.isEmpty ? '' : Daemon.fx.fiatCurrency
font.pixelSize: constants.fontSizeSmall font.pixelSize: constants.fontSizeSmall

2
electrum/gui/qml/qeinvoice.py

@ -182,7 +182,7 @@ class QEInvoiceParser(QEInvoice):
def amount(self, new_amount): def amount(self, new_amount):
self._logger.debug(f'set new amount {repr(new_amount)}') self._logger.debug(f'set new amount {repr(new_amount)}')
if self._effectiveInvoice: 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.determine_can_pay()
self.invoiceChanged.emit() self.invoiceChanged.emit()

Loading…
Cancel
Save