generate and parse bip 21 qr codes
This commit is contained in:
@@ -40,6 +40,21 @@ Pane {
|
||||
Layout.preferredWidth: parent.width /2
|
||||
placeholderText: qsTr('Amount')
|
||||
inputMethodHints: Qt.ImhPreferNumbers
|
||||
|
||||
property string textAsSats
|
||||
onTextChanged: {
|
||||
textAsSats = Config.unitsToSats(amount.text)
|
||||
if (amountFiat.activeFocus)
|
||||
return
|
||||
amountFiat.text = Daemon.fx.fiatValue(amount.textAsSats)
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Config
|
||||
function onBaseUnitChanged() {
|
||||
amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
@@ -58,6 +73,10 @@ Pane {
|
||||
Layout.preferredWidth: parent.width /2
|
||||
placeholderText: qsTr('Amount')
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
onTextChanged: {
|
||||
if (amountFiat.activeFocus)
|
||||
amount.text = Daemon.fx.satoshiValue(amountFiat.text)
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
@@ -216,7 +235,7 @@ Pane {
|
||||
text: qsTr('Timestamp: ')
|
||||
}
|
||||
Label {
|
||||
text: model.timestamp
|
||||
text: model.date
|
||||
}
|
||||
|
||||
Label {
|
||||
@@ -301,32 +320,11 @@ Pane {
|
||||
}
|
||||
dialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Daemon.currentWallet
|
||||
function onRequestStatusChanged(key, status) {
|
||||
Daemon.currentWallet.requestModel.updateRequest(key, status)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: amount
|
||||
function onTextChanged() {
|
||||
if (amountFiat.activeFocus)
|
||||
return
|
||||
var a = Config.unitsToSats(amount.text)
|
||||
amountFiat.text = Daemon.fx.fiatValue(a)
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: amountFiat
|
||||
function onTextChanged() {
|
||||
if (amountFiat.activeFocus) {
|
||||
amount.text = Daemon.fx.satoshiValue(amountFiat.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: Daemon.fx
|
||||
function onQuotesUpdated() {
|
||||
|
||||
@@ -56,13 +56,12 @@ Dialog {
|
||||
}
|
||||
|
||||
Image {
|
||||
id: qr
|
||||
Layout.columnSpan: 3
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
Layout.topMargin: constants.paddingSmall
|
||||
Layout.bottomMargin: constants.paddingSmall
|
||||
|
||||
source: 'image://qrgen/' + modelItem.address
|
||||
|
||||
Rectangle {
|
||||
property int size: 57 // should be qr pixel multiple
|
||||
color: 'white'
|
||||
@@ -131,7 +130,7 @@ Dialog {
|
||||
}
|
||||
Label {
|
||||
visible: modelItem.amount > 0
|
||||
text: Config.formatSats(modelItem.amount, false)
|
||||
text: Config.formatSats(modelItem.amount)
|
||||
font.family: FixedFont
|
||||
font.pixelSize: constants.fontSizeLarge
|
||||
}
|
||||
@@ -181,4 +180,13 @@ Dialog {
|
||||
modelItem = Daemon.currentWallet.get_request(key)
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
var bip21uri = bitcoin.create_uri(modelItem.address, modelItem.amount, modelItem.message, modelItem.timestamp, modelItem.exp)
|
||||
qr.source = 'image://qrgen/' + bip21uri
|
||||
}
|
||||
|
||||
Bitcoin {
|
||||
id: bitcoin
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import QtQuick 2.6
|
||||
import QtQuick.Controls 2.0
|
||||
|
||||
import org.electrum 1.0
|
||||
|
||||
Item {
|
||||
id: scanPage
|
||||
property string title: qsTr('Scan')
|
||||
@@ -8,6 +10,8 @@ Item {
|
||||
property bool toolbar: false
|
||||
|
||||
property string scanData
|
||||
property var invoiceData: undefined
|
||||
property string error
|
||||
|
||||
signal found
|
||||
|
||||
@@ -18,6 +22,16 @@ Item {
|
||||
|
||||
onFound: {
|
||||
scanPage.scanData = scanData
|
||||
var invoice = bitcoin.parse_uri(scanData)
|
||||
if (invoice['error']) {
|
||||
error = invoice['error']
|
||||
console.log(error)
|
||||
app.stack.pop()
|
||||
return
|
||||
}
|
||||
|
||||
invoiceData = invoice
|
||||
console.log(invoiceData['address'])
|
||||
scanPage.found()
|
||||
app.stack.pop()
|
||||
}
|
||||
@@ -31,4 +45,7 @@ Item {
|
||||
onClicked: app.stack.pop()
|
||||
}
|
||||
|
||||
Bitcoin {
|
||||
id: bitcoin
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,20 @@ Pane {
|
||||
placeholderText: qsTr('Amount')
|
||||
Layout.preferredWidth: parent.width /2
|
||||
inputMethodHints: Qt.ImhPreferNumbers
|
||||
property string textAsSats
|
||||
onTextChanged: {
|
||||
textAsSats = Config.unitsToSats(amount.text)
|
||||
if (amountFiat.activeFocus)
|
||||
return
|
||||
amountFiat.text = Daemon.fx.fiatValue(amount.textAsSats)
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Config
|
||||
function onBaseUnitChanged() {
|
||||
amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
@@ -67,6 +81,10 @@ Pane {
|
||||
Layout.preferredWidth: parent.width /2
|
||||
placeholderText: qsTr('Amount')
|
||||
inputMethodHints: Qt.ImhPreferNumbers
|
||||
onTextChanged: {
|
||||
if (amountFiat.activeFocus)
|
||||
amount.text = Daemon.fx.satoshiValue(amountFiat.text)
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
@@ -113,31 +131,15 @@ Pane {
|
||||
onClicked: {
|
||||
var page = app.stack.push(Qt.resolvedUrl('Scan.qml'))
|
||||
page.onFound.connect(function() {
|
||||
console.log('got ' + page.scanData)
|
||||
address.text = page.scanData
|
||||
console.log('got ' + page.invoiceData)
|
||||
address.text = page.invoiceData['address']
|
||||
amount.text = Config.formatSats(page.invoiceData['amount'])
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: amount
|
||||
function onTextChanged() {
|
||||
if (amountFiat.activeFocus)
|
||||
return
|
||||
var a = Config.unitsToSats(amount.text)
|
||||
amountFiat.text = Daemon.fx.fiatValue(a)
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: amountFiat
|
||||
function onTextChanged() {
|
||||
if (amountFiat.activeFocus) {
|
||||
amount.text = Daemon.fx.satoshiValue(amountFiat.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: Daemon.fx
|
||||
function onQuotesUpdated() {
|
||||
|
||||
Reference in New Issue
Block a user