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 accountListChanged*(self: WalletView) {.signal.}
|
||||||
|
|
||||||
proc addAccountToList*(self: WalletView, account: Account) =
|
proc addAccountToList*(self: WalletView, account: WalletAccount) =
|
||||||
self.accounts.addAccountToList(account)
|
self.accounts.addAccountToList(account)
|
||||||
# If it's the first account we ever get, use its assetList as our currentAssetList
|
# If it's the first account we ever get, use its assetList as our currentAssetList
|
||||||
if (self.accounts.rowCount == 1):
|
if (self.accounts.rowCount == 1):
|
||||||
|
@ -104,6 +104,13 @@ QtObject:
|
||||||
proc addWatchOnlyAccount*(self: WalletView, address: string, accountName: string, color: string) {.slot.} =
|
proc addWatchOnlyAccount*(self: WalletView, address: string, accountName: string, color: string) {.slot.} =
|
||||||
self.status.wallet.addWatchOnlyAccount(address, accountName, color)
|
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.} =
|
proc getAccountList(self: WalletView): QVariant {.slot.} =
|
||||||
return newQVariant(self.accounts)
|
return newQVariant(self.accounts)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import ../../../status/wallet
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type AccountItemView* = ref object of QObject
|
type AccountItemView* = ref object of QObject
|
||||||
account*: Account
|
account*: WalletAccount
|
||||||
|
|
||||||
proc setup(self: AccountItemView) =
|
proc setup(self: AccountItemView) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
|
@ -18,7 +18,7 @@ QtObject:
|
||||||
result = AccountItemView()
|
result = AccountItemView()
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc setAccountItem*(self: AccountItemView, account: Account) =
|
proc setAccountItem*(self: AccountItemView, account: WalletAccount) =
|
||||||
self.account = account
|
self.account = account
|
||||||
|
|
||||||
proc name*(self: AccountItemView): string {.slot.} = result = ?.self.account.name
|
proc name*(self: AccountItemView): string {.slot.} = result = ?.self.account.name
|
||||||
|
|
|
@ -16,7 +16,7 @@ type
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type AccountList* = ref object of QAbstractListModel
|
type AccountList* = ref object of QAbstractListModel
|
||||||
accounts*: seq[Account]
|
accounts*: seq[WalletAccount]
|
||||||
|
|
||||||
proc setup(self: AccountList) = self.QAbstractListModel.setup
|
proc setup(self: AccountList) = self.QAbstractListModel.setup
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ QtObject:
|
||||||
result.accounts = @[]
|
result.accounts = @[]
|
||||||
result.setup
|
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 =
|
method rowCount*(self: AccountList, index: QModelIndex = nil): int =
|
||||||
return self.accounts.len
|
return self.accounts.len
|
||||||
|
@ -53,7 +53,7 @@ QtObject:
|
||||||
AccountRoles.Color.int:"iconColor",
|
AccountRoles.Color.int:"iconColor",
|
||||||
AccountRoles.Balance.int:"balance" }.toTable
|
AccountRoles.Balance.int:"balance" }.toTable
|
||||||
|
|
||||||
proc addAccountToList*(self: AccountList, account: Account) =
|
proc addAccountToList*(self: AccountList, account: WalletAccount) =
|
||||||
if account.iconColor == "":
|
if account.iconColor == "":
|
||||||
randomize()
|
randomize()
|
||||||
account.iconColor = accountColors[rand(accountColors.len - 1)]
|
account.iconColor = accountColors[rand(accountColors.len - 1)]
|
||||||
|
|
|
@ -6,10 +6,11 @@ import accounts/constants
|
||||||
import nimcrypto
|
import nimcrypto
|
||||||
import os
|
import os
|
||||||
import uuids
|
import uuids
|
||||||
import types
|
import types as types
|
||||||
import json_serialization
|
import json_serialization
|
||||||
import chronicles
|
import chronicles
|
||||||
import ../../signals/types as signal_types
|
import ../../signals/types as signal_types
|
||||||
|
import ./wallet as status_wallet
|
||||||
|
|
||||||
proc queryAccounts*(): string =
|
proc queryAccounts*(): string =
|
||||||
var response = callPrivateRPC("eth_accounts")
|
var response = callPrivateRPC("eth_accounts")
|
||||||
|
@ -52,7 +53,7 @@ proc saveAccountAndLogin*(
|
||||||
accountData: string,
|
accountData: string,
|
||||||
password: string,
|
password: string,
|
||||||
configJSON: string,
|
configJSON: string,
|
||||||
settingsJSON: string): Account =
|
settingsJSON: string): types.Account =
|
||||||
let hashedPassword = "0x" & $keccak_256.digest(password)
|
let hashedPassword = "0x" & $keccak_256.digest(password)
|
||||||
let subaccountData = %* [
|
let subaccountData = %* [
|
||||||
{
|
{
|
||||||
|
@ -134,7 +135,7 @@ proc getAccountSettings*(account: GeneratedAccount, defaultNetworks: JsonNode):
|
||||||
"installation-id": $genUUID()
|
"installation-id": $genUUID()
|
||||||
}
|
}
|
||||||
|
|
||||||
proc setupAccount*(account: GeneratedAccount, password: string): Account =
|
proc setupAccount*(account: GeneratedAccount, password: string): types.Account =
|
||||||
try:
|
try:
|
||||||
let storeDerivedResult = storeDerivedAccounts(account, password)
|
let storeDerivedResult = storeDerivedAccounts(account, password)
|
||||||
let accountData = getAccountData(account)
|
let accountData = getAccountData(account)
|
||||||
|
@ -208,6 +209,23 @@ proc saveAccount*(account: GeneratedAccount, password: string, color: string, ac
|
||||||
except:
|
except:
|
||||||
error "Error storing the new account. Bad password?"
|
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 =
|
proc deriveAccounts*(accountId: string): MultiAccounts =
|
||||||
let deriveJson = %* {
|
let deriveJson = %* {
|
||||||
"accountID": accountId,
|
"accountID": accountId,
|
||||||
|
|
|
@ -7,9 +7,14 @@ import stint
|
||||||
import strutils, sequtils
|
import strutils, sequtils
|
||||||
import chronicles
|
import chronicles
|
||||||
|
|
||||||
type WalletAccount* = object
|
type Asset* = ref object
|
||||||
address*, path*, publicKey*, name*, color*, walletType*: string
|
name*, symbol*, value*, fiatValue*, image*: string
|
||||||
wallet*, chat*: bool
|
|
||||||
|
type WalletAccount* = ref object
|
||||||
|
name*, address*, iconColor*, balance*, path*, walletType*, publicKey*: string
|
||||||
|
realFiatBalance*: float
|
||||||
|
assetList*: seq[Asset]
|
||||||
|
wallet*, chat*: bool
|
||||||
|
|
||||||
proc getWalletAccounts*(): seq[WalletAccount] =
|
proc getWalletAccounts*(): seq[WalletAccount] =
|
||||||
try:
|
try:
|
||||||
|
@ -26,7 +31,7 @@ proc getWalletAccounts*(): seq[WalletAccount] =
|
||||||
# Watch accoutns don't have a public key
|
# Watch accoutns don't have a public key
|
||||||
publicKey: if (account.hasKey("public-key")): $account["public-key"].getStr else: "",
|
publicKey: if (account.hasKey("public-key")): $account["public-key"].getStr else: "",
|
||||||
name: $account["name"].getStr,
|
name: $account["name"].getStr,
|
||||||
color: $account["color"].getStr,
|
iconColor: $account["color"].getStr,
|
||||||
wallet: $account["wallet"].getStr == "true",
|
wallet: $account["wallet"].getStr == "true",
|
||||||
chat: $account["chat"].getStr == "false",
|
chat: $account["chat"].getStr == "false",
|
||||||
))
|
))
|
||||||
|
|
|
@ -10,9 +10,18 @@ import wallet/balance_manager
|
||||||
import wallet/account
|
import wallet/account
|
||||||
export 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
|
type WalletModel* = ref object
|
||||||
events*: EventEmitter
|
events*: EventEmitter
|
||||||
accounts*: seq[Account]
|
accounts*: seq[WalletAccount]
|
||||||
defaultCurrency*: string
|
defaultCurrency*: string
|
||||||
tokens*: JsonNode
|
tokens*: JsonNode
|
||||||
totalBalance*: float
|
totalBalance*: float
|
||||||
|
@ -113,6 +122,19 @@ proc addWatchOnlyAccount*(self: WalletModel, address: string, accountName: strin
|
||||||
proc hasAsset*(self: WalletModel, account: string, symbol: string): bool =
|
proc hasAsset*(self: WalletModel, account: string, symbol: string): bool =
|
||||||
self.tokens.anyIt(it["symbol"].getStr == symbol)
|
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) =
|
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)
|
self.tokens = addOrRemoveToken(enable, address, name, symbol, decimals, color)
|
||||||
for account in self.accounts:
|
for account in self.accounts:
|
||||||
|
|
|
@ -116,7 +116,8 @@ ModalPopup {
|
||||||
// TODO add message to show validation errors
|
// TODO add message to show validation errors
|
||||||
if (accountNameInput.text === "") return;
|
if (accountNameInput.text === "") return;
|
||||||
console.log('SAVE')
|
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
|
// TODO manage errors adding account
|
||||||
popup.close();
|
popup.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ Item {
|
||||||
ColorOverlay {
|
ColorOverlay {
|
||||||
anchors.fill: walletIcon
|
anchors.fill: walletIcon
|
||||||
source: walletIcon
|
source: walletIcon
|
||||||
color: selected ? Theme.transparent : iconColor // change image color
|
color: selected || !iconColor ? Theme.transparent : iconColor // change image color
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
id: walletName
|
id: walletName
|
||||||
|
|
Loading…
Reference in New Issue