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/devices/dto/[installation]
|
||||||
import ../../../../app_service/service/settings/dto/[settings]
|
import ../../../../app_service/service/settings/dto/[settings]
|
||||||
import ../../../../app_service/service/saved_address/dto as saved_address_dto
|
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
|
type MessageSignal* = ref object of Signal
|
||||||
bookmarks*: seq[BookmarkDto]
|
bookmarks*: seq[BookmarkDto]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import base
|
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
|
type WakuBackedUpKeypairSignal* = ref object of Signal
|
||||||
keypair*: KeypairDto
|
keypair*: KeypairDto
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import base
|
import base
|
||||||
|
|
||||||
import ../../../../app_service/service/wallet_account/[dto]
|
import ../../../../app_service/service/wallet_account/dto/account_dto
|
||||||
|
|
||||||
type WakuBackedUpWatchOnlyAccountSignal* = ref object of Signal
|
type WakuBackedUpWatchOnlyAccountSignal* = ref object of Signal
|
||||||
account*: WalletAccountDto
|
account*: WalletAccountDto
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import app_service/service/wallet_account/keypair_dto
|
import app_service/service/wallet_account/dto/keypair_dto
|
||||||
|
|
||||||
type
|
type
|
||||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||||
|
|
|
@ -3,7 +3,7 @@ import strutils, sequtils, sugar, chronicles
|
||||||
import ../shared_models/[keypair_item, currency_amount]
|
import ../shared_models/[keypair_item, currency_amount]
|
||||||
import ../../global/global_singleton
|
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
|
export keypair_item
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import NimQml, strformat
|
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
|
import ./currency_amount
|
||||||
|
|
||||||
export wa_dto
|
export wa_dto
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import strformat
|
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_item as balance_item
|
||||||
import ./balance_model as balance_model
|
import ./balance_model as balance_model
|
||||||
import ./currency_amount
|
import ./currency_amount
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import NimQml, strformat
|
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
|
export wa_dto
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Tables, NimQml
|
import Tables, NimQml
|
||||||
|
|
||||||
import ../../../../app_service/service/accounts/dto/generated_accounts
|
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
|
from ../../../../app_service/service/keycard/service import KeycardEvent
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -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 PINLengthForStatusApp
|
||||||
from ../../../../../app_service/service/keycard/service import PUKLengthForStatusApp
|
from ../../../../../app_service/service/keycard/service import PUKLengthForStatusApp
|
||||||
import ../../../../../app_service/common/account_constants
|
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 ../controller
|
||||||
import ../../../shared_models/[keypair_model]
|
import ../../../shared_models/[keypair_model]
|
||||||
import state
|
import state
|
||||||
|
|
|
@ -5,7 +5,7 @@ from web3/conversions import `$`
|
||||||
import ../../../backend/backend as backend
|
import ../../../backend/backend as backend
|
||||||
|
|
||||||
import ../network/service as network_service
|
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/global/global_singleton
|
||||||
|
|
||||||
import ../../../app/core/eventemitter
|
import ../../../app/core/eventemitter
|
||||||
|
|
|
@ -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
|
import json
|
||||||
|
|
||||||
include ../../common/json_utils
|
include app_service/common/json_utils
|
||||||
|
|
||||||
type DerivedAddressDto* = object
|
type DerivedAddressDto* = object
|
||||||
address*: string
|
address*: string
|
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
include ../../common/json_utils
|
include app_service/common/json_utils
|
||||||
|
|
||||||
const ParamKeycardUid = "keycard-uid"
|
const ParamKeycardUid = "keycard-uid"
|
||||||
const ParamKeycardName = "keycard-name"
|
const ParamKeycardName = "keycard-name"
|
|
@ -1,10 +1,10 @@
|
||||||
import tables, json, strformat, strutils, chronicles
|
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 KeypairTypeProfile* = "profile"
|
||||||
const KeypairTypeSeed* = "seed"
|
const KeypairTypeSeed* = "seed"
|
||||||
|
@ -69,4 +69,5 @@ proc `$`*(self: KeypairDto): string =
|
||||||
result &= fmt"""
|
result &= fmt"""
|
||||||
[{i}]:({$self.accounts[i]})
|
[{i}]:({$self.accounts[i]})
|
||||||
"""
|
"""
|
||||||
result &= "]"
|
result &= """
|
||||||
|
]"""
|
|
@ -1,15 +1,10 @@
|
||||||
import tables, json, strformat, sequtils, sugar, strutils
|
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
|
include app_service/common/json_utils
|
||||||
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
|
export balance_dto
|
||||||
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
|
|
||||||
|
|
||||||
const alwaysVisible = {
|
const alwaysVisible = {
|
||||||
1: @["ETH", "SNT", "DAI"],
|
1: @["ETH", "SNT", "DAI"],
|
||||||
|
@ -20,12 +15,6 @@ const alwaysVisible = {
|
||||||
421613: @["ETH", "STT", "DAI"],
|
421613: @["ETH", "STT", "DAI"],
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
type BalanceDto* = object
|
|
||||||
balance*: float64
|
|
||||||
address*: string
|
|
||||||
chainId*: int
|
|
||||||
hasError*: bool
|
|
||||||
|
|
||||||
type
|
type
|
||||||
TokenMarketValuesDto* = object
|
TokenMarketValuesDto* = object
|
||||||
marketCap*: float64
|
marketCap*: float64
|
||||||
|
@ -38,6 +27,18 @@ type
|
||||||
price*: float64
|
price*: float64
|
||||||
hasError*: bool
|
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*(
|
proc newTokenMarketValuesDto*(
|
||||||
marketCap: float64,
|
marketCap: float64,
|
||||||
highDay: float64,
|
highDay: float64,
|
||||||
|
@ -73,89 +74,64 @@ proc toTokenMarketValuesDto*(jsonObj: JsonNode): TokenMarketValuesDto =
|
||||||
discard jsonObj.getProp("price", result.price)
|
discard jsonObj.getProp("price", result.price)
|
||||||
discard jsonObj.getProp("hasError", result.hasError)
|
discard jsonObj.getProp("hasError", result.hasError)
|
||||||
|
|
||||||
type
|
proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
|
||||||
WalletTokenDto* = object
|
result = WalletTokenDto()
|
||||||
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()
|
|
||||||
discard jsonObj.getProp("name", result.name)
|
discard jsonObj.getProp("name", result.name)
|
||||||
discard jsonObj.getProp("address", result.address)
|
discard jsonObj.getProp("symbol", result.symbol)
|
||||||
discard jsonObj.getProp("mixedcase-address", result.mixedcaseAddress)
|
discard jsonObj.getProp("decimals", result.decimals)
|
||||||
discard jsonObj.getProp("key-uid", result.keyUid)
|
discard jsonObj.getProp("color", result.color)
|
||||||
discard jsonObj.getProp("path", result.path)
|
discard jsonObj.getProp("description", result.description)
|
||||||
discard jsonObj.getProp("colorId", result.colorId)
|
discard jsonObj.getProp("assetWebsiteUrl", result.assetWebsiteUrl)
|
||||||
result.colorId = result.colorId.toUpper() # to match `preDefinedWalletAccountColors` on the qml side
|
discard jsonObj.getProp("builtOn", result.builtOn)
|
||||||
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 =
|
var marketValuesPerCurrencyObj: JsonNode
|
||||||
result = fmt"""WalletAccountDto[
|
if(jsonObj.getProp("marketValuesPerCurrency", marketValuesPerCurrencyObj)):
|
||||||
name: {self.name},
|
for currency, marketValuesObj in marketValuesPerCurrencyObj:
|
||||||
address: {self.address},
|
result.marketValuesPerCurrency[currency.toUpperAscii()] = toTokenMarketValuesDto(marketValuesObj)
|
||||||
mixedcaseAddress: {self.mixedcaseAddress},
|
|
||||||
keyUid: {self.keyUid},
|
var balancesPerChainObj: JsonNode
|
||||||
path: {self.path},
|
if(jsonObj.getProp("balancesPerChain", balancesPerChainObj)):
|
||||||
colorId: {self.colorId},
|
for chainId, balanceObj in balancesPerChainObj:
|
||||||
publicKey: {self.publicKey},
|
result.balancesPerChain[parseInt(chainId)] = toBalanceDto(balanceObj)
|
||||||
walletType: {self.walletType},
|
|
||||||
isChat: {self.isChat},
|
proc `$`*(self: TokenMarketValuesDto): string =
|
||||||
emoji: {self.emoji},
|
result = fmt"""TokenMarketValuesDto[
|
||||||
hasBalanceCache: {self.hasBalanceCache},
|
marketCap: {self.marketCap},
|
||||||
hasMarketValuesCache: {self.hasMarketValuesCache},
|
highDay: {self.highDay},
|
||||||
removed: {self.removed}
|
lowDay: {self.lowDay},
|
||||||
operable: {self.operable}
|
changePctHour: {self.changePctHour},
|
||||||
prodPreferredChainIds: {self.prodPreferredChainIds}
|
changePctDay: {self.changePctDay},
|
||||||
testPreferredChainIds: {self.testPreferredChainIds}
|
changePct24hour: {self.changePct24hour},
|
||||||
|
change24hour: {self.change24hour},
|
||||||
|
price: {self.price},
|
||||||
|
hasError: {self.hasError}
|
||||||
]"""
|
]"""
|
||||||
|
|
||||||
proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =
|
proc `$`*(self: WalletTokenDto): string =
|
||||||
return self.balance * currencyPrice
|
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 =
|
proc copyToken*(self: WalletTokenDto): WalletTokenDto =
|
||||||
result = WalletTokenDto()
|
result = WalletTokenDto()
|
||||||
|
@ -177,14 +153,12 @@ proc copyToken*(self: WalletTokenDto): WalletTokenDto =
|
||||||
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
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
proc getTotalBalanceOfSupportedChains*(self: WalletTokenDto): float64 =
|
proc getTotalBalanceOfSupportedChains*(self: WalletTokenDto): float64 =
|
||||||
var sum = 0.0
|
var sum = 0.0
|
||||||
for chainId, balanceDto in self.balancesPerChain:
|
for chainId, balanceDto in self.balancesPerChain:
|
||||||
sum += balanceDto.balance
|
sum += balanceDto.balance
|
||||||
|
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
proc getBalances*(self: WalletTokenDto, chainIds: seq[int]): seq[BalanceDto] =
|
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:
|
for chainId in chainIds:
|
||||||
if self.balancesPerChain.hasKey(chainId):
|
if self.balancesPerChain.hasKey(chainId):
|
||||||
sum += self.balancesPerChain[chainId].balance
|
sum += self.balancesPerChain[chainId].balance
|
||||||
|
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: string): float64 =
|
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:
|
for chainId in chainIds:
|
||||||
if self.balancesPerChain.hasKey(chainId):
|
if self.balancesPerChain.hasKey(chainId):
|
||||||
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
|
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
|
||||||
|
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
proc getVisibleForNetwork*(self: WalletTokenDto, chainIds: seq[int]): bool =
|
proc getVisibleForNetwork*(self: WalletTokenDto, chainIds: seq[int]): bool =
|
||||||
for chainId in chainIds:
|
for chainId in chainIds:
|
||||||
if self.balancesPerChain.hasKey(chainId):
|
if self.balancesPerChain.hasKey(chainId):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc getVisibleForNetworkWithPositiveBalance*(self: WalletTokenDto, chainIds: seq[int]): bool =
|
proc getVisibleForNetworkWithPositiveBalance*(self: WalletTokenDto, chainIds: seq[int]): bool =
|
||||||
for chainId in chainIds:
|
for chainId in chainIds:
|
||||||
if alwaysVisible.hasKey(chainId) and self.symbol in alwaysVisible[chainId]:
|
if alwaysVisible.hasKey(chainId) and self.symbol in alwaysVisible[chainId]:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if self.balancesPerChain.hasKey(chainId) and self.balancesPerChain[chainId].balance > 0:
|
if self.balancesPerChain.hasKey(chainId) and self.balancesPerChain[chainId].balance > 0:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
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 net, strutils, os, times, algorithm, options
|
||||||
import web3/ethtypes
|
import web3/ethtypes
|
||||||
|
|
||||||
import ../settings/service as settings_service
|
import app/global/global_singleton
|
||||||
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 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 dto/keypair_dto as keypair_dto
|
||||||
import ../../../app/core/signals/types
|
import dto/derived_address_dto as derived_address_dto
|
||||||
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, 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:
|
logScope:
|
||||||
topics = "wallet-account-service"
|
topics = "wallet-account-service"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import json, json_serialization, chronicles, strutils
|
import json, json_serialization, chronicles, strutils
|
||||||
import ./core, ../app_service/common/utils
|
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 ./response_type
|
||||||
|
|
||||||
import status_go
|
import status_go
|
||||||
|
|
Loading…
Reference in New Issue