refactor btc <-> fiat amount behaviour into separate controls
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
28
electrum/gui/qml/components/controls/BtcField.qml
Normal file
28
electrum/gui/qml/components/controls/BtcField.qml
Normal 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) : ''
|
||||
}
|
||||
}
|
||||
}
|
||||
18
electrum/gui/qml/components/controls/FiatField.qml
Normal file
18
electrum/gui/qml/components/controls/FiatField.qml
Normal 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user