update balances & currency across walet; move account generation
update total fiat balance so it can auto update update account list when needed force update of asset list add account in the model add 0x0 address instead of invalid one ensure asset list is updated
This commit is contained in:
parent
1b086b006d
commit
1fb9be3d7d
|
@ -34,9 +34,18 @@ proc init*(self: WalletController) =
|
|||
var accounts = self.status.wallet.accounts
|
||||
for account in accounts:
|
||||
self.view.addAccountToList(account)
|
||||
self.view.setTotalFiatBalance(self.status.wallet.getTotalFiatBalance())
|
||||
|
||||
self.status.events.on("accountsUpdated") do(e: Args):
|
||||
self.view.totalFiatBalanceChanged()
|
||||
self.view.currentAccountChanged()
|
||||
self.view.accountListChanged()
|
||||
self.view.accounts.forceUpdate()
|
||||
self.view.currentAssetList.forceUpdate()
|
||||
|
||||
self.status.events.on("newAccountAdded") do(e: Args):
|
||||
var account = AccountArgs(e)
|
||||
self.view.accounts.addAccountToList(account.account)
|
||||
|
||||
method onSignal(self: WalletController, data: Signal) =
|
||||
debug "New signal received"
|
||||
|
|
|
@ -16,7 +16,7 @@ QtObject:
|
|||
currentAssetList*: AssetList
|
||||
currentAccount: AccountItemView
|
||||
status: Status
|
||||
totalFiatBalance: float
|
||||
totalFiatBalance: string
|
||||
|
||||
proc delete(self: WalletView) =
|
||||
self.QAbstractListModel.delete
|
||||
|
@ -30,10 +30,13 @@ QtObject:
|
|||
result.accounts = newAccountList()
|
||||
result.currentAccount = newAccountItemView()
|
||||
result.currentAssetList = newAssetList()
|
||||
result.totalFiatBalance = ""
|
||||
result.setup
|
||||
|
||||
proc currentAccountChanged*(self: WalletView) {.signal.}
|
||||
|
||||
proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset])
|
||||
|
||||
proc setCurrentAccountByIndex*(self: WalletView, index: int) {.slot.} =
|
||||
if(self.accounts.rowCount() == 0): return
|
||||
|
||||
|
@ -41,6 +44,7 @@ QtObject:
|
|||
if self.currentAccount.address == selectedAccount.address: return
|
||||
self.currentAccount.setAccountItem(selectedAccount)
|
||||
self.currentAccountChanged()
|
||||
self.setCurrentAssetList(selectedAccount.assetList)
|
||||
|
||||
proc getCurrentAccount*(self: WalletView): QVariant {.slot.} =
|
||||
result = newQVariant(self.currentAccount)
|
||||
|
@ -66,17 +70,17 @@ QtObject:
|
|||
|
||||
proc totalFiatBalanceChanged*(self: WalletView) {.signal.}
|
||||
|
||||
proc getTotalFiatBalance(self: WalletView): QVariant {.slot.} =
|
||||
return newQVariant(fmt"{self.totalFiatBalance:.2f} USD") # TODO use user's currency
|
||||
proc getTotalFiatBalance(self: WalletView): string {.slot.} =
|
||||
self.status.wallet.getTotalFiatBalance()
|
||||
|
||||
proc setTotalFiatBalance*(self: WalletView, newBalance: float) =
|
||||
proc setTotalFiatBalance*(self: WalletView, newBalance: string) =
|
||||
self.totalFiatBalance = newBalance
|
||||
self.totalFiatBalanceChanged()
|
||||
|
||||
QtProperty[QVariant] totalFiatBalance:
|
||||
QtProperty[string] totalFiatBalance:
|
||||
read = getTotalFiatBalance
|
||||
write = setTotalFiatBalance
|
||||
notify = currentAssetListChanged
|
||||
notify = totalFiatBalanceChanged
|
||||
|
||||
proc accountListChanged*(self: WalletView) {.signal.}
|
||||
|
||||
|
@ -86,20 +90,10 @@ QtObject:
|
|||
if (self.accounts.rowCount == 1):
|
||||
self.setCurrentAssetList(account.assetList)
|
||||
self.setCurrentAccountByIndex(0)
|
||||
self.setTotalFiatBalance(account.realFiatBalance + self.totalFiatBalance)
|
||||
self.accountListChanged()
|
||||
|
||||
proc generateNewAccount*(self: WalletView, password: string, accountName: string, color: string) {.slot.} =
|
||||
# TODO move all this to the model to add a real account
|
||||
# let assetList = newAssetList()
|
||||
var assetList: seq[Asset] = @[]
|
||||
let symbol = "ETH"
|
||||
let asset = Asset(name:"Ethereum", symbol: symbol, value: fmt"0", fiatValue: "$0.00", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
||||
# assetList.addAssetToList(asset)
|
||||
let defaultCurrency = "USD" # TODO get real default
|
||||
# TODO get a real address that we unlock with the password
|
||||
let account = Account(name: accountName, address: "0x0r329ru298u392r", iconColor: color, balance: fmt"0.00 {defaultCurrency}", assetList: assetList, realFiatBalance: 0.0)
|
||||
self.addAccountToList(account)
|
||||
self.status.wallet.generateNewAccount(password, accountName, color)
|
||||
|
||||
proc getAccountList(self: WalletView): QVariant {.slot.} =
|
||||
return newQVariant(self.accounts)
|
||||
|
|
|
@ -5,15 +5,7 @@ import ./asset_list
|
|||
import ./account_item
|
||||
import ../../../status/wallet
|
||||
|
||||
const accountColors* = [
|
||||
"#9B832F",
|
||||
"#D37EF4",
|
||||
"#1D806F",
|
||||
"#FA6565",
|
||||
"#7CDA00",
|
||||
"#887af9",
|
||||
"#8B3131"
|
||||
]
|
||||
const accountColors* = ["#9B832F", "#D37EF4", "#1D806F", "#FA6565", "#7CDA00", "#887af9", "#8B3131"]
|
||||
|
||||
type
|
||||
AccountRoles {.pure.} = enum
|
||||
|
@ -68,3 +60,7 @@ QtObject:
|
|||
self.beginInsertRows(newQModelIndex(), self.accounts.len, self.accounts.len)
|
||||
self.accounts.add(account)
|
||||
self.endInsertRows()
|
||||
|
||||
proc forceUpdate*(self: AccountList) =
|
||||
self.beginResetModel()
|
||||
self.endResetModel()
|
||||
|
|
|
@ -58,3 +58,7 @@ QtObject:
|
|||
self.beginResetModel()
|
||||
self.assets = assetList
|
||||
self.endResetModel()
|
||||
|
||||
proc forceUpdate*(self: AssetList) =
|
||||
self.beginResetModel()
|
||||
self.endResetModel()
|
||||
|
|
|
@ -16,19 +16,26 @@ type Account* = ref object
|
|||
realFiatBalance*: float
|
||||
assetList*: seq[Asset]
|
||||
|
||||
type AccountArgs* = ref object of Args
|
||||
account*: Account
|
||||
|
||||
type WalletModel* = ref object
|
||||
events*: EventEmitter
|
||||
accounts*: seq[Account]
|
||||
defaultCurrency*: string
|
||||
|
||||
proc updateBalance*(self: Account)
|
||||
proc getDefaultCurrency*(self: WalletModel): string
|
||||
|
||||
proc newWalletModel*(events: EventEmitter): WalletModel =
|
||||
result = WalletModel()
|
||||
result.accounts = @[]
|
||||
result.events = events
|
||||
result.defaultCurrency = ""
|
||||
|
||||
proc initEvents*(self: WalletModel) =
|
||||
self.events.on("currencyChanged") do(e: Args):
|
||||
self.defaultCurrency = self.getDefaultCurrency()
|
||||
for account in self.accounts:
|
||||
account.updateBalance()
|
||||
self.events.emit("accountsUpdated", Args())
|
||||
|
@ -100,3 +107,20 @@ proc initAccounts*(self: WalletModel) =
|
|||
var account = Account(name: "Status Account", address: address, iconColor: "", balance: "", assetList: assets, realFiatBalance: totalAccountBalance)
|
||||
account.updateBalance()
|
||||
self.accounts.add(account)
|
||||
|
||||
proc getTotalFiatBalance*(self: WalletModel): string =
|
||||
var newBalance = 0.0
|
||||
fmt"{newBalance:.2f} {self.defaultCurrency}"
|
||||
|
||||
proc generateNewAccount*(self: WalletModel, password: string, accountName: string, color: string) =
|
||||
# TODO get a real address that we unlock with the password
|
||||
|
||||
var symbol = "SNT"
|
||||
var asset = Asset(name:"Status", symbol: symbol, value: fmt"0.0", fiatValue: "$" & fmt"0.0", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
||||
var assets: seq[Asset] = @[]
|
||||
assets.add(asset)
|
||||
|
||||
var account = Account(name: accountName, address: "0x0000000000000000000000000000000000000000", iconColor: color, balance: fmt"0.00 {self.defaultCurrency}", assetList: assets, realFiatBalance: 0.0)
|
||||
|
||||
self.accounts.add(account)
|
||||
self.events.emit("newAccountAdded", AccountArgs(account: account))
|
||||
|
|
Loading…
Reference in New Issue