feat(@wallet): allows multiple addresses in assets module
Next will be other module
This commit is contained in:
parent
e022c98b4c
commit
5ac0547238
|
@ -34,8 +34,11 @@ proc delete*(self: Controller) =
|
||||||
proc init*(self: Controller) =
|
proc init*(self: Controller) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc getWalletAccountByAddress*(self: Controller, address: string): wallet_account_service.WalletAccountDto =
|
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
|
||||||
return self.walletAccountService.getAccountByAddress(address)
|
return self.walletAccountService.getAccountsByAddresses(addresses)
|
||||||
|
|
||||||
|
proc getWalletTokensByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletTokenDto] =
|
||||||
|
return self.walletAccountService.getTokensByAddresses(addresses)
|
||||||
|
|
||||||
proc getChainIds*(self: Controller): seq[int] =
|
proc getChainIds*(self: Controller): seq[int] =
|
||||||
return self.networkService.getNetworks().map(n => n.chainId)
|
return self.networkService.getNetworks().map(n => n.chainId)
|
||||||
|
|
|
@ -91,15 +91,16 @@ proc setAssetsAndBalance(self: Module, tokens: seq[WalletTokenDto], enabledChain
|
||||||
self.view.getAssetsModel().setItems(items)
|
self.view.getAssetsModel().setItems(items)
|
||||||
|
|
||||||
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
|
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
|
||||||
let walletAccount = self.controller.getWalletAccountByAddress(addresses[0])
|
let walletAccounts = self.controller.getWalletAccountsByAddresses(addresses)
|
||||||
|
|
||||||
let accountItem = walletAccountToWalletAssetsItem(walletAccount)
|
let accountItem = walletAccountToWalletAssetsItem(walletAccounts[0])
|
||||||
self.view.setData(accountItem)
|
self.view.setData(accountItem)
|
||||||
|
|
||||||
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
|
if walletAccounts[0].tokens.len == 0 and walletAccounts[0].assetsLoading:
|
||||||
self.setLoadingAssets()
|
self.setLoadingAssets()
|
||||||
else:
|
else:
|
||||||
self.setAssetsAndBalance(walletAccount.tokens, chainIds)
|
let walletTokens = self.controller.getWalletTokensByAddresses(addresses)
|
||||||
|
self.setAssetsAndBalance(walletTokens, chainIds)
|
||||||
|
|
||||||
proc onTokensRebuilt(self: Module, hasBalanceCache: bool, hasMarketValuesCache: bool) =
|
proc onTokensRebuilt(self: Module, hasBalanceCache: bool, hasMarketValuesCache: bool) =
|
||||||
self.view.setAssetsLoading(false)
|
self.view.setAssetsLoading(false)
|
||||||
|
|
|
@ -70,8 +70,10 @@ proc walletAccountToWalletAssetsItem*(w: WalletAccountDto): wallet_assets_item.I
|
||||||
w.assetsLoading,
|
w.assetsLoading,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc walletTokenToItem*(t: WalletTokenDto, chainIds: seq[int], enabledChainIds: seq[int], currency: string,
|
proc walletTokenToItem*(
|
||||||
currencyFormat: CurrencyFormatDto, tokenFormat: CurrencyFormatDto): token_item.Item =
|
t: WalletTokenDto, chainIds: seq[int], enabledChainIds: seq[int], currency: string,
|
||||||
|
currencyFormat: CurrencyFormatDto, tokenFormat: CurrencyFormatDto
|
||||||
|
): token_item.Item =
|
||||||
let marketValues = t.marketValuesPerCurrency.getOrDefault(currency)
|
let marketValues = t.marketValuesPerCurrency.getOrDefault(currency)
|
||||||
return token_item.initItem(
|
return token_item.initItem(
|
||||||
t.name,
|
t.name,
|
||||||
|
|
|
@ -178,6 +178,23 @@ proc `$`*(self: WalletAccountDto): string =
|
||||||
proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =
|
proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =
|
||||||
return self.balance * currencyPrice
|
return self.balance * currencyPrice
|
||||||
|
|
||||||
|
proc copyToken*(self: WalletTokenDto): WalletTokenDto =
|
||||||
|
result = WalletTokenDto()
|
||||||
|
result.name = self.name
|
||||||
|
result.symbol = self.symbol
|
||||||
|
result.decimals = self.decimals
|
||||||
|
result.color = self.color
|
||||||
|
result.description = self.description
|
||||||
|
result.assetWebsiteUrl = self.assetWebsiteUrl
|
||||||
|
result.builtOn = self.builtOn
|
||||||
|
|
||||||
|
result.balancesPerChain = initTable[int, BalanceDto]()
|
||||||
|
for chainId, balanceDto in self.balancesPerChain:
|
||||||
|
result.balancesPerChain[chainId] = balanceDto
|
||||||
|
result.marketValuesPerCurrency = initTable[string, TokenMarketValuesDto]()
|
||||||
|
for chainId, tokenMarketValuesDto in self.marketValuesPerCurrency:
|
||||||
|
result.marketValuesPerCurrency[chainId] = tokenMarketValuesDto
|
||||||
|
|
||||||
proc getAddress*(self: WalletTokenDto): string =
|
proc getAddress*(self: WalletTokenDto): string =
|
||||||
for balance in self.balancesPerChain.values:
|
for balance in self.balancesPerChain.values:
|
||||||
return balance.address
|
return balance.address
|
||||||
|
|
|
@ -274,6 +274,30 @@ QtObject:
|
||||||
return
|
return
|
||||||
result = self.walletAccounts[address]
|
result = self.walletAccounts[address]
|
||||||
|
|
||||||
|
proc getAccountsByAddresses*(self: Service, addresses: seq[string]): seq[WalletAccountDto] =
|
||||||
|
for address in addresses:
|
||||||
|
result.add(self.getAccountByAddress(address))
|
||||||
|
|
||||||
|
proc getTokensByAddresses*(self: Service, addresses: seq[string]): seq[WalletTokenDto] =
|
||||||
|
var tokens = initTable[string, WalletTokenDto]()
|
||||||
|
for address in addresses:
|
||||||
|
let walletAccount = self.getAccountByAddress(address)
|
||||||
|
for token in walletAccount.tokens:
|
||||||
|
if not tokens.hasKey(token.symbol):
|
||||||
|
let newToken = token.copyToken()
|
||||||
|
tokens[token.symbol] = newToken
|
||||||
|
continue
|
||||||
|
|
||||||
|
for chainId, balanceDto in token.balancesPerChain:
|
||||||
|
if not tokens[token.symbol].balancesPerChain.hasKey(chainId):
|
||||||
|
tokens[token.symbol].balancesPerChain[chainId] = balanceDto
|
||||||
|
continue
|
||||||
|
|
||||||
|
tokens[token.symbol].balancesPerChain[chainId].balance += balanceDto.balance
|
||||||
|
|
||||||
|
result = toSeq(tokens.values)
|
||||||
|
result.sort(priorityTokenCmp)
|
||||||
|
|
||||||
proc getWalletAccounts*(self: Service): seq[WalletAccountDto] =
|
proc getWalletAccounts*(self: Service): seq[WalletAccountDto] =
|
||||||
result = toSeq(self.walletAccounts.values)
|
result = toSeq(self.walletAccounts.values)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue