fix(wallet) remove unused API GetTokensBalances old api
Replace it with the new API GetWalletToken Move the backend related json parsing to the backend/helpers folder Update some imports to absolute paths Remove indirect imports Closes: #12914
This commit is contained in:
parent
d3a0c95979
commit
a4835a25ce
|
@ -1,9 +1,11 @@
|
||||||
import sugar, sequtils
|
import sugar, sequtils
|
||||||
import io_interface
|
import io_interface
|
||||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../../../app_service/service/network/service as network_service
|
import app_service/service/network/service as network_service
|
||||||
import ../../../../../app_service/service/token/service as token_service
|
import app_service/service/token/service as token_service
|
||||||
import ../../../../../app_service/service/currency/service as currency_service
|
import app_service/service/currency/service as currency_service
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
type
|
type
|
||||||
Controller* = ref object of RootObj
|
Controller* = ref object of RootObj
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
import NimQml, Tables, sequtils, strutils, sugar
|
import NimQml, Tables, sequtils, strutils, sugar
|
||||||
|
|
||||||
import ../../../../global/global_singleton
|
import app/global/global_singleton
|
||||||
import ../../../../core/eventemitter
|
import app/core/eventemitter
|
||||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../../../app_service/service/network/service as network_service
|
import app_service/service/network/service as network_service
|
||||||
import ../../../../../app_service/service/token/service as token_service
|
import app_service/service/token/service as token_service
|
||||||
import ../../../../../app_service/service/currency/service as currency_service
|
import app_service/service/currency/service as currency_service
|
||||||
import ../../../shared/wallet_utils
|
import app/modules/shared/wallet_utils
|
||||||
import ../../../shared_models/token_model as token_model
|
import app/modules/shared_models/token_model as token_model
|
||||||
|
|
||||||
import ./io_interface, ./view, ./controller
|
import ./io_interface, ./view, ./controller
|
||||||
import ../io_interface as delegate_interface
|
import ../io_interface as delegate_interface
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -10,6 +10,8 @@ import app_service/common/types
|
||||||
|
|
||||||
import app_service/service/profile/dto/profile_showcase_preferences
|
import app_service/service/profile/dto/profile_showcase_preferences
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
type
|
type
|
||||||
Controller* = ref object of RootObj
|
Controller* = ref object of RootObj
|
||||||
delegate: io_interface.AccessInterface
|
delegate: io_interface.AccessInterface
|
||||||
|
|
|
@ -5,11 +5,13 @@ import profile_preferences_base_item
|
||||||
import app_service/service/wallet_account/dto/account_dto
|
import app_service/service/wallet_account/dto/account_dto
|
||||||
import app_service/service/profile/dto/profile_showcase_preferences
|
import app_service/service/profile/dto/profile_showcase_preferences
|
||||||
|
|
||||||
import ../../../../shared_models/currency_amount
|
import app/modules/shared_models/currency_amount
|
||||||
|
|
||||||
include app_service/common/json_utils
|
include app_service/common/json_utils
|
||||||
include app_service/common/utils
|
include app_service/common/utils
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
type
|
type
|
||||||
ProfileShowcaseAssetItem* = ref object of ProfileShowcaseBaseItem
|
ProfileShowcaseAssetItem* = ref object of ProfileShowcaseBaseItem
|
||||||
symbol*: string
|
symbol*: string
|
||||||
|
|
|
@ -15,6 +15,8 @@ import app_service/service/settings/service
|
||||||
|
|
||||||
import backend/collectibles as backend_collectibles
|
import backend/collectibles as backend_collectibles
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import sugar, sequtils
|
import sugar, sequtils
|
||||||
import io_interface
|
import io_interface
|
||||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../../../app_service/service/network/service as network_service
|
import app_service/service/network/service as network_service
|
||||||
import ../../../../../app_service/service/token/service as token_service
|
import app_service/service/token/service as token_service
|
||||||
import ../../../../../app_service/service/currency/service as currency_service
|
import app_service/service/currency/service as currency_service
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
type
|
type
|
||||||
Controller* = ref object of RootObj
|
Controller* = ref object of RootObj
|
||||||
|
@ -36,7 +38,7 @@ proc init*(self: Controller) =
|
||||||
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
|
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
|
||||||
return self.walletAccountService.getAccountsByAddresses(addresses)
|
return self.walletAccountService.getAccountsByAddresses(addresses)
|
||||||
|
|
||||||
proc getWalletTokensByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletTokenDto] =
|
proc getWalletTokensByAddresses*(self: Controller, addresses: seq[string]): seq[WalletTokenDto] =
|
||||||
return self.walletAccountService.getTokensByAddresses(addresses)
|
return self.walletAccountService.getTokensByAddresses(addresses)
|
||||||
|
|
||||||
proc getChainIds*(self: Controller): seq[int] =
|
proc getChainIds*(self: Controller): seq[int] =
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
import NimQml, sequtils, sugar
|
import NimQml, sequtils, sugar
|
||||||
|
|
||||||
import ../../../../global/global_singleton
|
import app/global/global_singleton
|
||||||
import ../../../../core/eventemitter
|
import app/core/eventemitter
|
||||||
import ../../../../../app_service/service/token/service as token_service
|
import app_service/service/token/service as token_service
|
||||||
import ../../../../../app_service/service/currency/service as currency_service
|
import app_service/service/currency/service as currency_service
|
||||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../../../app_service/service/network/service as network_service
|
import app_service/service/network/service as network_service
|
||||||
import ../../../../../app_service/service/network_connection/service as network_connection
|
import app_service/service/network_connection/service as network_connection
|
||||||
import ../../../../../app_service/service/node/service as node_service
|
import app_service/service/node/service as node_service
|
||||||
import ../../../shared/wallet_utils
|
import app/modules/shared/wallet_utils
|
||||||
import ../../../shared_models/token_model as token_model
|
import app/modules/shared_models/token_model as token_model
|
||||||
import ../../../shared_models/token_item as token_item
|
import app/modules/shared_models/token_item as token_item
|
||||||
|
|
||||||
import ./io_interface, ./view, ./controller
|
import ./io_interface, ./view, ./controller
|
||||||
import ../io_interface as delegate_interface
|
import ../io_interface as delegate_interface
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import io_interface
|
import io_interface
|
||||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../../../app_service/service/currency/service as currency_service
|
import app_service/service/currency/service as currency_service
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
type
|
type
|
||||||
Controller* = ref object of RootObj
|
Controller* = ref object of RootObj
|
||||||
|
@ -27,7 +29,7 @@ proc init*(self: Controller) =
|
||||||
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
|
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
|
||||||
return self.walletAccountService.getAccountsByAddresses(addresses)
|
return self.walletAccountService.getAccountsByAddresses(addresses)
|
||||||
|
|
||||||
proc getWalletTokensByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletTokenDto] =
|
proc getWalletTokensByAddresses*(self: Controller, addresses: seq[string]): seq[WalletTokenDto] =
|
||||||
return self.walletAccountService.getTokensByAddresses(addresses)
|
return self.walletAccountService.getTokensByAddresses(addresses)
|
||||||
|
|
||||||
proc getCurrentCurrency*(self: Controller): string =
|
proc getCurrentCurrency*(self: Controller): string =
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
import NimQml, sequtils, sugar
|
import NimQml, sequtils, sugar
|
||||||
|
|
||||||
import ../../../../global/global_singleton
|
import app/global/global_singleton
|
||||||
import ../../../../core/eventemitter
|
import app/core/eventemitter
|
||||||
import ../../../../../app_service/service/currency/service as currency_service
|
import app_service/service/currency/service as currency_service
|
||||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../shared/wallet_utils
|
import app/modules/shared/wallet_utils
|
||||||
import ../../../shared_models/currency_amount
|
import app/modules/shared_models/currency_amount
|
||||||
import ./item
|
import ./item
|
||||||
|
|
||||||
import ./io_interface, ./view, ./controller
|
import ./io_interface, ./view, ./controller
|
||||||
import ../io_interface as delegate_interface
|
import ../io_interface as delegate_interface
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -15,6 +15,8 @@ import app/modules/shared_models/currency_amount
|
||||||
import app/core/signals/types
|
import app/core/signals/types
|
||||||
import app/core/eventemitter
|
import app/core/eventemitter
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "wallet-send-controller"
|
topics = "wallet-send-controller"
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@ import tables, sequtils, stint, sugar
|
||||||
|
|
||||||
import ../shared_models/[balance_item, currency_amount, token_item, token_model, wallet_account_item]
|
import ../shared_models/[balance_item, currency_amount, token_item, token_model, wallet_account_item]
|
||||||
|
|
||||||
import ../../../app_service/service/wallet_account/service as wallet_account_service
|
import backend/helpers/token
|
||||||
import ../../../app_service/service/currency/dto as currency_dto
|
|
||||||
|
import app_service/service/currency/dto as currency_dto
|
||||||
|
|
||||||
import ../main/wallet_section/accounts/item as wallet_accounts_item
|
import ../main/wallet_section/accounts/item as wallet_accounts_item
|
||||||
import ../main/wallet_section/assets/item as wallet_assets_item
|
import ../main/wallet_section/assets/item as wallet_assets_item
|
||||||
import ../main/wallet_section/send/account_item as wallet_send_account_item
|
import ../main/wallet_section/send/account_item as wallet_send_account_item
|
||||||
|
|
||||||
|
import backend/helpers/balance
|
||||||
|
|
||||||
proc currencyAmountToItem*(amount: float64, format: CurrencyFormatDto) : CurrencyAmount =
|
proc currencyAmountToItem*(amount: float64, format: CurrencyFormatDto) : CurrencyAmount =
|
||||||
return newCurrencyAmount(
|
return newCurrencyAmount(
|
||||||
amount,
|
amount,
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import NimQml, tables
|
import NimQml, tables
|
||||||
import app/core/eventemitter
|
import app/core/eventemitter
|
||||||
from app_service/service/keycard/service import KeycardEvent, CardMetadata, KeyDetails
|
from app_service/service/keycard/service import KeycardEvent, CardMetadata, KeyDetails
|
||||||
from app_service/service/wallet_account/service as wallet_account_service import WalletTokenDto
|
|
||||||
|
from backend/helpers/token import WalletTokenDto
|
||||||
|
|
||||||
import app/modules/shared_models/keypair_item
|
import app/modules/shared_models/keypair_item
|
||||||
|
|
||||||
type FlowType* {.pure.} = enum
|
type FlowType* {.pure.} = enum
|
||||||
|
|
|
@ -3,21 +3,23 @@ import NimQml, tables, strutils, sequtils, sugar, chronicles
|
||||||
import io_interface
|
import io_interface
|
||||||
import view, controller
|
import view, controller
|
||||||
import internal/[state, state_factory]
|
import internal/[state, state_factory]
|
||||||
import ../../shared/[keypairs, wallet_utils]
|
import app/modules/shared/[keypairs, wallet_utils]
|
||||||
import ../../shared_models/[keypair_model, keypair_item, currency_amount]
|
import app/modules/shared_models/[keypair_model, keypair_item, currency_amount]
|
||||||
import ../../../global/app_translatable_constants as atc
|
import app/global/app_translatable_constants as atc
|
||||||
import ../../../global/global_singleton
|
import app/global/global_singleton
|
||||||
import ../../../core/eventemitter
|
import app/core/eventemitter
|
||||||
|
|
||||||
import ../../../../app_service/common/utils
|
import app_service/common/utils
|
||||||
import ../../../../app_service/service/keycard/constants
|
import app_service/service/keycard/constants
|
||||||
import ../../../../app_service/service/keycard/service as keycard_service
|
import app_service/service/keycard/service as keycard_service
|
||||||
import ../../../../app_service/service/settings/service as settings_service
|
import app_service/service/settings/service as settings_service
|
||||||
import ../../../../app_service/service/network/service as network_service
|
import app_service/service/network/service as network_service
|
||||||
import ../../../../app_service/service/privacy/service as privacy_service
|
import app_service/service/privacy/service as privacy_service
|
||||||
import ../../../../app_service/service/accounts/service as accounts_service
|
import app_service/service/accounts/service as accounts_service
|
||||||
import ../../../../app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
import ../../../../app_service/service/keychain/service as keychain_service
|
import app_service/service/keychain/service as keychain_service
|
||||||
|
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,10 @@ import app/global/global_singleton
|
||||||
import backend/ens as status_ens
|
import backend/ens as status_ens
|
||||||
import backend/backend as status_go_backend
|
import backend/backend as status_go_backend
|
||||||
import backend/wallet as status_wallet
|
import backend/wallet as status_wallet
|
||||||
|
import backend/helpers/helpers
|
||||||
|
|
||||||
import app_service/common/conversion as common_conversion
|
import app_service/common/conversion as common_conversion
|
||||||
|
|
||||||
import utils as ens_utils
|
import utils as ens_utils
|
||||||
import app_service/service/settings/service as settings_service
|
import app_service/service/settings/service as settings_service
|
||||||
import app_service/service/wallet_account/service as wallet_account_service
|
import app_service/service/wallet_account/service as wallet_account_service
|
||||||
|
@ -311,8 +313,11 @@ QtObject:
|
||||||
proc getSNTBalance*(self: Service): string =
|
proc getSNTBalance*(self: Service): string =
|
||||||
let token = self.getStatusToken()
|
let token = self.getStatusToken()
|
||||||
let account = self.walletAccountService.getWalletAccount(0).address
|
let account = self.walletAccountService.getWalletAccount(0).address
|
||||||
let balances = status_go_backend.getTokensBalancesForChainIDs(@[self.getChainId()], @[account], @[token.address]).result
|
|
||||||
return ens_utils.hex2Token(balances{account}{token.address}.getStr, token.decimals)
|
let info = getTokenBalanceForAccount(self.getChainId(), account, token.symbol)
|
||||||
|
if info.isNone:
|
||||||
|
return "0"
|
||||||
|
return ens_utils.hex2Token(info.get().rawBalance.toString(16), token.decimals)
|
||||||
|
|
||||||
proc resourceUrl*(self: Service, username: string): (string, string, string) =
|
proc resourceUrl*(self: Service, username: string): (string, string, string) =
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
import NimQml, Tables, json, sequtils, chronicles, strutils, sets, strutils, tables, stint
|
import NimQml, Tables, json, sequtils, chronicles, strutils, sets, stint
|
||||||
|
|
||||||
import httpclient
|
import httpclient
|
||||||
|
|
||||||
import ../../../app/core/[main]
|
import app/core/[main]
|
||||||
import ../../../app/core/tasks/[qt, threadpool]
|
import app/core/tasks/[qt, threadpool]
|
||||||
|
|
||||||
import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, json_serialization, chronicles
|
import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, json_serialization
|
||||||
import json, tables, json_serialization
|
|
||||||
|
import backend/stickers as status_stickers
|
||||||
|
import backend/chat as status_chat
|
||||||
|
import backend/response_type
|
||||||
|
import backend/eth as status_eth
|
||||||
|
import backend/helpers/helpers
|
||||||
|
import backend/backend as status_go_backend
|
||||||
|
import backend/wallet_connect as status_wallet_connect
|
||||||
|
import backend/wallet as status_wallet
|
||||||
|
|
||||||
import ../../../backend/stickers as status_stickers
|
|
||||||
import ../../../backend/chat as status_chat
|
|
||||||
import ../../../backend/response_type
|
|
||||||
import ../../../backend/eth as status_eth
|
|
||||||
import ../../../backend/backend as status_go_backend
|
|
||||||
import ../../../backend/wallet_connect as status_wallet_connect
|
|
||||||
import ../../../backend/wallet as status_wallet
|
|
||||||
import ./dto/stickers
|
import ./dto/stickers
|
||||||
import ../ens/utils as ens_utils
|
import ../ens/utils as ens_utils
|
||||||
import ../token/service as token_service
|
import ../token/service as token_service
|
||||||
|
@ -24,8 +25,8 @@ import ../wallet_account/service as wallet_account_service
|
||||||
import ../transaction/service as transaction_service
|
import ../transaction/service as transaction_service
|
||||||
import ../network/service as network_service
|
import ../network/service as network_service
|
||||||
import ../chat/service as chat_service
|
import ../chat/service as chat_service
|
||||||
import ../../common/types
|
import app_service/common/types
|
||||||
import ../../common/utils as common_utils
|
import app_service/common/utils as common_utils
|
||||||
import ../eth/utils as status_utils
|
import ../eth/utils as status_utils
|
||||||
|
|
||||||
export StickerDto
|
export StickerDto
|
||||||
|
@ -394,8 +395,10 @@ QtObject:
|
||||||
let account = self.walletAccountService.getWalletAccount(0).address
|
let account = self.walletAccountService.getWalletAccount(0).address
|
||||||
let network = self.networkService.getNetworkForStickers()
|
let network = self.networkService.getNetworkForStickers()
|
||||||
|
|
||||||
let balances = status_go_backend.getTokensBalancesForChainIDs(@[network.chainId], @[account], @[token.address]).result
|
let info = getTokenBalanceForAccount(network.chainId, account, token.address)
|
||||||
return ens_utils.hex2Token(balances{account}{token.address}.getStr, token.decimals)
|
if info.isNone:
|
||||||
|
return "0"
|
||||||
|
return ens_utils.hex2Token(info.get().rawBalance.toString(16), token.decimals)
|
||||||
|
|
||||||
# proc prepareTxForBuyingStickers*(self: Service, chainId: int, packId: string, address: string): JsonNode =
|
# proc prepareTxForBuyingStickers*(self: Service, chainId: int, packId: string, address: string): JsonNode =
|
||||||
proc prepareTxForBuyingStickers*(self: Service, chainId: int, packId: string, address: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string,
|
proc prepareTxForBuyingStickers*(self: Service, chainId: int, packId: string, address: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string,
|
||||||
|
|
|
@ -6,14 +6,14 @@ import backend/backend as backend
|
||||||
|
|
||||||
import app_service/service/network/service as network_service
|
import app_service/service/network/service as network_service
|
||||||
import app_service/service/settings/service as settings_service
|
import app_service/service/settings/service as settings_service
|
||||||
import app_service/service/wallet_account/dto/account_dto
|
|
||||||
|
|
||||||
import app/core/eventemitter
|
import app/core/eventemitter
|
||||||
import app/core/tasks/[qt, threadpool]
|
import app/core/tasks/[qt, threadpool]
|
||||||
import app/core/signals/types
|
import app/core/signals/types
|
||||||
import app_service/common/cache
|
import app_service/common/cache
|
||||||
import ../../../constants as main_constants
|
import constants as main_constants
|
||||||
import ./dto, ./service_items
|
import ./dto, ./service_items
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
export dto, service_items
|
export dto, service_items
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import strformat
|
import strformat
|
||||||
|
|
||||||
import app_service/common/types as common_types
|
import app_service/common/types as common_types
|
||||||
#TODO: remove dependency
|
|
||||||
import ../wallet_account/dto/token_dto
|
import backend/helpers/token
|
||||||
|
|
||||||
# This file holds the data types used by models internally
|
# This file holds the data types used by models internally
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
import tables, json, strformat, strutils
|
import tables, json, strformat, strutils
|
||||||
|
|
||||||
import token_dto
|
|
||||||
|
|
||||||
include app_service/common/json_utils
|
include app_service/common/json_utils
|
||||||
|
|
||||||
export token_dto
|
|
||||||
|
|
||||||
const WalletTypeGenerated* = "generated" # refers to accounts generated from the profile keypair
|
const WalletTypeGenerated* = "generated" # refers to accounts generated from the profile keypair
|
||||||
const WalletTypeSeed* = "seed"
|
const WalletTypeSeed* = "seed"
|
||||||
const WalletTypeWatch* = "watch"
|
const WalletTypeWatch* = "watch"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import backend/helpers/token
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# Special signal emitted by main module and handled in wallet account service
|
# Special signal emitted by main module and handled in wallet account service
|
||||||
#################################################
|
#################################################
|
||||||
|
|
|
@ -98,11 +98,6 @@ rpc(getTokens, "wallet"):
|
||||||
rpc(getTokenList, "wallet"):
|
rpc(getTokenList, "wallet"):
|
||||||
discard
|
discard
|
||||||
|
|
||||||
rpc(getTokensBalancesForChainIDs, "wallet"):
|
|
||||||
chainIds: seq[int]
|
|
||||||
accounts: seq[string]
|
|
||||||
tokens: seq[string]
|
|
||||||
|
|
||||||
rpc(getPendingTransactions, "wallet"):
|
rpc(getPendingTransactions, "wallet"):
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import json, strformat, stint, strutils
|
import json, tables, stint, strutils, net, options, chronicles, strformat
|
||||||
|
|
||||||
include app_service/common/json_utils
|
import backend/backend
|
||||||
|
|
||||||
type BalanceDto* = object
|
include app_service/common/json_utils
|
||||||
rawBalance*: Uint256
|
|
||||||
balance*: float64
|
type
|
||||||
address*: string
|
BalanceDto* = object
|
||||||
chainId*: int
|
rawBalance*: Uint256
|
||||||
hasError*: bool
|
balance*: float64
|
||||||
|
address*: string
|
||||||
|
chainId*: int
|
||||||
|
hasError*: bool
|
||||||
|
|
||||||
proc `$`*(self: BalanceDto): string =
|
proc `$`*(self: BalanceDto): string =
|
||||||
result = fmt"""BalanceDto[
|
result = fmt"""BalanceDto[
|
|
@ -0,0 +1,23 @@
|
||||||
|
import json, tables, stint, strutils, net, sequtils, options, chronicles, strformat
|
||||||
|
|
||||||
|
import token
|
||||||
|
import balance
|
||||||
|
import backend/backend
|
||||||
|
|
||||||
|
proc getTokenBalanceForAccount*(chainId: int, accAddress: string, symbol: string): Option[BalanceDto] =
|
||||||
|
try:
|
||||||
|
let response = backend.getWalletToken(@[accAddress])
|
||||||
|
if not response.result.contains(accAddress):
|
||||||
|
error "Missing balance for account ", accAddress
|
||||||
|
return none[BalanceDto]()
|
||||||
|
|
||||||
|
let tokens = parseWalletTokenDtoJson(response.result[accAddress])
|
||||||
|
for token in tokens:
|
||||||
|
if token.symbol == symbol:
|
||||||
|
if chainId in token.balancesPerChain:
|
||||||
|
return some(token.balancesPerChain[chainId])
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
error "Error getting balance ", message=e.msg
|
||||||
|
|
||||||
|
return none[BalanceDto]()
|
|
@ -1,10 +1,8 @@
|
||||||
import tables, json, strformat, stint, strutils
|
import tables, json, strformat, stint, strutils, sequtils
|
||||||
|
|
||||||
import balance_dto
|
import backend/helpers/balance
|
||||||
|
|
||||||
include app_service/common/json_utils
|
include app_service/common/json_utils
|
||||||
|
|
||||||
export balance_dto
|
|
||||||
|
|
||||||
type
|
type
|
||||||
TokenMarketValuesDto* = object
|
TokenMarketValuesDto* = object
|
||||||
|
@ -179,4 +177,11 @@ proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: str
|
||||||
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
|
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
|
proc parseWalletTokenDtoJson*(jsonData: JsonNode): seq[WalletTokenDto] =
|
||||||
|
if jsonData.kind != JArray:
|
||||||
|
raise newException(Exception, "Invalid tokens details json")
|
||||||
|
|
||||||
|
var tokens: seq[WalletTokenDto]
|
||||||
|
tokens = map(jsonData.getElems(), proc(x: JsonNode): WalletTokenDto = x.toWalletTokenDto())
|
||||||
|
|
||||||
|
return tokens
|
Loading…
Reference in New Issue