move wallet related models
move wallet related models set data move accounts init to the model
This commit is contained in:
parent
1a160cf664
commit
b4aae8fa3b
|
@ -1,5 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
# import eventemitter
|
import eventemitter
|
||||||
import strformat
|
import strformat
|
||||||
import strutils
|
import strutils
|
||||||
import chronicles
|
import chronicles
|
||||||
|
@ -14,7 +14,6 @@ import ../../signals/types
|
||||||
import ../../status/wallet
|
import ../../status/wallet
|
||||||
import ../../status/status
|
import ../../status/status
|
||||||
|
|
||||||
|
|
||||||
type WalletController* = ref object of SignalSubscriber
|
type WalletController* = ref object of SignalSubscriber
|
||||||
status: Status
|
status: Status
|
||||||
view*: WalletView
|
view*: WalletView
|
||||||
|
@ -31,28 +30,14 @@ proc delete*(self: WalletController) =
|
||||||
delete self.variant
|
delete self.variant
|
||||||
|
|
||||||
proc init*(self: WalletController) =
|
proc init*(self: WalletController) =
|
||||||
let accounts = status_wallet.getAccounts()
|
self.status.events.on("currencyChanged") do(e: Args):
|
||||||
|
echo "currency changed"
|
||||||
|
|
||||||
var totalAccountBalance: float = 0
|
self.status.wallet.initAccounts()
|
||||||
|
var accounts = self.status.wallet.accounts
|
||||||
const symbol = "ETH"
|
for account in accounts:
|
||||||
let defaultCurrency = self.status.wallet.getDefaultCurrency()
|
|
||||||
for address in accounts:
|
|
||||||
let eth_balance = self.status.wallet.getEthBalance(address)
|
|
||||||
# TODO get all user assets and add them to balance
|
|
||||||
let usd_balance = self.status.wallet.getFiatValue(eth_balance, symbol, defaultCurrency)
|
|
||||||
|
|
||||||
totalAccountBalance = totalAccountBalance + usd_balance
|
|
||||||
|
|
||||||
let assetList = newAssetList()
|
|
||||||
let asset = Asset(name:"Ethereum", symbol: symbol, value: fmt"{eth_balance:.6}", fiatValue: "$" & fmt"{usd_balance:.2f}", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
|
||||||
assetList.addAssetToList(asset)
|
|
||||||
|
|
||||||
let account = Account(name: "Status Account", address: address, iconColor: "", balance: fmt"{totalAccountBalance:.2f} {defaultCurrency}", assetList: assetList, realFiatBalance: totalAccountBalance)
|
|
||||||
self.view.addAccountToList(account)
|
self.view.addAccountToList(account)
|
||||||
|
|
||||||
self.view.setDefaultAccount(accounts[0])
|
|
||||||
|
|
||||||
method onSignal(self: WalletController, data: Signal) =
|
method onSignal(self: WalletController, data: Signal) =
|
||||||
debug "New signal received"
|
debug "New signal received"
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -15,7 +15,6 @@ QtObject:
|
||||||
accounts*: AccountList
|
accounts*: AccountList
|
||||||
currentAssetList*: AssetList
|
currentAssetList*: AssetList
|
||||||
currentAccount: AccountItemView
|
currentAccount: AccountItemView
|
||||||
defaultAccount: string
|
|
||||||
status: Status
|
status: Status
|
||||||
totalFiatBalance: float
|
totalFiatBalance: float
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ QtObject:
|
||||||
result.status = status
|
result.status = status
|
||||||
result.accounts = newAccountList()
|
result.accounts = newAccountList()
|
||||||
result.currentAccount = newAccountItemView()
|
result.currentAccount = newAccountItemView()
|
||||||
result.currentAssetList = newAssetList() # Temporarily set to an empty list
|
result.currentAssetList = newAssetList()
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc currentAccountChanged*(self: WalletView) {.signal.}
|
proc currentAccountChanged*(self: WalletView) {.signal.}
|
||||||
|
@ -56,8 +55,8 @@ QtObject:
|
||||||
proc getCurrentAssetList(self: WalletView): QVariant {.slot.} =
|
proc getCurrentAssetList(self: WalletView): QVariant {.slot.} =
|
||||||
return newQVariant(self.currentAssetList)
|
return newQVariant(self.currentAssetList)
|
||||||
|
|
||||||
proc setCurrentAssetList*(self: WalletView, assetList: AssetList) =
|
proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset]) =
|
||||||
self.currentAssetList = assetList
|
self.currentAssetList.setNewData(assetList)
|
||||||
self.currentAssetListChanged()
|
self.currentAssetListChanged()
|
||||||
|
|
||||||
QtProperty[QVariant] assets:
|
QtProperty[QVariant] assets:
|
||||||
|
@ -111,11 +110,8 @@ QtObject:
|
||||||
proc onSendTransaction*(self: WalletView, from_value: string, to: string, value: string, password: string): string {.slot.} =
|
proc onSendTransaction*(self: WalletView, from_value: string, to: string, value: string, password: string): string {.slot.} =
|
||||||
result = self.status.wallet.sendTransaction(from_value, to, value, password)
|
result = self.status.wallet.sendTransaction(from_value, to, value, password)
|
||||||
|
|
||||||
proc setDefaultAccount*(self: WalletView, account: string) =
|
|
||||||
self.defaultAccount = account
|
|
||||||
|
|
||||||
proc getDefaultAccount*(self: WalletView): string {.slot.} =
|
proc getDefaultAccount*(self: WalletView): string {.slot.} =
|
||||||
return self.defaultAccount
|
self.currentAccount.address
|
||||||
|
|
||||||
proc defaultCurrency*(self: WalletView): string {.slot.} =
|
proc defaultCurrency*(self: WalletView): string {.slot.} =
|
||||||
self.status.wallet.getDefaultCurrency()
|
self.status.wallet.getDefaultCurrency()
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import std/wrapnils
|
import std/wrapnils
|
||||||
import ./asset_list
|
import ./asset_list
|
||||||
|
import ../../../status/wallet
|
||||||
type Account* = ref object
|
|
||||||
name*, address*, iconColor*, balance*: string
|
|
||||||
realFiatBalance*: float
|
|
||||||
assetList*: AssetList
|
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type AccountItemView* = ref object of QObject
|
type AccountItemView* = ref object of QObject
|
||||||
|
|
|
@ -53,3 +53,8 @@ QtObject:
|
||||||
self.beginInsertRows(newQModelIndex(), self.assets.len, self.assets.len)
|
self.beginInsertRows(newQModelIndex(), self.assets.len, self.assets.len)
|
||||||
self.assets.add(asset)
|
self.assets.add(asset)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
||||||
|
proc setNewData*(self: AssetList, assetList: seq[Asset]) =
|
||||||
|
self.beginResetModel()
|
||||||
|
self.assets = assetList
|
||||||
|
self.endResetModel()
|
||||||
|
|
|
@ -23,7 +23,7 @@ proc newStatusInstance*(): Status =
|
||||||
result.events = createEventEmitter()
|
result.events = createEventEmitter()
|
||||||
result.chat = chat.newChatModel(result.events)
|
result.chat = chat.newChatModel(result.events)
|
||||||
result.accounts = accounts.newAccountModel()
|
result.accounts = accounts.newAccountModel()
|
||||||
result.wallet = wallet.newWalletModel()
|
result.wallet = wallet.newWalletModel(result.events)
|
||||||
result.node = node.newNodeModel()
|
result.node = node.newNodeModel()
|
||||||
result.mailservers = mailservers.newMailserverModel(result.events)
|
result.mailservers = mailservers.newMailserverModel(result.events)
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,19 @@ type CurrencyArgs* = ref object of Args
|
||||||
type Asset* = ref object
|
type Asset* = ref object
|
||||||
name*, symbol*, value*, fiatValue*, image*: string
|
name*, symbol*, value*, fiatValue*, image*: string
|
||||||
|
|
||||||
|
type Account* = ref object
|
||||||
|
name*, address*, iconColor*, balance*: string
|
||||||
|
realFiatBalance*: float
|
||||||
|
assetList*: seq[Asset]
|
||||||
|
# assetList*: AssetList
|
||||||
|
|
||||||
type WalletModel* = ref object
|
type WalletModel* = ref object
|
||||||
events*: EventEmitter
|
events*: EventEmitter
|
||||||
|
accounts*: seq[Account]
|
||||||
|
|
||||||
proc newWalletModel*(): WalletModel =
|
proc newWalletModel*(events: EventEmitter): WalletModel =
|
||||||
result = WalletModel()
|
result = WalletModel()
|
||||||
result.events = createEventEmitter()
|
result.events = events
|
||||||
|
|
||||||
proc delete*(self: WalletModel) =
|
proc delete*(self: WalletModel) =
|
||||||
discard
|
discard
|
||||||
|
@ -52,3 +59,23 @@ proc getFiatValue*(self: WalletModel, eth_balance: string, symbol: string, fiat_
|
||||||
|
|
||||||
proc hasAsset*(self: WalletModel, account: string, symbol: string): bool =
|
proc hasAsset*(self: WalletModel, account: string, symbol: string): bool =
|
||||||
(symbol == "DAI") or (symbol == "OMG")
|
(symbol == "DAI") or (symbol == "OMG")
|
||||||
|
|
||||||
|
proc initAccounts*(self: WalletModel) =
|
||||||
|
let accounts = status_wallet.getAccounts()
|
||||||
|
|
||||||
|
var totalAccountBalance: float = 0
|
||||||
|
const symbol = "ETH"
|
||||||
|
let defaultCurrency = self.getDefaultCurrency()
|
||||||
|
|
||||||
|
for address in accounts:
|
||||||
|
let eth_balance = self.getEthBalance(address)
|
||||||
|
let usd_balance = self.getFiatValue(eth_balance, symbol, defaultCurrency)
|
||||||
|
|
||||||
|
totalAccountBalance = totalAccountBalance + usd_balance
|
||||||
|
|
||||||
|
var asset = Asset(name:"Ethereum", symbol: symbol, value: fmt"{eth_balance:.6}", fiatValue: "$" & fmt"{usd_balance:.2f}", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
||||||
|
var assets: seq[Asset] = @[]
|
||||||
|
assets.add(asset)
|
||||||
|
|
||||||
|
var account = Account(name: "Status Account", address: address, iconColor: "", balance: fmt"{totalAccountBalance:.2f} {defaultCurrency}", assetList: assets, realFiatBalance: totalAccountBalance)
|
||||||
|
self.accounts.add(account)
|
||||||
|
|
Loading…
Reference in New Issue