refactor(@desktop/wallet): wallet service dto files reorganized and moved to another folder
This commit is contained in:
parent
a793865835
commit
838aa215e0
|
@ -12,7 +12,7 @@ import ../../../../app_service/service/contacts/dto/[contacts, status_update]
|
|||
import ../../../../app_service/service/devices/dto/[installation]
|
||||
import ../../../../app_service/service/settings/dto/[settings]
|
||||
import ../../../../app_service/service/saved_address/dto as saved_address_dto
|
||||
import ../../../../app_service/service/wallet_account/[keypair_dto]
|
||||
import ../../../../app_service/service/wallet_account/dto/[keypair_dto]
|
||||
|
||||
type MessageSignal* = ref object of Signal
|
||||
bookmarks*: seq[BookmarkDto]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
import base
|
||||
|
||||
import ../../../../app_service/service/wallet_account/[keypair_dto]
|
||||
import ../../../../app_service/service/wallet_account/dto/[keypair_dto]
|
||||
|
||||
type WakuBackedUpKeypairSignal* = ref object of Signal
|
||||
keypair*: KeypairDto
|
||||
|
@ -11,4 +11,4 @@ proc fromEvent*(T: type WakuBackedUpKeypairSignal, event: JsonNode): WakuBackedU
|
|||
|
||||
let e = event["event"]
|
||||
if e.contains("backedUpKeypair"):
|
||||
result.keypair = e["backedUpKeypair"].toKeypairDto()
|
||||
result.keypair = e["backedUpKeypair"].toKeypairDto()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
import base
|
||||
|
||||
import ../../../../app_service/service/wallet_account/[dto]
|
||||
import ../../../../app_service/service/wallet_account/dto/account_dto
|
||||
|
||||
type WakuBackedUpWatchOnlyAccountSignal* = ref object of Signal
|
||||
account*: WalletAccountDto
|
||||
|
@ -11,4 +11,4 @@ proc fromEvent*(T: type WakuBackedUpWatchOnlyAccountSignal, event: JsonNode): Wa
|
|||
|
||||
let e = event["event"]
|
||||
if e.contains("backedUpWatchOnlyAccount"):
|
||||
result.account = e["backedUpWatchOnlyAccount"].toWalletAccountDto()
|
||||
result.account = e["backedUpWatchOnlyAccount"].toWalletAccountDto()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import NimQml
|
||||
import app_service/service/wallet_account/keypair_dto
|
||||
import app_service/service/wallet_account/dto/keypair_dto
|
||||
|
||||
type
|
||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||
|
|
|
@ -3,7 +3,7 @@ import strutils, sequtils, sugar, chronicles
|
|||
import ../shared_models/[keypair_item, currency_amount]
|
||||
import ../../global/global_singleton
|
||||
|
||||
import ../../../app_service/service/wallet_account/[keypair_dto, keycard_dto]
|
||||
import ../../../app_service/service/wallet_account/dto/[keypair_dto]
|
||||
|
||||
export keypair_item
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import NimQml, strformat
|
||||
import app_service/service/wallet_account/dto as wa_dto
|
||||
import app_service/service/wallet_account/dto/account_dto as wa_dto
|
||||
import ./currency_amount
|
||||
|
||||
export wa_dto
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import strformat
|
||||
|
||||
import ../../../app_service/service/wallet_account/dto
|
||||
import ../../../app_service/service/wallet_account/dto/account_dto
|
||||
import ./balance_item as balance_item
|
||||
import ./balance_model as balance_model
|
||||
import ./currency_amount
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import NimQml, strformat
|
||||
import app_service/service/wallet_account/dto as wa_dto
|
||||
import app_service/service/wallet_account/dto/account_dto as wa_dto
|
||||
|
||||
export wa_dto
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Tables, NimQml
|
||||
|
||||
import ../../../../app_service/service/accounts/dto/generated_accounts
|
||||
import ../../../../app_service/service/wallet_account/derived_address
|
||||
import ../../../../app_service/service/wallet_account/dto/derived_address_dto
|
||||
from ../../../../app_service/service/keycard/service import KeycardEvent
|
||||
|
||||
type
|
||||
|
@ -27,7 +27,7 @@ method getSeedPhrase*(self: AccessInterface): string {.base.} =
|
|||
|
||||
method onBackActionClicked*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
||||
method onPrimaryActionClicked*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from ../../../../../app_service/service/keycard/service import KCSFlowType
|
|||
from ../../../../../app_service/service/keycard/service import PINLengthForStatusApp
|
||||
from ../../../../../app_service/service/keycard/service import PUKLengthForStatusApp
|
||||
import ../../../../../app_service/common/account_constants
|
||||
import ../../../../../app_service/service/wallet_account/[keypair_dto, keycard_dto]
|
||||
import ../../../../../app_service/service/wallet_account/dto/[keypair_dto]
|
||||
import ../controller
|
||||
import ../../../shared_models/[keypair_model]
|
||||
import state
|
||||
|
|
|
@ -5,7 +5,7 @@ from web3/conversions import `$`
|
|||
import ../../../backend/backend as backend
|
||||
|
||||
import ../network/service as network_service
|
||||
import ../wallet_account/dto as wallet_account_dto
|
||||
import ../wallet_account/dto/account_dto as wallet_account_dto
|
||||
import ../../../app/global/global_singleton
|
||||
|
||||
import ../../../app/core/eventemitter
|
||||
|
@ -41,7 +41,7 @@ type
|
|||
TokenBalanceHistoryDataArgs* = ref object of Args
|
||||
result*: string
|
||||
|
||||
type
|
||||
type
|
||||
TokenData* = ref object of RootObj
|
||||
addresses*: Table[int, string]
|
||||
decimals*: int
|
||||
|
@ -57,7 +57,7 @@ QtObject:
|
|||
priceCache: TimedCache[float64]
|
||||
|
||||
proc updateCachedTokenPrice(self: Service, crypto: string, fiat: string, price: float64)
|
||||
proc jsonToPricesMap(node: JsonNode): Table[string, Table[string, float64]]
|
||||
proc jsonToPricesMap(node: JsonNode): Table[string, Table[string, float64]]
|
||||
|
||||
proc delete*(self: Service) =
|
||||
self.QObject.delete
|
||||
|
@ -83,7 +83,7 @@ QtObject:
|
|||
|
||||
try:
|
||||
let networks = self.networkService.getNetworks()
|
||||
|
||||
|
||||
for network in networks:
|
||||
let network = network # TODO https://github.com/nim-lang/Nim/issues/16740
|
||||
var found = false
|
||||
|
@ -96,7 +96,7 @@ QtObject:
|
|||
continue
|
||||
let responseTokens = backend.getTokens(network.chainId)
|
||||
let default_tokens = map(
|
||||
responseTokens.result.getElems(),
|
||||
responseTokens.result.getElems(),
|
||||
proc(x: JsonNode): TokenDto = x.toTokenDto(network.enabled, hasIcon=true, isCustom=false)
|
||||
)
|
||||
self.tokens[network.chainId] = default_tokens.filter(
|
||||
|
@ -138,8 +138,8 @@ QtObject:
|
|||
|
||||
proc init*(self: Service) =
|
||||
self.loadData()
|
||||
|
||||
proc getTokenList*(self: Service): seq[TokenDto] =
|
||||
|
||||
proc getTokenList*(self: Service): seq[TokenDto] =
|
||||
return self.tokenList
|
||||
|
||||
proc hasContractAddressesForToken*(self: Service, symbol: string): bool =
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
import tables, json, strformat, sequtils, sugar, 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"
|
||||
const WalletTypeKey* = "key"
|
||||
|
||||
const AccountNonOperable* = "no" # an account is non operable it is not a keycard account and there is no keystore file for it and no keystore file for the address it is derived from
|
||||
const AccountPartiallyOperable* = "partially" # an account is partially operable if it is not a keycard account and there is created keystore file for the address it is derived from
|
||||
const AccountFullyOperable* = "fully" # an account is fully operable if it is not a keycard account and there is a keystore file for it
|
||||
|
||||
type
|
||||
WalletAccountDto* = ref object of RootObj
|
||||
name*: string
|
||||
address*: string
|
||||
mixedcaseAddress*: string
|
||||
keyUid*: string
|
||||
path*: string
|
||||
colorId*: string
|
||||
publicKey*: string
|
||||
walletType*: string
|
||||
isWallet*: bool
|
||||
isChat*: bool
|
||||
tokens*: seq[WalletTokenDto]
|
||||
emoji*: string
|
||||
ens*: string
|
||||
assetsLoading*: bool
|
||||
hasBalanceCache*: bool
|
||||
hasMarketValuesCache*: bool
|
||||
removed*: bool # needs for synchronization
|
||||
operable*: string
|
||||
createdAt*: int
|
||||
position*: int
|
||||
prodPreferredChainIDs*: string
|
||||
testPreferredChainIDs*: string
|
||||
|
||||
proc toWalletAccountDto*(jsonObj: JsonNode): WalletAccountDto =
|
||||
result = WalletAccountDto()
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("mixedcase-address", result.mixedcaseAddress)
|
||||
discard jsonObj.getProp("key-uid", result.keyUid)
|
||||
discard jsonObj.getProp("path", result.path)
|
||||
discard jsonObj.getProp("colorId", result.colorId)
|
||||
result.colorId = result.colorId.toUpper() # to match `preDefinedWalletAccountColors` on the qml side
|
||||
discard jsonObj.getProp("wallet", result.isWallet)
|
||||
discard jsonObj.getProp("chat", result.isChat)
|
||||
discard jsonObj.getProp("public-key", result.publicKey)
|
||||
discard jsonObj.getProp("type", result.walletType)
|
||||
discard jsonObj.getProp("emoji", result.emoji)
|
||||
discard jsonObj.getProp("removed", result.removed)
|
||||
discard jsonObj.getProp("operable", result.operable)
|
||||
discard jsonObj.getProp("createdAt", result.createdAt)
|
||||
discard jsonObj.getProp("position", result.position)
|
||||
discard jsonObj.getProp("prodPreferredChainIds", result.prodPreferredChainIds)
|
||||
discard jsonObj.getProp("testPreferredChainIds", result.testPreferredChainIds)
|
||||
result.assetsLoading = true
|
||||
result.hasBalanceCache = false
|
||||
result.hasMarketValuesCache = false
|
||||
|
||||
proc `$`*(self: WalletAccountDto): string =
|
||||
result = fmt"""WalletAccountDto[
|
||||
name: {self.name},
|
||||
address: {self.address},
|
||||
mixedcaseAddress: {self.mixedcaseAddress},
|
||||
keyUid: {self.keyUid},
|
||||
path: {self.path},
|
||||
colorId: {self.colorId},
|
||||
publicKey: {self.publicKey},
|
||||
walletType: {self.walletType},
|
||||
isChat: {self.isChat},
|
||||
emoji: {self.emoji},
|
||||
hasBalanceCache: {self.hasBalanceCache},
|
||||
hasMarketValuesCache: {self.hasMarketValuesCache},
|
||||
removed: {self.removed}
|
||||
operable: {self.operable}
|
||||
prodPreferredChainIds: {self.prodPreferredChainIds}
|
||||
testPreferredChainIds: {self.testPreferredChainIds}
|
||||
]"""
|
||||
|
||||
proc getCurrencyBalance*(self: WalletAccountDto, chainIds: seq[int], currency: string): float64 =
|
||||
return self.tokens.map(t => t.getCurrencyBalance(chainIds, currency)).foldl(a + b, 0.0)
|
|
@ -0,0 +1,27 @@
|
|||
import json, strformat, strutils
|
||||
|
||||
include app_service/common/json_utils
|
||||
|
||||
type BalanceDto* = object
|
||||
balance*: float64
|
||||
address*: string
|
||||
chainId*: int
|
||||
hasError*: bool
|
||||
|
||||
proc `$`*(self: BalanceDto): string =
|
||||
result = fmt"""BalanceDto[
|
||||
address: {self.address},
|
||||
balance: {self.balance},
|
||||
chainId: {self.chainId},
|
||||
hasError: {self.hasError}
|
||||
]"""
|
||||
|
||||
proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =
|
||||
return self.balance * currencyPrice
|
||||
|
||||
proc toBalanceDto*(jsonObj: JsonNode): BalanceDto =
|
||||
result = BalanceDto()
|
||||
result.balance = jsonObj{"balance"}.getStr.parseFloat()
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("chainId", result.chainId)
|
||||
discard jsonObj.getProp("hasError", result.hasError)
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
|
||||
include ../../common/json_utils
|
||||
include app_service/common/json_utils
|
||||
|
||||
type DerivedAddressDto* = object
|
||||
address*: string
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
|
||||
include ../../common/json_utils
|
||||
include app_service/common/json_utils
|
||||
|
||||
const ParamKeycardUid = "keycard-uid"
|
||||
const ParamKeycardName = "keycard-name"
|
||||
|
@ -23,7 +23,7 @@ const KeycardActionNameChanged* = "NAME_CHANGED"
|
|||
type KeycardDto* = object
|
||||
keycardUid*: string
|
||||
keycardName*: string
|
||||
keycardLocked*: bool
|
||||
keycardLocked*: bool
|
||||
accountsAddresses*: seq[string]
|
||||
keyUid*: string
|
||||
|
||||
|
@ -38,7 +38,7 @@ proc toKeycardDto*(jsonObj: JsonNode): KeycardDto =
|
|||
discard jsonObj.getProp(ParamKeycardName, result.keycardName)
|
||||
discard jsonObj.getProp(ParamKeycardLocked, result.keycardLocked)
|
||||
discard jsonObj.getProp(ParamKeyUid, result.keyUid)
|
||||
|
||||
|
||||
var jArr: JsonNode
|
||||
if(jsonObj.getProp(ParamAccountAddresses, jArr) and jArr.kind == JArray):
|
||||
for addrObj in jArr:
|
||||
|
@ -48,7 +48,7 @@ proc toKeycardActionDto*(jsonObj: JsonNode): KeycardActionDto =
|
|||
result = KeycardActionDto()
|
||||
discard jsonObj.getProp(ParamAction, result.action)
|
||||
discard jsonObj.getProp(ParamOldKeycardUid, result.oldKeycardUid)
|
||||
|
||||
|
||||
var keycardObj: JsonNode
|
||||
if(jsonObj.getProp("keycard", keycardObj)):
|
||||
result.keycard = toKeycardDto(keycardObj)
|
|
@ -1,10 +1,10 @@
|
|||
import tables, json, strformat, strutils, chronicles
|
||||
|
||||
import dto, keycard_dto
|
||||
import account_dto, keycard_dto
|
||||
|
||||
include ../../common/json_utils
|
||||
include app_service/common/json_utils
|
||||
|
||||
export dto, keycard_dto
|
||||
export account_dto, keycard_dto
|
||||
|
||||
const KeypairTypeProfile* = "profile"
|
||||
const KeypairTypeSeed* = "seed"
|
||||
|
@ -69,4 +69,5 @@ proc `$`*(self: KeypairDto): string =
|
|||
result &= fmt"""
|
||||
[{i}]:({$self.accounts[i]})
|
||||
"""
|
||||
result &= "]"
|
||||
result &= """
|
||||
]"""
|
|
@ -1,15 +1,10 @@
|
|||
import tables, json, strformat, sequtils, sugar, strutils
|
||||
|
||||
include ../../common/json_utils
|
||||
import balance_dto
|
||||
|
||||
const WalletTypeGenerated* = "generated" # refers to accounts generated from the profile keypair
|
||||
const WalletTypeSeed* = "seed"
|
||||
const WalletTypeWatch* = "watch"
|
||||
const WalletTypeKey* = "key"
|
||||
include app_service/common/json_utils
|
||||
|
||||
const AccountNonOperable* = "no" # an account is non operable it is not a keycard account and there is no keystore file for it and no keystore file for the address it is derived from
|
||||
const AccountPartiallyOperable* = "partially" # an account is partially operable if it is not a keycard account and there is created keystore file for the address it is derived from
|
||||
const AccountFullyOperable* = "fully" # an account is fully operable if it is not a keycard account and there is a keystore file for it
|
||||
export balance_dto
|
||||
|
||||
const alwaysVisible = {
|
||||
1: @["ETH", "SNT", "DAI"],
|
||||
|
@ -20,12 +15,6 @@ const alwaysVisible = {
|
|||
421613: @["ETH", "STT", "DAI"],
|
||||
}.toTable
|
||||
|
||||
type BalanceDto* = object
|
||||
balance*: float64
|
||||
address*: string
|
||||
chainId*: int
|
||||
hasError*: bool
|
||||
|
||||
type
|
||||
TokenMarketValuesDto* = object
|
||||
marketCap*: float64
|
||||
|
@ -38,6 +27,18 @@ type
|
|||
price*: float64
|
||||
hasError*: bool
|
||||
|
||||
type
|
||||
WalletTokenDto* = object
|
||||
name*: string
|
||||
symbol*: string
|
||||
decimals*: int
|
||||
color*: string
|
||||
balancesPerChain*: Table[int, BalanceDto]
|
||||
description*: string
|
||||
assetWebsiteUrl*: string
|
||||
builtOn*: string
|
||||
marketValuesPerCurrency*: Table[string, TokenMarketValuesDto]
|
||||
|
||||
proc newTokenMarketValuesDto*(
|
||||
marketCap: float64,
|
||||
highDay: float64,
|
||||
|
@ -73,89 +74,64 @@ proc toTokenMarketValuesDto*(jsonObj: JsonNode): TokenMarketValuesDto =
|
|||
discard jsonObj.getProp("price", result.price)
|
||||
discard jsonObj.getProp("hasError", result.hasError)
|
||||
|
||||
type
|
||||
WalletTokenDto* = object
|
||||
name*: string
|
||||
symbol*: string
|
||||
decimals*: int
|
||||
color*: string
|
||||
balancesPerChain*: Table[int, BalanceDto]
|
||||
description*: string
|
||||
assetWebsiteUrl*: string
|
||||
builtOn*: string
|
||||
marketValuesPerCurrency*: Table[string, TokenMarketValuesDto]
|
||||
|
||||
type
|
||||
WalletAccountDto* = ref object of RootObj
|
||||
name*: string
|
||||
address*: string
|
||||
mixedcaseAddress*: string
|
||||
keyUid*: string
|
||||
path*: string
|
||||
colorId*: string
|
||||
publicKey*: string
|
||||
walletType*: string
|
||||
isWallet*: bool
|
||||
isChat*: bool
|
||||
tokens*: seq[WalletTokenDto]
|
||||
emoji*: string
|
||||
ens*: string
|
||||
assetsLoading*: bool
|
||||
hasBalanceCache*: bool
|
||||
hasMarketValuesCache*: bool
|
||||
removed*: bool # needs for synchronization
|
||||
operable*: string
|
||||
createdAt*: int
|
||||
position*: int
|
||||
prodPreferredChainIDs*: string
|
||||
testPreferredChainIDs*: string
|
||||
|
||||
proc toWalletAccountDto*(jsonObj: JsonNode): WalletAccountDto =
|
||||
result = WalletAccountDto()
|
||||
proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
|
||||
result = WalletTokenDto()
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("mixedcase-address", result.mixedcaseAddress)
|
||||
discard jsonObj.getProp("key-uid", result.keyUid)
|
||||
discard jsonObj.getProp("path", result.path)
|
||||
discard jsonObj.getProp("colorId", result.colorId)
|
||||
result.colorId = result.colorId.toUpper() # to match `preDefinedWalletAccountColors` on the qml side
|
||||
discard jsonObj.getProp("wallet", result.isWallet)
|
||||
discard jsonObj.getProp("chat", result.isChat)
|
||||
discard jsonObj.getProp("public-key", result.publicKey)
|
||||
discard jsonObj.getProp("type", result.walletType)
|
||||
discard jsonObj.getProp("emoji", result.emoji)
|
||||
discard jsonObj.getProp("removed", result.removed)
|
||||
discard jsonObj.getProp("operable", result.operable)
|
||||
discard jsonObj.getProp("createdAt", result.createdAt)
|
||||
discard jsonObj.getProp("position", result.position)
|
||||
discard jsonObj.getProp("prodPreferredChainIds", result.prodPreferredChainIds)
|
||||
discard jsonObj.getProp("testPreferredChainIds", result.testPreferredChainIds)
|
||||
result.assetsLoading = true
|
||||
result.hasBalanceCache = false
|
||||
result.hasMarketValuesCache = false
|
||||
discard jsonObj.getProp("symbol", result.symbol)
|
||||
discard jsonObj.getProp("decimals", result.decimals)
|
||||
discard jsonObj.getProp("color", result.color)
|
||||
discard jsonObj.getProp("description", result.description)
|
||||
discard jsonObj.getProp("assetWebsiteUrl", result.assetWebsiteUrl)
|
||||
discard jsonObj.getProp("builtOn", result.builtOn)
|
||||
|
||||
proc `$`*(self: WalletAccountDto): string =
|
||||
result = fmt"""WalletAccountDto[
|
||||
name: {self.name},
|
||||
address: {self.address},
|
||||
mixedcaseAddress: {self.mixedcaseAddress},
|
||||
keyUid: {self.keyUid},
|
||||
path: {self.path},
|
||||
colorId: {self.colorId},
|
||||
publicKey: {self.publicKey},
|
||||
walletType: {self.walletType},
|
||||
isChat: {self.isChat},
|
||||
emoji: {self.emoji},
|
||||
hasBalanceCache: {self.hasBalanceCache},
|
||||
hasMarketValuesCache: {self.hasMarketValuesCache},
|
||||
removed: {self.removed}
|
||||
operable: {self.operable}
|
||||
prodPreferredChainIds: {self.prodPreferredChainIds}
|
||||
testPreferredChainIds: {self.testPreferredChainIds}
|
||||
var marketValuesPerCurrencyObj: JsonNode
|
||||
if(jsonObj.getProp("marketValuesPerCurrency", marketValuesPerCurrencyObj)):
|
||||
for currency, marketValuesObj in marketValuesPerCurrencyObj:
|
||||
result.marketValuesPerCurrency[currency.toUpperAscii()] = toTokenMarketValuesDto(marketValuesObj)
|
||||
|
||||
var balancesPerChainObj: JsonNode
|
||||
if(jsonObj.getProp("balancesPerChain", balancesPerChainObj)):
|
||||
for chainId, balanceObj in balancesPerChainObj:
|
||||
result.balancesPerChain[parseInt(chainId)] = toBalanceDto(balanceObj)
|
||||
|
||||
proc `$`*(self: TokenMarketValuesDto): string =
|
||||
result = fmt"""TokenMarketValuesDto[
|
||||
marketCap: {self.marketCap},
|
||||
highDay: {self.highDay},
|
||||
lowDay: {self.lowDay},
|
||||
changePctHour: {self.changePctHour},
|
||||
changePctDay: {self.changePctDay},
|
||||
changePct24hour: {self.changePct24hour},
|
||||
change24hour: {self.change24hour},
|
||||
price: {self.price},
|
||||
hasError: {self.hasError}
|
||||
]"""
|
||||
|
||||
proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =
|
||||
return self.balance * currencyPrice
|
||||
proc `$`*(self: WalletTokenDto): string =
|
||||
result = fmt"""WalletTokenDto[
|
||||
name: {self.name},
|
||||
symbol: {self.symbol},
|
||||
decimals: {self.decimals},
|
||||
color: {self.color},
|
||||
description: {self.description},
|
||||
assetWebsiteUrl: {self.assetWebsiteUrl},
|
||||
builtOn: {self.builtOn},
|
||||
balancesPerChain:
|
||||
"""
|
||||
for chain, balance in self.balancesPerChain:
|
||||
result &= fmt"""
|
||||
[{chain}]:({$balance})
|
||||
"""
|
||||
|
||||
result &= fmt"""
|
||||
marketValuesPerCurrency:
|
||||
"""
|
||||
for currency, values in self.marketValuesPerCurrency:
|
||||
result &= fmt"""
|
||||
[{currency}]:({$values})
|
||||
"""
|
||||
result &= """
|
||||
]"""
|
||||
|
||||
proc copyToken*(self: WalletTokenDto): WalletTokenDto =
|
||||
result = WalletTokenDto()
|
||||
|
@ -177,14 +153,12 @@ proc copyToken*(self: WalletTokenDto): WalletTokenDto =
|
|||
proc getAddress*(self: WalletTokenDto): string =
|
||||
for balance in self.balancesPerChain.values:
|
||||
return balance.address
|
||||
|
||||
return ""
|
||||
|
||||
proc getTotalBalanceOfSupportedChains*(self: WalletTokenDto): float64 =
|
||||
var sum = 0.0
|
||||
for chainId, balanceDto in self.balancesPerChain:
|
||||
sum += balanceDto.balance
|
||||
|
||||
return sum
|
||||
|
||||
proc getBalances*(self: WalletTokenDto, chainIds: seq[int]): seq[BalanceDto] =
|
||||
|
@ -197,7 +171,6 @@ proc getBalance*(self: WalletTokenDto, chainIds: seq[int]): float64 =
|
|||
for chainId in chainIds:
|
||||
if self.balancesPerChain.hasKey(chainId):
|
||||
sum += self.balancesPerChain[chainId].balance
|
||||
|
||||
return sum
|
||||
|
||||
proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: string): float64 =
|
||||
|
@ -206,52 +179,20 @@ proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: str
|
|||
for chainId in chainIds:
|
||||
if self.balancesPerChain.hasKey(chainId):
|
||||
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
|
||||
|
||||
return sum
|
||||
|
||||
proc getVisibleForNetwork*(self: WalletTokenDto, chainIds: seq[int]): bool =
|
||||
for chainId in chainIds:
|
||||
if self.balancesPerChain.hasKey(chainId):
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
proc getVisibleForNetworkWithPositiveBalance*(self: WalletTokenDto, chainIds: seq[int]): bool =
|
||||
for chainId in chainIds:
|
||||
if alwaysVisible.hasKey(chainId) and self.symbol in alwaysVisible[chainId]:
|
||||
return true
|
||||
|
||||
if self.balancesPerChain.hasKey(chainId) and self.balancesPerChain[chainId].balance > 0:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
proc getCurrencyBalance*(self: WalletAccountDto, chainIds: seq[int], currency: string): float64 =
|
||||
return self.tokens.map(t => t.getCurrencyBalance(chainIds, currency)).foldl(a + b, 0.0)
|
||||
|
||||
proc toBalanceDto*(jsonObj: JsonNode): BalanceDto =
|
||||
result = BalanceDto()
|
||||
result.balance = jsonObj{"balance"}.getStr.parseFloat()
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("chainId", result.chainId)
|
||||
discard jsonObj.getProp("hasError", result.hasError)
|
||||
|
||||
proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
|
||||
result = WalletTokenDto()
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("symbol", result.symbol)
|
||||
discard jsonObj.getProp("decimals", result.decimals)
|
||||
discard jsonObj.getProp("color", result.color)
|
||||
discard jsonObj.getProp("description", result.description)
|
||||
discard jsonObj.getProp("assetWebsiteUrl", result.assetWebsiteUrl)
|
||||
discard jsonObj.getProp("builtOn", result.builtOn)
|
||||
|
||||
var marketValuesPerCurrencyObj: JsonNode
|
||||
if(jsonObj.getProp("marketValuesPerCurrency", marketValuesPerCurrencyObj)):
|
||||
for currency, marketValuesObj in marketValuesPerCurrencyObj:
|
||||
result.marketValuesPerCurrency[currency.toUpperAscii()] = marketValuesObj.toTokenMarketValuesDto()
|
||||
|
||||
var balancesPerChainObj: JsonNode
|
||||
if(jsonObj.getProp("balancesPerChain", balancesPerChainObj)):
|
||||
for chainId, balanceObj in balancesPerChainObj:
|
||||
result.balancesPerChain[parseInt(chainId)] = toBalanceDto(balanceObj)
|
|
@ -2,26 +2,28 @@ import NimQml, Tables, json, sequtils, sugar, chronicles, strformat, stint, http
|
|||
import net, strutils, os, times, algorithm, options
|
||||
import web3/ethtypes
|
||||
|
||||
import ../settings/service as settings_service
|
||||
import ../accounts/service as accounts_service
|
||||
import ../token/service as token_service
|
||||
import ../network/service as network_service
|
||||
import ../currency/service as currency_service
|
||||
import ../../common/[utils]
|
||||
import ../../../app/global/global_singleton
|
||||
import app/global/global_singleton
|
||||
|
||||
import keypair_dto, derived_address, keycard_dto
|
||||
import app_service/service/settings/service as settings_service
|
||||
import app_service/service/accounts/service as accounts_service
|
||||
import app_service/service/token/service as token_service
|
||||
import app_service/service/network/service as network_service
|
||||
import app_service/service/currency/service as currency_service
|
||||
import app_service/common/[utils]
|
||||
|
||||
import ../../../app/core/eventemitter
|
||||
import ../../../app/core/signals/types
|
||||
import ../../../app/core/tasks/[qt, threadpool]
|
||||
import ../../../backend/accounts as status_go_accounts
|
||||
import ../../../backend/backend as backend
|
||||
import ../../../backend/eth as status_go_eth
|
||||
import ../../../backend/transactions as status_go_transactions
|
||||
import ../../../constants as main_constants
|
||||
import dto/keypair_dto as keypair_dto
|
||||
import dto/derived_address_dto as derived_address_dto
|
||||
|
||||
export keypair_dto, derived_address, keycard_dto
|
||||
import app/core/eventemitter
|
||||
import app/core/signals/types
|
||||
import app/core/tasks/[qt, threadpool]
|
||||
import backend/accounts as status_go_accounts
|
||||
import backend/backend as backend
|
||||
import backend/eth as status_go_eth
|
||||
import backend/transactions as status_go_transactions
|
||||
import constants as main_constants
|
||||
|
||||
export keypair_dto, derived_address_dto
|
||||
|
||||
logScope:
|
||||
topics = "wallet-account-service"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json, json_serialization, chronicles, strutils
|
||||
import ./core, ../app_service/common/utils
|
||||
import ../app_service/service/wallet_account/dto
|
||||
import ../app_service/service/wallet_account/dto/account_dto
|
||||
import ./response_type
|
||||
|
||||
import status_go
|
||||
|
|
Loading…
Reference in New Issue