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:
Stefan 2023-11-29 20:23:04 +02:00 committed by Stefan Dunca
parent d3a0c95979
commit a4835a25ce
23 changed files with 160 additions and 101 deletions

View File

@ -1,9 +1,11 @@
import sugar, sequtils
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/token/service as token_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/network/service as network_service
import app_service/service/token/service as token_service
import app_service/service/currency/service as currency_service
import backend/helpers/token
type
Controller* = ref object of RootObj

View File

@ -1,17 +1,19 @@
import NimQml, Tables, sequtils, strutils, sugar
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/token/service as token_service
import ../../../../../app_service/service/currency/service as currency_service
import ../../../shared/wallet_utils
import ../../../shared_models/token_model as token_model
import app/global/global_singleton
import app/core/eventemitter
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
import app_service/service/token/service as token_service
import app_service/service/currency/service as currency_service
import app/modules/shared/wallet_utils
import app/modules/shared_models/token_model as token_model
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import backend/helpers/token
export io_interface
type

View File

@ -10,6 +10,8 @@ import app_service/common/types
import app_service/service/profile/dto/profile_showcase_preferences
import backend/helpers/token
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface

View File

@ -5,11 +5,13 @@ import profile_preferences_base_item
import app_service/service/wallet_account/dto/account_dto
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/utils
import backend/helpers/token
type
ProfileShowcaseAssetItem* = ref object of ProfileShowcaseBaseItem
symbol*: string

View File

@ -15,6 +15,8 @@ import app_service/service/settings/service
import backend/collectibles as backend_collectibles
import backend/helpers/token
export io_interface
type

View File

@ -1,9 +1,11 @@
import sugar, sequtils
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/token/service as token_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/network/service as network_service
import app_service/service/token/service as token_service
import app_service/service/currency/service as currency_service
import backend/helpers/token
type
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] =
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)
proc getChainIds*(self: Controller): seq[int] =

View File

@ -1,20 +1,22 @@
import NimQml, sequtils, sugar
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/token/service as token_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/network/service as network_service
import ../../../../../app_service/service/network_connection/service as network_connection
import ../../../../../app_service/service/node/service as node_service
import ../../../shared/wallet_utils
import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_item as token_item
import app/global/global_singleton
import app/core/eventemitter
import app_service/service/token/service as token_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/network/service as network_service
import app_service/service/network_connection/service as network_connection
import app_service/service/node/service as node_service
import app/modules/shared/wallet_utils
import app/modules/shared_models/token_model as token_model
import app/modules/shared_models/token_item as token_item
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import backend/helpers/token
export io_interface
type

View File

@ -1,13 +1,15 @@
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_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/currency/service as currency_service
import backend/helpers/token
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.Service
currencyService: currency_service.Service
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.Service,
@ -27,7 +29,7 @@ proc init*(self: Controller) =
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
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)
proc getCurrentCurrency*(self: Controller): string =

View File

@ -1,16 +1,18 @@
import NimQml, sequtils, sugar
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/currency/service as currency_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../shared/wallet_utils
import ../../../shared_models/currency_amount
import app/global/global_singleton
import app/core/eventemitter
import app_service/service/currency/service as currency_service
import app_service/service/wallet_account/service as wallet_account_service
import app/modules/shared/wallet_utils
import app/modules/shared_models/currency_amount
import ./item
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import backend/helpers/token
export io_interface
type

View File

@ -15,6 +15,8 @@ import app/modules/shared_models/currency_amount
import app/core/signals/types
import app/core/eventemitter
import backend/helpers/token
logScope:
topics = "wallet-send-controller"

View File

@ -2,13 +2,16 @@ import tables, sequtils, stint, sugar
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 ../../../app_service/service/currency/dto as currency_dto
import backend/helpers/token
import app_service/service/currency/dto as currency_dto
import ../main/wallet_section/accounts/item as wallet_accounts_item
import ../main/wallet_section/assets/item as wallet_assets_item
import ../main/wallet_section/send/account_item as wallet_send_account_item
import backend/helpers/balance
proc currencyAmountToItem*(amount: float64, format: CurrencyFormatDto) : CurrencyAmount =
return newCurrencyAmount(
amount,

View File

@ -1,7 +1,9 @@
import NimQml, tables
import app/core/eventemitter
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
type FlowType* {.pure.} = enum

View File

@ -3,21 +3,23 @@ import NimQml, tables, strutils, sequtils, sugar, chronicles
import io_interface
import view, controller
import internal/[state, state_factory]
import ../../shared/[keypairs, wallet_utils]
import ../../shared_models/[keypair_model, keypair_item, currency_amount]
import ../../../global/app_translatable_constants as atc
import ../../../global/global_singleton
import ../../../core/eventemitter
import app/modules/shared/[keypairs, wallet_utils]
import app/modules/shared_models/[keypair_model, keypair_item, currency_amount]
import app/global/app_translatable_constants as atc
import app/global/global_singleton
import app/core/eventemitter
import ../../../../app_service/common/utils
import ../../../../app_service/service/keycard/constants
import ../../../../app_service/service/keycard/service as keycard_service
import ../../../../app_service/service/settings/service as settings_service
import ../../../../app_service/service/network/service as network_service
import ../../../../app_service/service/privacy/service as privacy_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/keychain/service as keychain_service
import app_service/common/utils
import app_service/service/keycard/constants
import app_service/service/keycard/service as keycard_service
import app_service/service/settings/service as settings_service
import app_service/service/network/service as network_service
import app_service/service/privacy/service as privacy_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/keychain/service as keychain_service
import backend/helpers/token
export io_interface

View File

@ -8,8 +8,10 @@ import app/global/global_singleton
import backend/ens as status_ens
import backend/backend as status_go_backend
import backend/wallet as status_wallet
import backend/helpers/helpers
import app_service/common/conversion as common_conversion
import utils as ens_utils
import app_service/service/settings/service as settings_service
import app_service/service/wallet_account/service as wallet_account_service
@ -311,8 +313,11 @@ QtObject:
proc getSNTBalance*(self: Service): string =
let token = self.getStatusToken()
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) =
try:

View File

@ -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 ../../../app/core/[main]
import ../../../app/core/tasks/[qt, threadpool]
import app/core/[main]
import app/core/tasks/[qt, threadpool]
import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, json_serialization, chronicles
import json, tables, json_serialization
import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, 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 ../ens/utils as ens_utils
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 ../network/service as network_service
import ../chat/service as chat_service
import ../../common/types
import ../../common/utils as common_utils
import app_service/common/types
import app_service/common/utils as common_utils
import ../eth/utils as status_utils
export StickerDto
@ -394,8 +395,10 @@ QtObject:
let account = self.walletAccountService.getWalletAccount(0).address
let network = self.networkService.getNetworkForStickers()
let balances = status_go_backend.getTokensBalancesForChainIDs(@[network.chainId], @[account], @[token.address]).result
return ens_utils.hex2Token(balances{account}{token.address}.getStr, token.decimals)
let info = getTokenBalanceForAccount(network.chainId, account, token.address)
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, gas: string, gasPrice: string, maxPriorityFeePerGas: string,
@ -490,4 +493,4 @@ QtObject:
result.txHash = transactionHash
except Exception as e:
result.error = e.msg
error "error occurred", procName="sendBuyingStickersTxWithSignatureAndWatch", msg = result.error
error "error occurred", procName="sendBuyingStickersTxWithSignatureAndWatch", msg = result.error

View File

@ -6,14 +6,14 @@ import backend/backend as backend
import app_service/service/network/service as network_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/tasks/[qt, threadpool]
import app/core/signals/types
import app_service/common/cache
import ../../../constants as main_constants
import constants as main_constants
import ./dto, ./service_items
import backend/helpers/token
export dto, service_items

View File

@ -1,8 +1,8 @@
import strformat
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

View File

@ -1,11 +1,7 @@
import tables, json, strformat, strutils
import token_dto
include app_service/common/json_utils
export token_dto
const WalletTypeGenerated* = "generated" # refers to accounts generated from the profile keypair
const WalletTypeSeed* = "seed"
const WalletTypeWatch* = "watch"

View File

@ -1,3 +1,5 @@
import backend/helpers/token
#################################################
# Special signal emitted by main module and handled in wallet account service
#################################################

View File

@ -98,11 +98,6 @@ rpc(getTokens, "wallet"):
rpc(getTokenList, "wallet"):
discard
rpc(getTokensBalancesForChainIDs, "wallet"):
chainIds: seq[int]
accounts: seq[string]
tokens: seq[string]
rpc(getPendingTransactions, "wallet"):
discard

View File

@ -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
rawBalance*: Uint256
balance*: float64
address*: string
chainId*: int
hasError*: bool
include app_service/common/json_utils
type
BalanceDto* = object
rawBalance*: Uint256
balance*: float64
address*: string
chainId*: int
hasError*: bool
proc `$`*(self: BalanceDto): string =
result = fmt"""BalanceDto[

View File

@ -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]()

View File

@ -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
export balance_dto
include app_service/common/json_utils
type
TokenMarketValuesDto* = object
@ -179,4 +177,11 @@ proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: str
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
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