diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index 401bf1b2b3..feeb1fce3e 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -84,7 +84,7 @@ QtObject: proc accountListChanged*(self: WalletView) {.signal.} - proc addAccountToList*(self: WalletView, account: Account) = + proc addAccountToList*(self: WalletView, account: WalletAccount) = self.accounts.addAccountToList(account) # If it's the first account we ever get, use its assetList as our currentAssetList if (self.accounts.rowCount == 1): @@ -104,6 +104,13 @@ QtObject: proc addWatchOnlyAccount*(self: WalletView, address: string, accountName: string, color: string) {.slot.} = self.status.wallet.addWatchOnlyAccount(address, accountName, color) + proc changeAccountSettings*(self: WalletView, address: string, accountName: string, color: string): string {.slot.} = + result = self.status.wallet.changeAccountSettings(address, accountName, color) + if (result == ""): + self.currentAccountChanged() + self.accountListChanged() + self.accounts.forceUpdate() + proc getAccountList(self: WalletView): QVariant {.slot.} = return newQVariant(self.accounts) diff --git a/src/app/wallet/views/account_item.nim b/src/app/wallet/views/account_item.nim index 9c28525858..b5bee24561 100644 --- a/src/app/wallet/views/account_item.nim +++ b/src/app/wallet/views/account_item.nim @@ -5,7 +5,7 @@ import ../../../status/wallet QtObject: type AccountItemView* = ref object of QObject - account*: Account + account*: WalletAccount proc setup(self: AccountItemView) = self.QObject.setup @@ -18,7 +18,7 @@ QtObject: result = AccountItemView() result.setup - proc setAccountItem*(self: AccountItemView, account: Account) = + proc setAccountItem*(self: AccountItemView, account: WalletAccount) = self.account = account proc name*(self: AccountItemView): string {.slot.} = result = ?.self.account.name diff --git a/src/app/wallet/views/account_list.nim b/src/app/wallet/views/account_list.nim index 92f85d39f2..5a8bf6d29a 100644 --- a/src/app/wallet/views/account_list.nim +++ b/src/app/wallet/views/account_list.nim @@ -16,7 +16,7 @@ type QtObject: type AccountList* = ref object of QAbstractListModel - accounts*: seq[Account] + accounts*: seq[WalletAccount] proc setup(self: AccountList) = self.QAbstractListModel.setup @@ -29,7 +29,7 @@ QtObject: result.accounts = @[] result.setup - proc getAccount*(self: AccountList, index: int): Account = self.accounts[index] + proc getAccount*(self: AccountList, index: int): WalletAccount = self.accounts[index] method rowCount*(self: AccountList, index: QModelIndex = nil): int = return self.accounts.len @@ -53,7 +53,7 @@ QtObject: AccountRoles.Color.int:"iconColor", AccountRoles.Balance.int:"balance" }.toTable - proc addAccountToList*(self: AccountList, account: Account) = + proc addAccountToList*(self: AccountList, account: WalletAccount) = if account.iconColor == "": randomize() account.iconColor = accountColors[rand(accountColors.len - 1)] diff --git a/src/status/libstatus/accounts.nim b/src/status/libstatus/accounts.nim index 29184cf180..4bd213536e 100644 --- a/src/status/libstatus/accounts.nim +++ b/src/status/libstatus/accounts.nim @@ -6,10 +6,11 @@ import accounts/constants import nimcrypto import os import uuids -import types +import types as types import json_serialization import chronicles import ../../signals/types as signal_types +import ./wallet as status_wallet proc queryAccounts*(): string = var response = callPrivateRPC("eth_accounts") @@ -52,7 +53,7 @@ proc saveAccountAndLogin*( accountData: string, password: string, configJSON: string, - settingsJSON: string): Account = + settingsJSON: string): types.Account = let hashedPassword = "0x" & $keccak_256.digest(password) let subaccountData = %* [ { @@ -134,7 +135,7 @@ proc getAccountSettings*(account: GeneratedAccount, defaultNetworks: JsonNode): "installation-id": $genUUID() } -proc setupAccount*(account: GeneratedAccount, password: string): Account = +proc setupAccount*(account: GeneratedAccount, password: string): types.Account = try: let storeDerivedResult = storeDerivedAccounts(account, password) let accountData = getAccountData(account) @@ -208,6 +209,23 @@ proc saveAccount*(account: GeneratedAccount, password: string, color: string, ac except: error "Error storing the new account. Bad password?" +proc changeAccount*(account: status_wallet.WalletAccount): string = + try: + let res= callPrivateRPC("accounts_saveAccounts", %* [ + [{ + "color": account.iconColor, + "name": account.name, + "address": account.address, + "public-key": account.publicKey, + "type": account.walletType, + "path": "m/44'/60'/0'/0/1" + }] + ]) + return "" + except Exception as e: + error "Error saving the account", msg=e.msg + result = e.msg + proc deriveAccounts*(accountId: string): MultiAccounts = let deriveJson = %* { "accountID": accountId, diff --git a/src/status/libstatus/wallet.nim b/src/status/libstatus/wallet.nim index 871ac42ffb..238c25fe58 100644 --- a/src/status/libstatus/wallet.nim +++ b/src/status/libstatus/wallet.nim @@ -7,9 +7,14 @@ import stint import strutils, sequtils import chronicles -type WalletAccount* = object - address*, path*, publicKey*, name*, color*, walletType*: string - wallet*, chat*: bool +type Asset* = ref object + name*, symbol*, value*, fiatValue*, image*: string + +type WalletAccount* = ref object + name*, address*, iconColor*, balance*, path*, walletType*, publicKey*: string + realFiatBalance*: float + assetList*: seq[Asset] + wallet*, chat*: bool proc getWalletAccounts*(): seq[WalletAccount] = try: @@ -26,7 +31,7 @@ proc getWalletAccounts*(): seq[WalletAccount] = # Watch accoutns don't have a public key publicKey: if (account.hasKey("public-key")): $account["public-key"].getStr else: "", name: $account["name"].getStr, - color: $account["color"].getStr, + iconColor: $account["color"].getStr, wallet: $account["wallet"].getStr == "true", chat: $account["chat"].getStr == "false", )) diff --git a/src/status/wallet.nim b/src/status/wallet.nim index f3cc77ae52..b03e4a0d88 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -10,9 +10,18 @@ import wallet/balance_manager import wallet/account export account +type WalletAccount* = status_wallet.WalletAccount +type Asset* = status_wallet.Asset + +type CurrencyArgs* = ref object of Args + currency*: string + +type AccountArgs* = ref object of Args + account*: WalletAccount + type WalletModel* = ref object events*: EventEmitter - accounts*: seq[Account] + accounts*: seq[WalletAccount] defaultCurrency*: string tokens*: JsonNode totalBalance*: float @@ -113,6 +122,19 @@ proc addWatchOnlyAccount*(self: WalletModel, address: string, accountName: strin proc hasAsset*(self: WalletModel, account: string, symbol: string): bool = self.tokens.anyIt(it["symbol"].getStr == symbol) +proc changeAccountSettings*(self: WalletModel, address: string, accountName: string, color: string): string = + var selectedAccount: WalletAccount + for account in self.accounts: + if (account.address == address): + selectedAccount = account + break + if (isNil(selectedAccount)): + result = "No account found with that address" + error "No account found with that address", address + selectedAccount.name = accountName + selectedAccount.iconColor = color + result = status_accounts.changeAccount(selectedAccount) + proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) = self.tokens = addOrRemoveToken(enable, address, name, symbol, decimals, color) for account in self.accounts: diff --git a/ui/app/AppLayouts/Wallet/AccountSettingsModal.qml b/ui/app/AppLayouts/Wallet/AccountSettingsModal.qml index 8aac8534d7..8664cf1021 100644 --- a/ui/app/AppLayouts/Wallet/AccountSettingsModal.qml +++ b/ui/app/AppLayouts/Wallet/AccountSettingsModal.qml @@ -116,7 +116,8 @@ ModalPopup { // TODO add message to show validation errors if (accountNameInput.text === "") return; console.log('SAVE') - // walletModel.generateNewAccount(passwordInput.text, accountNameInput.text, selectedColor); + const error = walletModel.changeAccountSettings(currentAccount.address, accountNameInput.text, selectedColor); + console.log('Error?', error) // TODO manage errors adding account popup.close(); } diff --git a/ui/app/AppLayouts/Wallet/LeftTab.qml b/ui/app/AppLayouts/Wallet/LeftTab.qml index 6cd8a60cd7..2e1686cc21 100644 --- a/ui/app/AppLayouts/Wallet/LeftTab.qml +++ b/ui/app/AppLayouts/Wallet/LeftTab.qml @@ -103,7 +103,7 @@ Item { ColorOverlay { anchors.fill: walletIcon source: walletIcon - color: selected ? Theme.transparent : iconColor // change image color + color: selected || !iconColor ? Theme.transparent : iconColor // change image color } Text { id: walletName