2015-07-14 19:06:00 +00:00
|
|
|
import QtQuick 2.5
|
|
|
|
|
import QtQuick.Controls 1.4
|
|
|
|
|
import QtQuick.Dialogs 1.2
|
|
|
|
|
import QtQuick.Layouts 1.2
|
|
|
|
|
|
|
|
|
|
import Graphene.Client 0.1
|
|
|
|
|
|
|
|
|
|
import "."
|
|
|
|
|
|
2015-07-17 20:39:01 +00:00
|
|
|
/// A component for choosing an Account from the chain
|
2015-07-14 19:06:00 +00:00
|
|
|
RowLayout {
|
2015-07-17 20:39:01 +00:00
|
|
|
property GrapheneApplication app
|
|
|
|
|
/// The text to show in the name field when it is empty
|
|
|
|
|
property alias placeholderText: accountNameField.placeholderText
|
|
|
|
|
/// Index into the balances Array of the balance to show beneath the name field
|
|
|
|
|
property int showBalance: -1
|
|
|
|
|
|
|
|
|
|
/// The Account object the user has selected
|
2015-07-14 19:06:00 +00:00
|
|
|
property Account account
|
2015-07-29 19:50:12 +00:00
|
|
|
/// A real in the range [0,1] representing the amount of control the wallet has over this account
|
|
|
|
|
property real accountControlLevel: account && account.isLoaded? account.getActiveControl(app.wallet) : 0
|
2015-07-17 20:39:01 +00:00
|
|
|
/// An Array of Balance objects held by account
|
2015-07-15 21:48:44 +00:00
|
|
|
property var balances: account? Object.keys(account.balances).map(function(key){return account.balances[key]})
|
2015-07-29 19:59:15 +00:00
|
|
|
.filter(function(balance){return balance.amount > 0})
|
2015-07-15 21:48:44 +00:00
|
|
|
: null
|
2015-07-14 19:06:00 +00:00
|
|
|
|
2015-07-17 20:39:01 +00:00
|
|
|
/// Set the name field to have active focus
|
2015-07-14 19:06:00 +00:00
|
|
|
function setFocus() {
|
|
|
|
|
accountNameField.forceActiveFocus()
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 21:09:44 +00:00
|
|
|
signal balanceClicked(var balance)
|
|
|
|
|
|
2015-07-14 19:06:00 +00:00
|
|
|
Identicon {
|
2015-07-15 22:14:48 +00:00
|
|
|
name: account && account.name == accountNameField.text? accountNameField.text : ""
|
2015-07-14 19:06:00 +00:00
|
|
|
width: Scaling.cm(2)
|
|
|
|
|
height: Scaling.cm(2)
|
2015-07-29 19:50:12 +00:00
|
|
|
showOwnership: accountControlLevel > 0
|
|
|
|
|
fullOwnership: accountControlLevel >= 1
|
2015-07-14 19:06:00 +00:00
|
|
|
}
|
|
|
|
|
Column {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
TextField {
|
|
|
|
|
id: accountNameField
|
|
|
|
|
width: parent.width
|
2015-07-17 20:06:07 +00:00
|
|
|
|
2015-07-14 19:06:00 +00:00
|
|
|
onEditingFinished: accountDetails.update(text)
|
2015-07-17 20:06:07 +00:00
|
|
|
onTextChanged: if (account && account.name !== text) accountDetails.update("")
|
2015-07-14 19:06:00 +00:00
|
|
|
}
|
2015-07-15 21:48:44 +00:00
|
|
|
Text {
|
2015-07-14 19:06:00 +00:00
|
|
|
id: accountDetails
|
2015-07-15 21:48:44 +00:00
|
|
|
width: parent.width
|
|
|
|
|
height: text? implicitHeight : 0
|
2015-07-21 21:09:44 +00:00
|
|
|
onLinkActivated: if (link === "balance") balanceClicked(balances[showBalance].amountReal())
|
2015-07-15 21:48:44 +00:00
|
|
|
|
|
|
|
|
Behavior on height { NumberAnimation{ easing.type: Easing.InOutQuad } }
|
|
|
|
|
|
2015-07-14 19:06:00 +00:00
|
|
|
function update(name) {
|
|
|
|
|
if (!name)
|
|
|
|
|
{
|
|
|
|
|
text = ""
|
2015-07-15 21:48:44 +00:00
|
|
|
account = null
|
2015-07-14 19:06:00 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
account = app.model.getAccount(name)
|
2015-07-15 21:48:44 +00:00
|
|
|
if (account == null) {
|
2015-07-14 19:06:00 +00:00
|
|
|
text = qsTr("Error fetching account.")
|
2015-07-15 21:48:44 +00:00
|
|
|
} else {
|
2015-07-14 19:06:00 +00:00
|
|
|
text = Qt.binding(function() {
|
|
|
|
|
if (account == null)
|
|
|
|
|
return qsTr("Account does not exist.")
|
2015-07-29 19:50:12 +00:00
|
|
|
var text = qsTr("Account ID: %1").arg(!account.isLoaded? qsTr("Loading...")
|
|
|
|
|
: account.id)
|
2015-07-15 21:48:44 +00:00
|
|
|
if (showBalance >= 0) {
|
2015-07-17 20:06:07 +00:00
|
|
|
var bal = balances[showBalance]
|
2015-07-21 21:09:44 +00:00
|
|
|
text += "<br/>" + qsTr("Balance: <a href='balance'>%1</a> %2").arg(String(bal.amountReal()))
|
|
|
|
|
.arg(bal.type.symbol)
|
2015-07-15 21:48:44 +00:00
|
|
|
}
|
|
|
|
|
return text
|
2015-07-14 19:06:00 +00:00
|
|
|
})
|
2015-07-15 21:48:44 +00:00
|
|
|
}
|
2015-07-14 19:06:00 +00:00
|
|
|
}
|
2015-07-14 20:08:54 +00:00
|
|
|
|
|
|
|
|
Behavior on text {
|
|
|
|
|
SequentialAnimation {
|
|
|
|
|
PropertyAnimation {
|
|
|
|
|
target: accountDetails
|
|
|
|
|
property: "opacity"
|
|
|
|
|
from: 1; to: 0
|
|
|
|
|
duration: 100
|
|
|
|
|
}
|
|
|
|
|
PropertyAction { target: accountDetails; property: "text" }
|
|
|
|
|
PropertyAnimation {
|
|
|
|
|
target: accountDetails
|
|
|
|
|
property: "opacity"
|
|
|
|
|
from: 0; to: 1
|
|
|
|
|
duration: 100
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-14 19:06:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|