fix: fix conflicts and bad types

This commit is contained in:
Jonathan Rainville 2020-06-11 10:36:02 -04:00 committed by Iuri Matias
parent 65efdf4c71
commit 7476cf3d16
9 changed files with 30 additions and 37 deletions

View File

@ -12,6 +12,7 @@ import ../../status/libstatus/wallet as status_wallet
import ../../signals/types
import ../../status/wallet
import ../../status/wallet/account as WalletTypes
import ../../status/status
type WalletController* = ref object of SignalSubscriber
@ -40,7 +41,7 @@ proc init*(self: WalletController) =
self.view.updateView()
self.status.events.on("newAccountAdded") do(e: Args):
var account = AccountArgs(e)
var account = WalletTypes.AccountArgs(e)
self.view.accounts.addAccountToList(account.account)
self.status.events.on("assetChanged") do(e: Args):

View File

@ -1,6 +1,5 @@
import NimQml
import std/wrapnils
import ./asset_list
import ../../../status/wallet
QtObject:

View File

@ -1,7 +1,6 @@
import NimQml
import Tables
import random
import ./asset_list
import ./account_item
import ../../../status/wallet

View File

@ -10,7 +10,7 @@ import types as types
import json_serialization
import chronicles
import ../../signals/types as signal_types
import ./wallet as status_wallet
import ../wallet/account
proc queryAccounts*(): string =
var response = callPrivateRPC("eth_accounts")
@ -178,8 +178,11 @@ proc MultiAccountImportPrivateKey*(privateKey: string): GeneratedAccount =
"privateKey": privateKey
}
# libstatus.MultiAccountImportPrivateKey never results in an error given ANY input
let importResult = $libstatus.MultiAccountImportPrivateKey($privateKeyJson)
result = Json.decode(importResult, GeneratedAccount)
try:
let importResult = $libstatus.MultiAccountImportPrivateKey($privateKeyJson)
result = Json.decode(importResult, GeneratedAccount)
except Exception as e:
error "Error getting account from private key", msg=e.msg
proc saveAccount*(account: GeneratedAccount, password: string, color: string, accountType: string, isADerivedAccount = true): DerivedAccount =
try:
@ -209,7 +212,7 @@ 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 =
proc changeAccount*(account: WalletAccount): string =
try:
let res= callPrivateRPC("accounts_saveAccounts", %* [
[{

View File

@ -6,15 +6,7 @@ import strformat
import stint
import strutils, sequtils
import chronicles
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
import ../wallet/account
proc getWalletAccounts*(): seq[WalletAccount] =
try:

View File

@ -1,24 +1,14 @@
import eventemitter, json, strformat, strutils, tables, chronicles, sequtils
import eventemitter, json, strformat, strutils, chronicles, sequtils
import libstatus/accounts as status_accounts
import libstatus/tokens as status_tokens
import libstatus/settings as status_settings
import libstatus/wallet as status_wallet
import libstatus/accounts/constants as constants
from libstatus/types import GeneratedAccount, DerivedAccount
import wallet/token_list
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[WalletAccount]
@ -71,9 +61,16 @@ proc generateAccountConfiguredAssets*(self: WalletModel, accountAddress: string)
assets.add(existingToken)
assets
proc newAccount*(self: WalletModel, name: string, address: string, iconColor: string, balance: string): Account =
proc populateAccount*(self: WalletModel, walletAccount: var WalletAccount, balance: string) =
var assets: seq[Asset] = self.generateAccountConfiguredAssets(walletAccount.address)
walletAccount.balance = fmt"{balance} {self.defaultCurrency}"
walletAccount.assetList = assets
walletAccount.realFiatBalance = 0.0
updateBalance(walletAccount, self.getDefaultCurrency())
proc newAccount*(self: WalletModel, name: string, address: string, iconColor: string, balance: string, publicKey: string): WalletAccount =
var assets: seq[Asset] = self.generateAccountConfiguredAssets(address)
var account = Account(name: name, address: address, iconColor: iconColor, balance: fmt"{balance} {self.defaultCurrency}", assetList: assets, realFiatBalance: 0.0)
var account = WalletAccount(name: name, address: address, iconColor: iconColor, balance: fmt"{balance} {self.defaultCurrency}", assetList: assets, realFiatBalance: 0.0, publicKey: publicKey)
updateBalance(account, self.getDefaultCurrency())
account
@ -81,8 +78,9 @@ proc initAccounts*(self: WalletModel) =
self.tokens = status_tokens.getCustomTokens()
let accounts = status_wallet.getWalletAccounts()
for account in accounts:
var account = self.newAccount(account.name, account.address, account.color, "")
self.accounts.add(account)
var acc = WalletAccount(account)
self.populateAccount(acc, "")
self.accounts.add(acc)
self.calculateTotalFiatBalance
proc getTotalFiatBalance*(self: WalletModel): string =
@ -97,7 +95,7 @@ proc calculateTotalFiatBalance*(self: WalletModel) =
proc addNewGeneratedAccount(self: WalletModel, generatedAccount: GeneratedAccount, password: string, accountName: string, color: string, accountType: string, isADerivedAccount = true) =
generatedAccount.name = accountName
var derivedAccount: DerivedAccount = status_accounts.saveAccount(generatedAccount, password, color, accountType, isADerivedAccount)
var account = self.newAccount(accountName, derivedAccount.address, color, fmt"0.00 {self.defaultCurrency}")
var account = self.newAccount(accountName, derivedAccount.address, color, fmt"0.00 {self.defaultCurrency}", derivedAccount.publicKey)
self.accounts.add(account)
self.events.emit("newAccountAdded", AccountArgs(account: account))

View File

@ -7,10 +7,11 @@ type Asset* = ref object
name*, symbol*, value*, fiatValue*, image*, accountAddress*: string
hasIcon*: bool
type Account* = ref object
name*, address*, iconColor*, balance*: string
type WalletAccount* = ref object
name*, address*, iconColor*, balance*, path*, walletType*, publicKey*: string
realFiatBalance*: float
assetList*: seq[Asset]
wallet*, chat*: bool
type AccountArgs* = ref object of Args
account*: Account
account*: WalletAccount

View File

@ -56,7 +56,7 @@ proc updateBalance*(asset: Asset, currency: string) =
asset.value = token_balance
asset.fiatValue = fmt"{fiat_balance:.2f} {currency}"
proc updateBalance*(account: Account, currency: string) =
proc updateBalance*(account: WalletAccount, currency: string) =
let eth_balance = getBalance("ETH", account.address)
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
var totalAccountBalance = usd_balance

View File

@ -73,7 +73,7 @@ ModalPopup {
// TODO add message to show validation errors
if (passwordInput.text === "" || accountNameInput.text === "" || accountPKeyInput.textAreaText === "") return;
walletModel.addAccountsFromPrivateKey(accountPKeyInput.textAreaText, passwordInput.text, accountNameInput.text, selectedColor)
walletModel.addAccountsFromPrivateKey(accountPKeyInput.text, passwordInput.text, accountNameInput.text, selectedColor)
// TODO manage errors adding account
popup.close();
}