|
| 1 | +import QtQuick |
| 2 | +import QtQuick.Layouts |
| 3 | +import QtQuick.Controls |
| 4 | +import QtQuick.Controls.Material |
| 5 | + |
| 6 | +import org.electrum 1.0 |
| 7 | + |
| 8 | +import "controls" |
| 9 | + |
| 10 | +ElDialog { |
| 11 | + id: dialog |
| 12 | + |
| 13 | + title: qsTr('BOLT12 Offer') |
| 14 | + iconSource: '../../../icons/bolt12.png' |
| 15 | + |
| 16 | + property InvoiceParser invoiceParser |
| 17 | + |
| 18 | + padding: 0 |
| 19 | + |
| 20 | + property bool commentValid: true // TODO? |
| 21 | + property bool amountValid: amountBtc.textAsSats.satsInt > 0 |
| 22 | + property bool valid: commentValid && amountValid |
| 23 | + |
| 24 | + ColumnLayout { |
| 25 | + width: parent.width |
| 26 | + |
| 27 | + spacing: 0 |
| 28 | + |
| 29 | + GridLayout { |
| 30 | + id: rootLayout |
| 31 | + columns: 2 |
| 32 | + |
| 33 | + Layout.fillWidth: true |
| 34 | + Layout.leftMargin: constants.paddingLarge |
| 35 | + Layout.rightMargin: constants.paddingLarge |
| 36 | + Layout.bottomMargin: constants.paddingLarge |
| 37 | + |
| 38 | + // qml quirk; first cells cannot colspan without messing up the grid width |
| 39 | + Item { Layout.fillWidth: true; Layout.preferredWidth: 1; Layout.preferredHeight: 1 } |
| 40 | + Item { Layout.fillWidth: true; Layout.preferredWidth: 1; Layout.preferredHeight: 1 } |
| 41 | + |
| 42 | + Label { |
| 43 | + Layout.columnSpan: 2 |
| 44 | + text: qsTr('Issuer') |
| 45 | + color: Material.accentColor |
| 46 | + visible: 'issuer' in invoiceParser.offerData |
| 47 | + } |
| 48 | + TextHighlightPane { |
| 49 | + Layout.columnSpan: 2 |
| 50 | + Layout.fillWidth: true |
| 51 | + visible: 'issuer' in invoiceParser.offerData |
| 52 | + Label { |
| 53 | + width: parent.width |
| 54 | + wrapMode: Text.Wrap |
| 55 | + text: invoiceParser.offerData['issuer'] |
| 56 | + } |
| 57 | + } |
| 58 | + Label { |
| 59 | + Layout.columnSpan: 2 |
| 60 | + Layout.fillWidth: true |
| 61 | + text: qsTr('Description') |
| 62 | + color: Material.accentColor |
| 63 | + } |
| 64 | + TextHighlightPane { |
| 65 | + Layout.columnSpan: 2 |
| 66 | + Layout.fillWidth: true |
| 67 | + Label { |
| 68 | + width: parent.width |
| 69 | + text: invoiceParser.offerData['description'] |
| 70 | + wrapMode: Text.Wrap |
| 71 | + } |
| 72 | + } |
| 73 | + Label { |
| 74 | + Layout.columnSpan: 2 |
| 75 | + text: qsTr('Amount') |
| 76 | + color: Material.accentColor |
| 77 | + } |
| 78 | + |
| 79 | + RowLayout { |
| 80 | + Layout.columnSpan: 2 |
| 81 | + Layout.fillWidth: true |
| 82 | + BtcField { |
| 83 | + id: amountBtc |
| 84 | + Layout.preferredWidth: rootLayout.width /3 |
| 85 | + text: 'amount' in invoiceParser.offerData |
| 86 | + ? Config.formatSatsForEditing(invoiceParser.offerData['amount']/1000) |
| 87 | + : '' |
| 88 | + readOnly: 'amount' in invoiceParser.offerData |
| 89 | + color: Material.foreground // override gray-out on disabled |
| 90 | + fiatfield: amountFiat |
| 91 | + onTextAsSatsChanged: { |
| 92 | + invoiceParser.amountOverride = textAsSats |
| 93 | + } |
| 94 | + } |
| 95 | + Label { |
| 96 | + text: Config.baseUnit |
| 97 | + color: Material.accentColor |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + RowLayout { |
| 102 | + Layout.columnSpan: 2 |
| 103 | + visible: Daemon.fx.enabled |
| 104 | + FiatField { |
| 105 | + id: amountFiat |
| 106 | + Layout.preferredWidth: rootLayout.width / 3 |
| 107 | + btcfield: amountBtc |
| 108 | + readOnly: btcfield.readOnly |
| 109 | + } |
| 110 | + Label { |
| 111 | + text: Daemon.fx.fiatCurrency |
| 112 | + color: Material.accentColor |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + Label { |
| 117 | + Layout.columnSpan: 2 |
| 118 | + text: qsTr('Note') |
| 119 | + color: Material.accentColor |
| 120 | + } |
| 121 | + ElTextArea { |
| 122 | + id: note |
| 123 | + Layout.columnSpan: 2 |
| 124 | + Layout.fillWidth: true |
| 125 | + Layout.minimumHeight: 100 |
| 126 | + wrapMode: TextEdit.Wrap |
| 127 | + placeholderText: qsTr('Enter an (optional) message for the receiver') |
| 128 | + // TODO: max 100 chars is arbitrary, not sure what the max size is |
| 129 | + color: text.length > 100 ? constants.colorError : Material.foreground |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + FlatButton { |
| 134 | + Layout.topMargin: constants.paddingLarge |
| 135 | + Layout.fillWidth: true |
| 136 | + text: qsTr('Pay') |
| 137 | + icon.source: '../../icons/confirmed.png' |
| 138 | + enabled: valid |
| 139 | + onClicked: { |
| 140 | + invoiceParser.requestInvoiceFromOffer(note.text) |
| 141 | + dialog.close() |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | +} |
0 commit comments