1
mirror of https://github.com/monero-project/monero-gui synced 2024-12-29 23:26:24 +01:00

Wallet: persistent subaddress account selection

This commit is contained in:
xiphon 2019-12-03 11:53:12 +00:00
parent d5f4d5d93f
commit 646d3394d3
5 changed files with 27 additions and 22 deletions

View File

@ -40,8 +40,8 @@ import "components/effects/" as MoneroEffects
Rectangle {
id: panel
property int currentAccountIndex: 0
property string currentAccountLabel: "Primary account"
property int currentAccountIndex
property alias currentAccountLabel: accountLabel.text
property string balanceString: "?.??"
property string balanceUnlockedString: "?.??"
property string balanceFiatString: "?.??"
@ -184,7 +184,7 @@ Rectangle {
MoneroComponents.Label {
fontSize: 12
id: accountIndex
text: qsTr("Account") + " #" + currentAccountIndex
text: qsTr("Account") + translationManager.emptyString + " #" + currentAccountIndex
color: MoneroComponents.Style.blackTheme ? "white" : "black"
anchors.left: parent.left
anchors.leftMargin: 60
@ -204,7 +204,6 @@ Rectangle {
fontSize: 16
id: accountLabel
textWidth: 170
text: currentAccountLabel
color: MoneroComponents.Style.blackTheme ? "white" : "black"
anchors.left: parent.left
anchors.leftMargin: 60

View File

@ -112,7 +112,6 @@ ApplicationWindow {
property var current_address
property var current_address_label: "Primary"
property int current_subaddress_table_index: 0
property int current_subaddress_account_table_index: 0
function altKeyReleased() { ctrlPressed = false; }
@ -418,8 +417,6 @@ ApplicationWindow {
}
leftPanel.minutesToUnlock = (balance !== balanceU) ? currentWallet.history.minutesToUnlock : "";
leftPanel.currentAccountIndex = currentWallet.currentSubaddressAccount;
leftPanel.currentAccountLabel = currentWallet.getSubaddressLabel(currentWallet.currentSubaddressAccount, 0);
leftPanel.balanceString = balance
leftPanel.balanceUnlockedString = balanceU
}
@ -1616,6 +1613,13 @@ ApplicationWindow {
anchors.left: parent.left
anchors.bottom: parent.bottom
visible: rootItem.state == "normal" && middlePanel.state != "Merchant"
currentAccountIndex: currentWallet ? currentWallet.currentSubaddressAccount : 0
currentAccountLabel: {
if (currentWallet) {
return currentWallet.getSubaddressLabel(currentWallet.currentSubaddressAccount, 0);
}
return qsTr("Primary account") + translationManager.emptyString;
}
onTransferClicked: {
middlePanel.state = "Transfer";
@ -1687,6 +1691,7 @@ ApplicationWindow {
MiddlePanel {
id: middlePanel
accountView.currentAccountIndex: currentWallet ? currentWallet.currentSubaddressAccount : 0
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: leftPanel.visible ? leftPanel.right : parent.left

View File

@ -49,6 +49,7 @@ Rectangle {
property var model
property alias accountHeight: mainLayout.height
property bool selectAndSend: false
property int currentAccountIndex
function renameSubaddressAccountLabel(_index){
inputDialog.labelText = qsTr("Set the label of the selected account:") + translationManager.emptyString;
@ -180,6 +181,7 @@ Rectangle {
clip: true
boundsBehavior: ListView.StopAtBounds
interactive: false
currentIndex: currentAccountIndex
delegate: Rectangle {
id: tableItem2
@ -211,7 +213,7 @@ Rectangle {
MoneroComponents.Label {
id: idLabel
color: index === appWindow.current_subaddress_account_table_index ? MoneroComponents.Style.defaultFontColor : "#757575"
color: index === currentAccountIndex ? MoneroComponents.Style.defaultFontColor : "#757575"
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 6
@ -278,9 +280,9 @@ Rectangle {
onEntered: tableItem2.color = MoneroComponents.Style.titleBarButtonHoverColor
onExited: tableItem2.color = "transparent"
onClicked: {
if (index == subaddressAccountListView.currentIndex && selectAndSend)
appWindow.currentWallet.switchSubaddressAccount(index);
if (selectAndSend)
appWindow.showPageRequest("Transfer");
subaddressAccountListView.currentIndex = index;
}
}
}
@ -319,17 +321,9 @@ Rectangle {
}
}
}
onCurrentItemChanged: {
// reset global vars
appWindow.current_subaddress_account_table_index = subaddressAccountListView.currentIndex;
appWindow.currentWallet.switchSubaddressAccount(appWindow.current_subaddress_account_table_index);
appWindow.onWalletUpdate();
}
onCurrentIndexChanged: {
if (selectAndSend) {
appWindow.showPageRequest("Transfer");
}
appWindow.onWalletUpdate();
}
}
}
@ -364,8 +358,6 @@ Rectangle {
inputDialog.onAcceptedCallback = function() {
appWindow.currentWallet.subaddressAccount.addRow(inputDialog.inputText)
appWindow.currentWallet.switchSubaddressAccount(appWindow.currentWallet.numSubaddressAccounts() - 1)
current_subaddress_account_table_index = appWindow.currentWallet.numSubaddressAccounts() - 1
subaddressAccountListView.currentIndex = current_subaddress_account_table_index
appWindow.onWalletUpdate();
}
inputDialog.onRejectedCallback = null;

View File

@ -55,6 +55,8 @@ namespace {
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 5;
static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 30;
static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5;
static constexpr char ATTRIBUTE_SUBADDRESS_ACCOUNT[] ="gui.subaddress_account";
}
class WalletListenerImpl : public Monero::WalletListener
@ -316,8 +318,13 @@ void Wallet::switchSubaddressAccount(quint32 accountIndex)
if (accountIndex < numSubaddressAccounts())
{
m_currentSubaddressAccount = accountIndex;
if (!setCacheAttribute(ATTRIBUTE_SUBADDRESS_ACCOUNT, QString::number(m_currentSubaddressAccount)))
{
qWarning() << "failed to set " << ATTRIBUTE_SUBADDRESS_ACCOUNT << " cache attribute";
}
m_subaddress->refresh(m_currentSubaddressAccount);
m_history->refresh(m_currentSubaddressAccount);
emit currentSubaddressAccountChanged();
}
}
void Wallet::addSubaddressAccount(const QString& label)
@ -982,6 +989,7 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent)
m_walletListener = new WalletListenerImpl(this);
m_walletImpl->setListener(m_walletListener);
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
m_currentSubaddressAccount = getCacheAttribute(ATTRIBUTE_SUBADDRESS_ACCOUNT).toUInt();
// start cache timers
m_connectionStatusTime.restart();
m_daemonBlockChainHeightTime.restart();

View File

@ -65,7 +65,7 @@ class Wallet : public QObject
Q_PROPERTY(Status status READ status)
Q_PROPERTY(NetworkType::Type nettype READ nettype)
// Q_PROPERTY(ConnectionStatus connected READ connected)
Q_PROPERTY(quint32 currentSubaddressAccount READ currentSubaddressAccount)
Q_PROPERTY(quint32 currentSubaddressAccount READ currentSubaddressAccount NOTIFY currentSubaddressAccountChanged)
Q_PROPERTY(bool synchronized READ synchronized)
Q_PROPERTY(QString errorString READ errorString)
Q_PROPERTY(TransactionHistory * history READ history)
@ -365,6 +365,7 @@ signals:
void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount);
void connectionStatusChanged(int status) const;
void currentSubaddressAccountChanged() const;
private:
Wallet(QObject * parent = nullptr);