feat: enable changing account setting in the wallet
This commit is contained in:
parent
317c956718
commit
be8188078b
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -7,8 +7,13 @@ import stint
|
|||
import strutils, sequtils
|
||||
import chronicles
|
||||
|
||||
type WalletAccount* = object
|
||||
address*, path*, publicKey*, name*, color*, walletType*: string
|
||||
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] =
|
||||
|
@ -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",
|
||||
))
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue