refactor btc <-> fiat amount behaviour into separate controls
This commit is contained in:
@@ -36,27 +36,10 @@ Pane {
|
|||||||
Layout.rightMargin: constants.paddingXLarge
|
Layout.rightMargin: constants.paddingXLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
BtcField {
|
||||||
id: amount
|
id: amount
|
||||||
font.family: FixedFont
|
fiatfield: amountFiat
|
||||||
Layout.preferredWidth: parent.width /2
|
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 {
|
Label {
|
||||||
@@ -68,17 +51,11 @@ Pane {
|
|||||||
|
|
||||||
Item { visible: Daemon.fx.enabled; width: 1; height: 1 }
|
Item { visible: Daemon.fx.enabled; width: 1; height: 1 }
|
||||||
|
|
||||||
TextField {
|
FiatField {
|
||||||
id: amountFiat
|
id: amountFiat
|
||||||
|
btcfield: amount
|
||||||
visible: Daemon.fx.enabled
|
visible: Daemon.fx.enabled
|
||||||
font.family: FixedFont
|
|
||||||
Layout.preferredWidth: parent.width /2
|
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 {
|
Label {
|
||||||
|
|||||||
@@ -71,26 +71,10 @@ Pane {
|
|||||||
text: qsTr('Amount')
|
text: qsTr('Amount')
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
BtcField {
|
||||||
id: amount
|
id: amount
|
||||||
font.family: FixedFont
|
fiatfield: amountFiat
|
||||||
placeholderText: qsTr('Amount')
|
|
||||||
Layout.preferredWidth: parent.width /2
|
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 {
|
Label {
|
||||||
@@ -103,17 +87,11 @@ Pane {
|
|||||||
|
|
||||||
Item { width: 1; height: 1; visible: Daemon.fx.enabled }
|
Item { width: 1; height: 1; visible: Daemon.fx.enabled }
|
||||||
|
|
||||||
TextField {
|
FiatField {
|
||||||
id: amountFiat
|
id: amountFiat
|
||||||
|
btcfield: amount
|
||||||
visible: Daemon.fx.enabled
|
visible: Daemon.fx.enabled
|
||||||
font.family: FixedFont
|
|
||||||
Layout.preferredWidth: parent.width /2
|
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 {
|
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