feat: Add network balance
This commit is contained in:
parent
c7d2157d20
commit
d4d9797eec
|
@ -34,6 +34,9 @@ proc init*(self: Controller) =
|
|||
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
|
||||
self.delegate.refreshNetworks()
|
||||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
|
||||
self.delegate.refreshNetworks()
|
||||
|
||||
proc getNetworks*(self: Controller): seq[NetworkDto] =
|
||||
return self.networkService.getNetworks()
|
||||
|
||||
|
@ -44,4 +47,7 @@ proc areTestNetworksEnabled*(self: Controller): bool =
|
|||
return self.settingsService.areTestNetworksEnabled()
|
||||
|
||||
proc toggleTestNetworksEnabled*(self: Controller) =
|
||||
self.walletAccountService.toggleTestNetworksEnabled()
|
||||
self.walletAccountService.toggleTestNetworksEnabled()
|
||||
|
||||
proc getNetworkCurrencyBalance*(self: Controller, network: NetworkDto): float64 =
|
||||
return self.walletAccountService.getNetworkCurrencyBalance(network)
|
|
@ -15,6 +15,7 @@ type
|
|||
iconUrl: string
|
||||
chainColor: string
|
||||
shortName: string
|
||||
balance: float64
|
||||
|
||||
proc initItem*(
|
||||
chainId: int,
|
||||
|
@ -30,6 +31,7 @@ proc initItem*(
|
|||
iconUrl: string,
|
||||
chainColor: string,
|
||||
shortName: string,
|
||||
balance: float64,
|
||||
): Item =
|
||||
result.chainId = chainId
|
||||
result.nativeCurrencyDecimals = nativeCurrencyDecimals
|
||||
|
@ -44,6 +46,7 @@ proc initItem*(
|
|||
result.iconUrl = iconUrl
|
||||
result.chainColor = chainColor
|
||||
result.shortName = shortName
|
||||
result.balance = balance
|
||||
|
||||
proc `$`*(self: Item): string =
|
||||
result = fmt"""NetworkItem(
|
||||
|
@ -60,6 +63,7 @@ proc `$`*(self: Item): string =
|
|||
iconUrl:{self.iconUrl},
|
||||
shortName: {self.shortName},
|
||||
chainColor: {self.chainColor},
|
||||
balance: {self.balance},
|
||||
]"""
|
||||
|
||||
proc getChainId*(self: Item): int =
|
||||
|
@ -100,3 +104,6 @@ proc getShortName*(self: Item): string =
|
|||
|
||||
proc getChainColor*(self: Item): string =
|
||||
return self.chainColor
|
||||
|
||||
proc getBalance*(self: Item): float64 =
|
||||
return self.balance
|
||||
|
|
|
@ -17,6 +17,7 @@ type
|
|||
IconUrl
|
||||
ChainColor
|
||||
ShortName
|
||||
Balance
|
||||
|
||||
QtObject:
|
||||
type
|
||||
|
@ -65,6 +66,7 @@ QtObject:
|
|||
ModelRole.IconUrl.int:"iconUrl",
|
||||
ModelRole.ShortName.int: "shortName",
|
||||
ModelRole.ChainColor.int: "chainColor",
|
||||
ModelRole.Balance.int: "balance",
|
||||
}.toTable
|
||||
|
||||
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
||||
|
@ -104,6 +106,8 @@ QtObject:
|
|||
result = newQVariant(item.getShortName())
|
||||
of ModelRole.ChainColor:
|
||||
result = newQVariant(item.getChainColor())
|
||||
of ModelRole.Balance:
|
||||
result = newQVariant(item.getBalance())
|
||||
|
||||
proc setItems*(self: Model, items: seq[Item]) =
|
||||
self.beginResetModel()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml
|
||||
import Tables, NimQml
|
||||
import ../io_interface as delegate_interface
|
||||
import io_interface, view, controller
|
||||
import ../../../global/global_singleton
|
||||
|
@ -39,7 +39,10 @@ method delete*(self: Module) =
|
|||
self.controller.delete
|
||||
|
||||
method refreshNetworks*(self: Module) =
|
||||
let networks = self.controller.getNetworks()
|
||||
let networks = newTable[NetworkDto, float64]()
|
||||
|
||||
for network in self.controller.getNetworks():
|
||||
networks[network] = self.controller.getNetworkCurrencyBalance(network)
|
||||
self.view.load(networks)
|
||||
|
||||
method load*(self: Module) =
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, sequtils, sugar
|
||||
import Tables, NimQml, sequtils, sugar
|
||||
|
||||
import ../../../../app_service/service/network/dto
|
||||
import ./io_interface
|
||||
|
@ -68,22 +68,26 @@ QtObject:
|
|||
read = getEnabled
|
||||
notify = enabledChanged
|
||||
|
||||
proc load*(self: View, networks: seq[NetworkDto]) =
|
||||
let items = networks.map(n => initItem(
|
||||
n.chainId,
|
||||
n.nativeCurrencyDecimals,
|
||||
n.layer,
|
||||
n.chainName,
|
||||
n.rpcURL,
|
||||
n.blockExplorerURL,
|
||||
n.nativeCurrencyName,
|
||||
n.nativeCurrencySymbol,
|
||||
n.isTest,
|
||||
n.enabled,
|
||||
n.iconUrl,
|
||||
n.chainColor,
|
||||
n.shortName,
|
||||
))
|
||||
proc load*(self: View, networks: TableRef[NetworkDto, float64]) =
|
||||
var items: seq[Item] = @[]
|
||||
for n, balance in networks.pairs:
|
||||
items.add(initItem(
|
||||
n.chainId,
|
||||
n.nativeCurrencyDecimals,
|
||||
n.layer,
|
||||
n.chainName,
|
||||
n.rpcURL,
|
||||
n.blockExplorerURL,
|
||||
n.nativeCurrencyName,
|
||||
n.nativeCurrencySymbol,
|
||||
n.isTest,
|
||||
n.enabled,
|
||||
n.iconUrl,
|
||||
n.chainColor,
|
||||
n.shortName,
|
||||
balance,
|
||||
))
|
||||
|
||||
self.layer1.setItems(items.filter(i => i.getLayer() == 1))
|
||||
self.layer2.setItems(items.filter(i => i.getLayer() == 2))
|
||||
self.enabled.setItems(items.filter(i => i.getIsEnabled()))
|
||||
|
|
|
@ -420,4 +420,11 @@ QtObject:
|
|||
self.threadpool.start(arg)
|
||||
|
||||
proc onIsWalletEnabledChanged*(self: Service) {.slot.} =
|
||||
self.buildAllTokens()
|
||||
self.buildAllTokens()
|
||||
|
||||
proc getNetworkCurrencyBalance*(self: Service, network: NetworkDto): float64 =
|
||||
for walletAccount in toSeq(self.walletAccounts.values):
|
||||
for token in walletAccount.tokens:
|
||||
if token.balancesPerChain.hasKey(network.chainId):
|
||||
let balance = token.balancesPerChain[network.chainId]
|
||||
result += balance.currencyBalance
|
Loading…
Reference in New Issue