1
0

refactor btc <-> fiat amount behaviour into separate controls

This commit is contained in:
Sander van Grieken
2022-05-11 12:08:29 +02:00
parent 532d19979d
commit 5e92624f33
4 changed files with 54 additions and 53 deletions

View File

@@ -36,27 +36,10 @@ Pane {
Layout.rightMargin: constants.paddingXLarge
}
TextField {
BtcField {
id: amount
font.family: FixedFont
fiatfield: amountFiat
Layout.preferredWidth: parent.width /2
placeholderText: qsTr('Amount')
inputMethodHints: Qt.ImhPreferNumbers
property Amount textAsSats
onTextChanged: {
textAsSats = Config.unitsToSats(amount.text)
if (amountFiat.activeFocus)
return
amountFiat.text = text == '' ? '' : Daemon.fx.fiatValue(amount.textAsSats)
}
Connections {
target: Config
function onBaseUnitChanged() {
amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : ''
}
}
}
Label {
@@ -68,17 +51,11 @@ Pane {
Item { visible: Daemon.fx.enabled; width: 1; height: 1 }
TextField {
FiatField {
id: amountFiat
btcfield: amount
visible: Daemon.fx.enabled
font.family: FixedFont
Layout.preferredWidth: parent.width /2
placeholderText: qsTr('Amount')
inputMethodHints: Qt.ImhDigitsOnly
onTextChanged: {
if (amountFiat.activeFocus)
amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text))
}
}
Label {

View File

@@ -71,26 +71,10 @@ Pane {
text: qsTr('Amount')
}
TextField {
BtcField {
id: amount
font.family: FixedFont
placeholderText: qsTr('Amount')
fiatfield: amountFiat
Layout.preferredWidth: parent.width /2
inputMethodHints: Qt.ImhPreferNumbers
property Amount 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 {
@@ -103,17 +87,11 @@ Pane {
Item { width: 1; height: 1; visible: Daemon.fx.enabled }
TextField {
FiatField {
id: amountFiat
btcfield: amount
visible: Daemon.fx.enabled
font.family: FixedFont
Layout.preferredWidth: parent.width /2
placeholderText: qsTr('Amount')
inputMethodHints: Qt.ImhPreferNumbers
onTextChanged: {
if (amountFiat.activeFocus)
amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text))
}
}
Label {

View File

@@ -0,0 +1,28 @@
import QtQuick 2.6
import QtQuick.Controls 2.0
import org.electrum 1.0
TextField {
id: amount
required property TextField fiatfield
font.family: FixedFont
placeholderText: qsTr('Amount')
inputMethodHints: Qt.ImhPreferNumbers
property Amount textAsSats
onTextChanged: {
textAsSats = Config.unitsToSats(amount.text)
if (fiatfield.activeFocus)
return
fiatfield.text = text == '' ? '' : Daemon.fx.fiatValue(amount.textAsSats)
}
Connections {
target: Config
function onBaseUnitChanged() {
amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : ''
}
}
}

View File

@@ -0,0 +1,18 @@
import QtQuick 2.6
import QtQuick.Controls 2.0
import org.electrum 1.0
TextField {
id: amountFiat
required property TextField btcfield
font.family: FixedFont
placeholderText: qsTr('Amount')
inputMethodHints: Qt.ImhPreferNumbers
onTextChanged: {
if (amountFiat.activeFocus)
btcfield.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text))
}
}