Browse Source

qml: BalanceSummary now flipflops between fiat view and btc view

master
Sander van Grieken 3 years ago
parent
commit
aaca7c58ad
  1. 70
      electrum/gui/qml/components/controls/BalanceSummary.qml

70
electrum/gui/qml/components/controls/BalanceSummary.qml

@ -9,20 +9,31 @@ Item {
implicitWidth: balancePane.implicitWidth implicitWidth: balancePane.implicitWidth
implicitHeight: balancePane.implicitHeight implicitHeight: balancePane.implicitHeight
property string formattedConfirmedBalance
property string formattedTotalBalance property string formattedTotalBalance
property string formattedTotalBalanceFiat property string formattedTotalBalanceFiat
property string formattedLightningCanSend property string formattedLightningBalance
property string formattedLightningCanSendFiat
function setBalances() { function setBalances() {
root.formattedConfirmedBalance = Config.formatSats(Daemon.currentWallet.confirmedBalance)
root.formattedTotalBalance = Config.formatSats(Daemon.currentWallet.totalBalance) root.formattedTotalBalance = Config.formatSats(Daemon.currentWallet.totalBalance)
root.formattedLightningCanSend = Config.formatSats(Daemon.currentWallet.lightningCanSend) root.formattedLightningBalance = Config.formatSats(Daemon.currentWallet.lightningBalance)
if (Daemon.fx.enabled) { if (Daemon.fx.enabled) {
root.formattedTotalBalanceFiat = Daemon.fx.fiatValue(Daemon.currentWallet.totalBalance, false) root.formattedTotalBalanceFiat = Daemon.fx.fiatValue(Daemon.currentWallet.totalBalance, false)
root.formattedLightningCanSendFiat = Daemon.fx.fiatValue(Daemon.currentWallet.lightningCanSend, false)
} }
} }
state: 'fiat'
states: [
State {
name: 'fiat'
},
State {
name: 'btc'
}
]
TextHighlightPane { TextHighlightPane {
id: balancePane id: balancePane
leftPadding: constants.paddingXLarge leftPadding: constants.paddingXLarge
@ -51,26 +62,26 @@ Item {
} }
Item { Item {
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && root.state == 'fiat'
Layout.preferredHeight: 1 Layout.preferredHeight: 1
Layout.preferredWidth: 1 Layout.preferredWidth: 1
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && root.state == 'fiat'
font.pixelSize: constants.fontSizeLarge font.pixelSize: constants.fontSizeLarge
color: constants.mutedForeground color: constants.mutedForeground
text: formattedTotalBalanceFiat text: formattedTotalBalanceFiat
} }
Label { Label {
visible: Daemon.fx.enabled visible: Daemon.fx.enabled && root.state == 'fiat'
font.pixelSize: constants.fontSizeLarge font.pixelSize: constants.fontSizeLarge
color: constants.mutedForeground color: constants.mutedForeground
text: Daemon.fx.fiatCurrency text: Daemon.fx.fiatCurrency
} }
RowLayout { RowLayout {
visible: Daemon.currentWallet.isLightning visible: Daemon.currentWallet.isLightning && root.state == 'btc'
Image { Image {
Layout.preferredWidth: constants.iconSizeSmall Layout.preferredWidth: constants.iconSizeSmall
Layout.preferredHeight: constants.iconSizeSmall Layout.preferredHeight: constants.iconSizeSmall
@ -83,34 +94,42 @@ Item {
} }
} }
Label { Label {
visible: Daemon.currentWallet.isLightning visible: Daemon.currentWallet.isLightning && root.state == 'btc'
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: formattedLightningCanSend text: formattedLightningBalance
font.family: FixedFont font.family: FixedFont
} }
Label { Label {
visible: Daemon.currentWallet.isLightning visible: Daemon.currentWallet.isLightning && root.state == 'btc'
font.pixelSize: constants.fontSizeSmall font.pixelSize: constants.fontSizeSmall
color: Material.accentColor color: Material.accentColor
text: Config.baseUnit text: Config.baseUnit
} }
Item {
visible: Daemon.currentWallet.isLightning && Daemon.fx.enabled RowLayout {
Layout.preferredHeight: 1 visible: root.state == 'btc'
Layout.preferredWidth: 1 Image {
Layout.preferredWidth: constants.iconSizeSmall
Layout.preferredHeight: constants.iconSizeSmall
source: '../../../icons/bitcoin.png'
} }
Label { Label {
Layout.alignment: Qt.AlignRight text: qsTr('On-chain:')
visible: Daemon.currentWallet.isLightning && Daemon.fx.enabled
font.pixelSize: constants.fontSizeSmall font.pixelSize: constants.fontSizeSmall
color: constants.mutedForeground color: Material.accentColor
text: formattedLightningCanSendFiat }
} }
Label { Label {
visible: Daemon.currentWallet.isLightning && Daemon.fx.enabled visible: root.state == 'btc'
Layout.alignment: Qt.AlignRight
text: formattedConfirmedBalance
font.family: FixedFont
}
Label {
visible: root.state == 'btc'
font.pixelSize: constants.fontSizeSmall font.pixelSize: constants.fontSizeSmall
color: constants.mutedForeground color: Material.accentColor
text: Daemon.fx.fiatCurrency text: Config.baseUnit
} }
} }
@ -124,6 +143,13 @@ Item {
font.pixelSize: constants.fontSizeLarge font.pixelSize: constants.fontSizeLarge
} }
MouseArea {
anchors.fill: parent
onClicked: {
root.state = root.state == 'fiat' ? 'btc' : 'fiat'
}
}
// instead of all these explicit connections, we should expose // instead of all these explicit connections, we should expose
// formatted balances directly as a property // formatted balances directly as a property
Connections { Connections {

Loading…
Cancel
Save