chore(@desktop/wallet): wallet improvements

This commit is contained in:
Sale Djenic 2023-04-27 12:32:44 +02:00 committed by saledjenic
parent 3115b9d19e
commit 20102ebe3b
26 changed files with 321 additions and 360 deletions

View File

@ -6,10 +6,8 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
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 ../../../shared_models/token_model as token_model import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_utils
import ../../wallet_section/accounts/utils
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
@ -68,7 +66,7 @@ proc switchAccount*(self: Module, accountIndex: int) =
let currencyFormat = self.controller.getCurrencyFormat(currency) let currencyFormat = self.controller.getCurrencyFormat(currency)
let accountItem = walletAccountToItem( let accountItem = walletAccountToWalletAccountsItem(
walletAccount, walletAccount,
enabledChainIds, enabledChainIds,
currency, currency,

View File

@ -121,19 +121,19 @@ QtObject:
return self.assets.hasGas(chainId, nativeGasSymbol, requiredGas) return self.assets.hasGas(chainId, nativeGasSymbol, requiredGas)
proc setData*(self: View, item: account_item.Item) = proc setData*(self: View, item: account_item.Item) =
self.name = item.getName() self.name = item.name()
self.nameChanged() self.nameChanged()
self.address = item.getAddress() self.address = item.address()
self.addressChanged() self.addressChanged()
self.path = item.getPath() self.path = item.path()
self.pathChanged() self.pathChanged()
self.color = item.getColor() self.color = item.color()
self.colorChanged() self.colorChanged()
self.walletType = item.getWalletType() self.walletType = item.walletType()
self.walletTypeChanged() self.walletTypeChanged()
self.currencyBalance = item.getCurrencyBalance() self.currencyBalance = item.currencyBalance()
self.currencyBalanceChanged() self.currencyBalanceChanged()
self.emoji = item.getEmoji() self.emoji = item.emoji()
self.emojiChanged() self.emojiChanged()
proc isAddressCurrentAccount*(self: View, address: string): bool = proc isAddressCurrentAccount*(self: View, address: string): bool =

View File

@ -1,16 +1,12 @@
import strformat import strformat
import ../../../../shared_models/wallet_account_item
import ./related_accounts_model as related_accounts_model import ./related_accounts_model as related_accounts_model
export wallet_account_item
type type
Item* = object Item* = ref object of WalletAccountItem
name*: string
address: string
color*: string
emoji*: string
walletType: string
path: string
relatedAccounts: related_accounts_model.Model relatedAccounts: related_accounts_model.Model
keyUid: string
proc initItem*( proc initItem*(
name: string = "", name: string = "",
@ -22,47 +18,21 @@ proc initItem*(
relatedAccounts: related_accounts_model.Model = nil, relatedAccounts: related_accounts_model.Model = nil,
keyUid: string = "", keyUid: string = "",
): Item = ): Item =
result.name = name result = Item()
result.address = address result.WalletAccountItem.setup(name,
result.path = path address,
result.color = color color,
result.walletType = walletType emoji,
result.emoji = emoji walletType,
path,
keyUid)
result.relatedAccounts = relatedAccounts result.relatedAccounts = relatedAccounts
result.keyUid = keyUid
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""WalletAccountItem( result = "ProfileSection-Accounts-Item("
name: {self.name}, result = result & $self.WalletAccountItem
address: {self.address}, result = result & "\nrelatedAccounts: " & $self.relatedAccounts
path: {self.path}, result = result & ")"
color: {self.color},
walletType: {self.walletType},
emoji: {self.emoji},
relatedAccounts: {self.relatedAccounts}
keyUid: {self.keyUid},
]"""
proc getName*(self: Item): string = proc relatedAccounts*(self: Item): related_accounts_model.Model =
return self.name return self.relatedAccounts
proc getAddress*(self: Item): string =
return self.address
proc getPath*(self: Item): string =
return self.path
proc getEmoji*(self: Item): string =
return self.emoji
proc getColor*(self: Item): string =
return self.color
proc getWalletType*(self: Item): string =
return self.walletType
proc getRelatedAccounts*(self: Item): related_accounts_model.Model =
return self.relatedAccounts
proc getKeyUid*(self: Item): string =
return self.keyUid

View File

@ -66,7 +66,7 @@ QtObject:
proc onUpdatedAccount*(self: Model, account: Item) = proc onUpdatedAccount*(self: Model, account: Item) =
var i = 0 var i = 0
for item in self.items.mitems: for item in self.items.mitems:
if account.getAddress() == item.getAddress(): if account.address == item.address:
item.name = account.name item.name = account.name
item.color = account.color item.color = account.color
item.emoji = account.emoji item.emoji = account.emoji
@ -89,18 +89,18 @@ QtObject:
case enumRole: case enumRole:
of ModelRole.Name: of ModelRole.Name:
result = newQVariant(item.getName()) result = newQVariant(item.name())
of ModelRole.Address: of ModelRole.Address:
result = newQVariant(item.getAddress()) result = newQVariant(item.address())
of ModelRole.Path: of ModelRole.Path:
result = newQVariant(item.getPath()) result = newQVariant(item.path())
of ModelRole.Color: of ModelRole.Color:
result = newQVariant(item.getColor()) result = newQVariant(item.color())
of ModelRole.WalletType: of ModelRole.WalletType:
result = newQVariant(item.getWalletType()) result = newQVariant(item.walletType())
of ModelRole.Emoji: of ModelRole.Emoji:
result = newQVariant(item.getEmoji()) result = newQVariant(item.emoji())
of ModelRole.RelatedAccounts: of ModelRole.RelatedAccounts:
result = newQVariant(item.getRelatedAccounts()) result = newQVariant(item.relatedAccounts())
of ModelRole.KeyUid: of ModelRole.KeyUid:
result = newQVariant(item.getKeyUid()) result = newQVariant(item.keyUid())

View File

@ -1,7 +1,8 @@
import NimQml, sequtils, sugar, chronicles import NimQml, sequtils, sugar, chronicles
import ./io_interface, ./view, ./item, ./controller, ./utils import ./io_interface, ./view, ./item, ./controller
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import ../../../../shared/wallet_utils
import ../../../../../global/global_singleton import ../../../../../global/global_singleton
import ../../../../../core/eventemitter import ../../../../../core/eventemitter
import ../../../../../../app_service/service/keycard/service as keycard_service import ../../../../../../app_service/service/keycard/service as keycard_service
@ -63,7 +64,7 @@ method refreshWalletAccounts*(self: Module) =
let walletAccounts = self.controller.getWalletAccounts() let walletAccounts = self.controller.getWalletAccounts()
let items = walletAccounts.map(w => (block: let items = walletAccounts.map(w => (block:
walletAccountToItem(w) walletAccountToWalletSettingsAccountsItem(w)
)) ))
self.view.setItems(items) self.view.setItems(items)
@ -77,7 +78,7 @@ method load*(self: Module) =
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args): self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
let args = WalletAccountUpdated(e) let args = WalletAccountUpdated(e)
self.view.onUpdatedAccount(walletAccountToItem(args.account)) self.view.onUpdatedAccount(walletAccountToWalletSettingsAccountsItem(args.account))
self.events.on(SIGNAL_NEW_KEYCARD_SET) do(e: Args): self.events.on(SIGNAL_NEW_KEYCARD_SET) do(e: Args):
let args = KeycardActivityArgs(e) let args = KeycardActivityArgs(e)

View File

@ -1,34 +0,0 @@
import tables, sequtils, sugar
import ../../../../../../app_service/service/wallet_account/service as wallet_account_service
import ./item
import ./related_account_item as related_account_item
import ./related_accounts_model as related_accounts_model
proc walletAccountToRelatedAccountItem*(w: WalletAccountDto) : related_account_item.Item =
return related_account_item.initItem(
w.name,
w.color,
w.emoji,
)
proc walletAccountToItem*(
w: WalletAccountDto,
) : item.Item =
let relatedAccounts = related_accounts_model.newModel()
if w.isNil:
return item.initItem()
relatedAccounts.setItems(
w.relatedAccounts.map(x => walletAccountToRelatedAccountItem(x))
)
return item.initItem(
w.name,
w.address,
w.path,
w.color,
w.walletType,
w.emoji,
relatedAccounts,
w.keyUid,
)

View File

@ -1,17 +1,13 @@
import strformat import strformat
import ../../../shared_models/wallet_account_item
import ../../../shared_models/currency_amount import ../../../shared_models/currency_amount
export wallet_account_item
type type
Item* = object Item* = ref object of WalletAccountItem
name: string
address: string
path: string
color: string
walletType: string
currencyBalance: CurrencyAmount
emoji: string
keyUid: string
assetsLoading: bool assetsLoading: bool
currencyBalance: CurrencyAmount
proc initItem*( proc initItem*(
name: string = "", name: string = "",
@ -24,52 +20,26 @@ proc initItem*(
keyUid: string = "", keyUid: string = "",
assetsLoading: bool = true, assetsLoading: bool = true,
): Item = ): Item =
result.name = name result = Item()
result.address = address result.WalletAccountItem.setup(name,
result.path = path address,
result.color = color color,
result.walletType = walletType emoji,
result.currencyBalance = currencyBalance walletType,
result.emoji = emoji path,
result.keyUid = keyUid keyUid)
result.assetsLoading = assetsLoading result.assetsLoading = assetsLoading
result.currencyBalance = currencyBalance
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""WalletAccountItem( result = "WalletSection-Accounts-Item("
name: {self.name}, result = result & $self.WalletAccountItem
address: {self.address}, result = result & "\nassetsLoading: " & $self.assetsLoading
path: {self.path}, result = result & "\ncurrencyBalance: " & $self.currencyBalance
color: {self.color}, result = result & ")"
walletType: {self.walletType},
currencyBalance: {self.currencyBalance}, proc currencyBalance*(self: Item): CurrencyAmount =
emoji: {self.emoji},
keyUid: {self.keyUid},
assetsLoading: {self.assetsLoading},
]"""
proc getName*(self: Item): string =
return self.name
proc getAddress*(self: Item): string =
return self.address
proc getPath*(self: Item): string =
return self.path
proc getEmoji*(self: Item): string =
return self.emoji
proc getColor*(self: Item): string =
return self.color
proc getWalletType*(self: Item): string =
return self.walletType
proc getCurrencyBalance*(self: Item): CurrencyAmount =
return self.currencyBalance return self.currencyBalance
proc getKeyUid*(self: Item): string = proc assetsLoading*(self: Item): bool =
return self.keyUid
proc getAssetsLoading*(self: Item): bool =
return self.assetsLoading return self.assetsLoading

View File

@ -80,20 +80,20 @@ QtObject:
case enumRole: case enumRole:
of ModelRole.Name: of ModelRole.Name:
result = newQVariant(item.getName()) result = newQVariant(item.name())
of ModelRole.Address: of ModelRole.Address:
result = newQVariant(item.getAddress()) result = newQVariant(item.address())
of ModelRole.Path: of ModelRole.Path:
result = newQVariant(item.getPath()) result = newQVariant(item.path())
of ModelRole.Color: of ModelRole.Color:
result = newQVariant(item.getColor()) result = newQVariant(item.color())
of ModelRole.WalletType: of ModelRole.WalletType:
result = newQVariant(item.getWalletType()) result = newQVariant(item.walletType())
of ModelRole.CurrencyBalance: of ModelRole.CurrencyBalance:
result = newQVariant(item.getCurrencyBalance()) result = newQVariant(item.currencyBalance())
of ModelRole.Emoji: of ModelRole.Emoji:
result = newQVariant(item.getEmoji()) result = newQVariant(item.emoji())
of ModelRole.KeyUid: of ModelRole.KeyUid:
result = newQVariant(item.getKeyUid()) result = newQVariant(item.keyUid())
of ModelRole.AssetsLoading: of ModelRole.AssetsLoading:
result = newQVariant(item.getAssetsLoading()) result = newQVariant(item.assetsLoading())

View File

@ -1,6 +1,6 @@
import tables, NimQml, sequtils, sugar, chronicles import tables, NimQml, sequtils, sugar, chronicles
import ./io_interface, ./view, ./item, ./controller, ./utils import ./io_interface, ./view, ./item, ./controller
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../core/eventemitter import ../../../../core/eventemitter
@ -9,6 +9,7 @@ import ../../../../../app_service/service/keycard/service as keycard_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/currency/service as currency_service import ../../../../../app_service/service/currency/service as currency_service
import ../../../shared/wallet_utils
import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module
export io_interface export io_interface
@ -64,7 +65,7 @@ method refreshWalletAccounts*(self: Module) =
let currencyFormat = self.controller.getCurrencyFormat(currency) let currencyFormat = self.controller.getCurrencyFormat(currency)
let items = walletAccounts.map(w => (block: let items = walletAccounts.map(w => (block:
walletAccountToItem( walletAccountToWalletAccountsItem(
w, w,
enabledChainIds, enabledChainIds,
currency, currency,

View File

@ -1,25 +0,0 @@
import ./item
import ../../../../../app_service/service/wallet_account/dto
import ../../../../../app_service/service/currency/dto as currency_dto
import ../../../shared_models/currency_amount
import ../../../shared_models/currency_amount_utils
proc walletAccountToItem*(
w: WalletAccountDto,
enabledChainIds: seq[int],
currency: string,
currencyFormat: CurrencyFormatDto,
) : item.Item =
return item.initItem(
w.name,
w.address,
w.path,
w.color,
w.walletType,
currencyAmountToItem(w.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
w.emoji,
w.keyUid,
w.assetsLoading,
)

View File

@ -9,13 +9,11 @@ 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/collectible/service as collectible_service import ../../../../../app_service/service/collectible/service as collectible_service
import ../../../../../app_service/service/node/service as node_service import ../../../../../app_service/service/node/service as node_service
import ../../../shared_models/currency_amount_utils import ../../../shared/wallet_utils
import ../../../shared_models/currency_amount import ../../../shared_models/currency_amount
import ../../../shared_models/token_model as token_model import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_item as token_item import ../../../shared_models/token_item as token_item
import ../../../shared_models/token_utils
import ./item as account_item import ./item as account_item
import ./utils
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
@ -129,7 +127,7 @@ method switchAccount*(self: Module, accountIndex: int) =
self.currentAccountIndex = 0 self.currentAccountIndex = 0
walletAccount = self.controller.getWalletAccount(self.currentAccountIndex) walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
let accountItem = walletAccountToItem(walletAccount) let accountItem = walletAccountToWalletAssetsItem(walletAccount)
self.view.setData(accountItem) self.view.setData(accountItem)
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading: if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
@ -137,7 +135,6 @@ method switchAccount*(self: Module, accountIndex: int) =
else: else:
self.setAssetsAndBalance(walletAccount.tokens) self.setAssetsAndBalance(walletAccount.tokens)
proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool, hasMarketValuesCache: bool) = proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool, hasMarketValuesCache: bool) =
let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex) let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
if not accountsTokens.contains(walletAccount.address): if not accountsTokens.contains(walletAccount.address):

View File

@ -1,10 +0,0 @@
import ./item
import ../../../../../app_service/service/wallet_account/dto
proc walletAccountToItem*(
w: WalletAccountDto,
) : item.Item =
return item.initItem(
w.assetsLoading,
)

View File

@ -3,8 +3,8 @@ 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
import ../../../../app_service/service/currency/service as currency_service import ../../../../app_service/service/currency/service as currency_service
import ../../shared/wallet_utils
import ../../shared_models/currency_amount import ../../shared_models/currency_amount
import ../../shared_models/currency_amount_utils
type type
Controller* = ref object of RootObj Controller* = ref object of RootObj

View File

@ -5,7 +5,7 @@ import ../../../../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 ../../../../../app_service/service/network/service as network_service import ../../../../../app_service/service/network/service as network_service
import ../../../shared_models/currency_amount_utils import ../../../shared/wallet_utils
import ../../../shared_models/currency_amount import ../../../shared_models/currency_amount
import ./item import ./item

View File

@ -1,18 +1,15 @@
import strformat import strformat
import ../../../shared_models/token_model as token_model import ../../../shared_models/wallet_account_item
import ../../../shared_models/token_model
import ../../../shared_models/currency_amount import ../../../shared_models/currency_amount
export wallet_account_item
type type
AccountItem* = object AccountItem* = ref object of WalletAccountItem
name: string
address: string
color: string
walletType: string
emoji: string
assets: token_model.Model assets: token_model.Model
currencyBalance: CurrencyAmount currencyBalance: CurrencyAmount
proc initAccountItem*( proc initAccountItem*(
name: string = "", name: string = "",
address: string = "", address: string = "",
@ -22,42 +19,26 @@ proc initAccountItem*(
assets: token_model.Model = nil, assets: token_model.Model = nil,
currencyBalance: CurrencyAmount = nil, currencyBalance: CurrencyAmount = nil,
): AccountItem = ): AccountItem =
result.name = name result = AccountItem()
result.address = address result.WalletAccountItem.setup(name,
result.color = color address,
result.walletType = walletType color,
result.emoji = emoji emoji,
walletType,
path = "",
keyUid = "")
result.assets = assets result.assets = assets
result.currencyBalance = currencyBalance result.currencyBalance = currencyBalance
proc `$`*(self: AccountItem): string = proc `$`*(self: AccountItem): string =
result = fmt"""WalletAccountItem( result = "WalletSection-Send-Item("
name: {self.name}, result = result & $self.WalletAccountItem
address: {self.address}, result = result & "\nassets: " & $self.assets
color: {self.color}, result = result & "\ncurrencyBalance: " & $self.currencyBalance
walletType: {self.walletType}, result = result & ")"
emoji: {self.emoji},
assets: {self.assets}, proc assets*(self: AccountItem): token_model.Model =
currencyBalance: {self.currencyBalance},
]"""
proc getName*(self: AccountItem): string =
return self.name
proc getAddress*(self: AccountItem): string =
return self.address
proc getEmoji*(self: AccountItem): string =
return self.emoji
proc getColor*(self: AccountItem): string =
return self.color
proc getWalletType*(self: AccountItem): string =
return self.walletType
proc getAssets*(self: AccountItem): token_model.Model =
return self.assets return self.assets
proc getCurrencyBalance*(self: AccountItem): CurrencyAmount = proc currencyBalance*(self: AccountItem): CurrencyAmount =
return self.currencyBalance return self.currencyBalance

View File

@ -75,17 +75,17 @@ QtObject:
case enumRole: case enumRole:
of ModelRole.Name: of ModelRole.Name:
result = newQVariant(item.getName()) result = newQVariant(item.name())
of ModelRole.Address: of ModelRole.Address:
result = newQVariant(item.getAddress()) result = newQVariant(item.address())
of ModelRole.Color: of ModelRole.Color:
result = newQVariant(item.getColor()) result = newQVariant(item.color())
of ModelRole.WalletType: of ModelRole.WalletType:
result = newQVariant(item.getWalletType()) result = newQVariant(item.walletType())
of ModelRole.Emoji: of ModelRole.Emoji:
result = newQVariant(item.getEmoji()) result = newQVariant(item.emoji())
of ModelRole.Assets: of ModelRole.Assets:
result = newQVariant(item.getAssets()) result = newQVariant(item.assets())
of ModelRole.CurrencyBalance: of ModelRole.CurrencyBalance:
result = newQVariant(item.getCurrencyBalance()) result = newQVariant(item.currencyBalance())

View File

@ -7,8 +7,8 @@ import ../../../../../app_service/service/currency/service as currency_service
import ../../../../../app_service/service/currency/dto as currency_dto import ../../../../../app_service/service/currency/dto as currency_dto
import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module
import ../../../shared/wallet_utils
import ../../../shared_models/currency_amount import ../../../shared_models/currency_amount
import ../../../shared_models/currency_amount_utils
import ../../../../core/eventemitter import ../../../../core/eventemitter

View File

@ -1,6 +1,6 @@
import tables, NimQml, sequtils, sugar, json, stint import tables, NimQml, sequtils, sugar, json, stint
import ./io_interface, ./view, ./controller, ./utils import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../core/eventemitter import ../../../../core/eventemitter
@ -8,6 +8,7 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
import ../../../../../app_service/service/network/service as network_service import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/currency/service as currency_service import ../../../../../app_service/service/currency/service as currency_service
import ../../../../../app_service/service/transaction/service as transaction_service import ../../../../../app_service/service/transaction/service as transaction_service
import ../../../shared/wallet_utils
export io_interface export io_interface
@ -61,7 +62,7 @@ method refreshWalletAccounts*(self: Module) =
let tokenFormats = collect(initTable()): let tokenFormats = collect(initTable()):
for t in w.tokens: {t.symbol: self.controller.getCurrencyFormat(t.symbol)} for t in w.tokens: {t.symbol: self.controller.getCurrencyFormat(t.symbol)}
walletAccountToItem( walletAccountToWalletSendAccountItem(
w, w,
chainIds, chainIds,
enabledChainIds, enabledChainIds,

View File

@ -1,30 +0,0 @@
import Tables, sequtils, sugar
import ./account_item
import ../../../../../app_service/service/wallet_account/dto
import ../../../../../app_service/service/currency/dto as currency_dto
import ../../../shared_models/currency_amount_utils
import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_utils
proc walletAccountToItem*(
w: WalletAccountDto,
chainIds: seq[int],
enabledChainIds: seq[int],
currency: string,
currencyFormat: CurrencyFormatDto,
tokenFormats: Table[string, CurrencyFormatDto],
) : account_item.AccountItem =
let assets = token_model.newModel()
assets.setItems(
w.tokens.map(t => walletTokenToItem(t, chainIds, enabledChainIds, currency, currencyFormat, tokenFormats[t.symbol]))
)
return account_item.initAccountItem(
w.name,
w.address,
w.color,
w.walletType,
w.emoji,
assets,
currencyAmountToItem(w.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
)

View File

@ -107,7 +107,7 @@ QtObject:
proc hasGas*(self: View, address: string, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.slot.} = proc hasGas*(self: View, address: string, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.slot.} =
for account in self.accounts.items: for account in self.accounts.items:
if account.getAddress() == address: if account.address() == address:
return account.getAssets().hasGas(chainId, nativeGasSymbol, requiredGas) return account.assets().hasGas(chainId, nativeGasSymbol, requiredGas)
return false return false

View File

@ -4,8 +4,8 @@ import ../../../../global/global_singleton
import ../../../../../app_service/service/transaction/dto import ../../../../../app_service/service/transaction/dto
import ../../../../../app_service/service/currency/dto as currency_dto import ../../../../../app_service/service/currency/dto as currency_dto
import ../../../../../app_service/service/collectible/dto as collectible_dto import ../../../../../app_service/service/collectible/dto as collectible_dto
import ../../../shared/wallet_utils
import ../../../shared_models/currency_amount import ../../../shared_models/currency_amount
import ../../../shared_models/currency_amount_utils
import ./item import ./item
import ./multi_transaction_item import ./multi_transaction_item

View File

@ -0,0 +1,116 @@
import tables, sequtils, sugar
import ../shared_models/[balance_item, currency_amount, token_item, token_model]
import ../../../app_service/service/wallet_account/service as wallet_account_service
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 ../main/profile_section/wallet/accounts/item as wallet_settings_accounts_item
import ../main/profile_section/wallet/accounts/[related_account_item, related_accounts_model]
proc currencyAmountToItem*(amount: float64, format: CurrencyFormatDto) : CurrencyAmount =
return newCurrencyAmount(
amount,
format.symbol,
int(format.displayDecimals),
format.stripTrailingZeroes
)
proc balanceToItemBalanceItem*(b: BalanceDto, format: CurrencyFormatDto) : balance_item.Item =
return balance_item.initItem(
currencyAmountToItem(b.balance, format),
b.address,
b.chainId
)
proc walletAccountToRelatedAccountItem*(w: WalletAccountDto) : related_account_item.Item =
return related_account_item.initItem(
w.name,
w.color,
w.emoji,
)
proc walletAccountToWalletSettingsAccountsItem*(w: WalletAccountDto): wallet_settings_accounts_item.Item =
let relatedAccounts = related_accounts_model.newModel()
if w.isNil:
return wallet_settings_accounts_item.initItem()
relatedAccounts.setItems(w.relatedAccounts.map(x => walletAccountToRelatedAccountItem(x)))
return wallet_settings_accounts_item.initItem(
w.name,
w.address,
w.path,
w.color,
w.walletType,
w.emoji,
relatedAccounts,
w.keyUid,
)
proc walletAccountToWalletAccountsItem*(w: WalletAccountDto, enabledChainIds: seq[int], currency: string,
currencyFormat: CurrencyFormatDto): wallet_accounts_item.Item =
return wallet_accounts_item.initItem(
w.name,
w.address,
w.path,
w.color,
w.walletType,
currencyAmountToItem(w.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
w.emoji,
w.keyUid,
w.assetsLoading,
)
proc walletAccountToWalletAssetsItem*(w: WalletAccountDto): wallet_assets_item.Item =
return wallet_assets_item.initItem(
w.assetsLoading,
)
proc walletTokenToItem*(t: WalletTokenDto, chainIds: seq[int], enabledChainIds: seq[int], currency: string,
currencyFormat: CurrencyFormatDto, tokenFormat: CurrencyFormatDto): token_item.Item =
let marketValues = t.marketValuesPerCurrency.getOrDefault(currency)
return token_item.initItem(
t.name,
t.symbol,
currencyAmountToItem(t.getBalance(chainIds), tokenFormat),
currencyAmountToItem(t.getCurrencyBalance(chainIds, currency), currencyFormat),
currencyAmountToItem(t.getBalance(enabledChainIds), tokenFormat),
currencyAmountToItem(t.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
t.getVisibleForNetwork(enabledChainIds),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(chainIds).map(b => balanceToItemBalanceItem(b, tokenFormat)),
t.description,
t.assetWebsiteUrl,
t.builtOn,
t.getAddress(),
currencyAmountToItem(marketValues.marketCap, currencyFormat),
currencyAmountToItem(marketValues.highDay, currencyFormat),
currencyAmountToItem(marketValues.lowDay, currencyFormat),
marketValues.changePctHour,
marketValues.changePctDay,
marketValues.changePct24hour,
marketValues.change24hour,
currencyAmountToItem(marketValues.price, currencyFormat),
t.decimals,
loading = false
)
proc walletAccountToWalletSendAccountItem*(w: WalletAccountDto, chainIds: seq[int], enabledChainIds: seq[int], currency: string,
currencyFormat: CurrencyFormatDto, tokenFormats: Table[string, CurrencyFormatDto]): wallet_send_account_item.AccountItem =
let assets = token_model.newModel()
assets.setItems(
w.tokens.map(t => walletTokenToItem(t, chainIds, enabledChainIds, currency, currencyFormat, tokenFormats[t.symbol]))
)
return wallet_send_account_item.initAccountItem(
w.name,
w.address,
w.color,
w.walletType,
w.emoji,
assets,
currencyAmountToItem(w.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
)

View File

@ -1,11 +0,0 @@
import ../../../app_service/service/wallet_account/dto
import ../../../app_service/service/currency/dto as currency_dto
import ./currency_amount_utils
import ./balance_item
proc balanceToItem*(b: BalanceDto, format: CurrencyFormatDto) : Item =
return initItem(
currencyAmountToItem(b.balance, format),
b.address,
b.chainId
)

View File

@ -1,10 +0,0 @@
import ../../../app_service/service/currency/dto
import ./currency_amount
proc currencyAmountToItem*(amount: float64, format: CurrencyFormatDto) : CurrencyAmount =
return newCurrencyAmount(
amount,
format.symbol,
int(format.displayDecimals),
format.stripTrailingZeroes
)

View File

@ -1,42 +0,0 @@
import tables, sequtils, sugar
import ../../../app_service/service/wallet_account/dto
import ../../../app_service/service/currency/dto as currency_dto
import ./currency_amount_utils
import ./balance_utils
import ./token_item
proc walletTokenToItem*(
t: WalletTokenDto,
chainIds: seq[int],
enabledChainIds: seq[int],
currency: string,
currencyFormat: CurrencyFormatDto,
tokenFormat: CurrencyFormatDto,
) : token_item.Item =
let marketValues = t.marketValuesPerCurrency.getOrDefault(currency)
return token_item.initItem(
t.name,
t.symbol,
currencyAmountToItem(t.getBalance(chainIds), tokenFormat),
currencyAmountToItem(t.getCurrencyBalance(chainIds, currency), currencyFormat),
currencyAmountToItem(t.getBalance(enabledChainIds), tokenFormat),
currencyAmountToItem(t.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
t.getVisibleForNetwork(enabledChainIds),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(chainIds).map(b => balanceToItem(b, tokenFormat)),
t.description,
t.assetWebsiteUrl,
t.builtOn,
t.getAddress(),
currencyAmountToItem(marketValues.marketCap, currencyFormat),
currencyAmountToItem(marketValues.highDay, currencyFormat),
currencyAmountToItem(marketValues.lowDay, currencyFormat),
marketValues.changePctHour,
marketValues.changePctDay,
marketValues.changePct24hour,
marketValues.change24hour,
currencyAmountToItem(marketValues.price, currencyFormat),
t.decimals,
loading = false
)

View File

@ -0,0 +1,88 @@
import strformat
type
WalletAccountItem* = ref object of RootObj
name: string
address: string
color: string
emoji: string
walletType: string
path: string
keyUid: string
proc setup*(self: WalletAccountItem,
name: string = "",
address: string = "",
color: string = "",
emoji: string = "",
walletType: string = "",
path: string = "",
keyUid: string = ""
) =
self.name = name
self.address = address
self.color = color
self.emoji = emoji
self.walletType = walletType
self.path = path
self.keyUid = keyUid
proc initWalletAccountItem*(
name: string = "",
address: string = "",
color: string = "",
emoji: string = "",
walletType: string = "",
path: string = "",
keyUid: string = ""
): WalletAccountItem =
result = WalletAccountItem()
result.setup(name,
address,
color,
emoji,
walletType,
path,
keyUid)
proc `$`*(self: WalletAccountItem): string =
result = fmt"""WalletAccountItem(
name: {self.name},
address: {self.address},
color: {self.color},
emoji: {self.emoji},
walletType: {self.walletType},
path: {self.path},
keyUid: {self.keyUid},
]"""
proc name*(self: WalletAccountItem): string {.inline.} =
return self.name
proc `name=`*(self: WalletAccountItem, value: string) {.inline.} =
self.name = value
proc address*(self: WalletAccountItem): string {.inline.} =
return self.address
proc emoji*(self: WalletAccountItem): string {.inline.} =
return self.emoji
proc `emoji=`*(self: WalletAccountItem, value: string) {.inline.} =
self.emoji = value
proc color*(self: WalletAccountItem): string {.inline.} =
return self.color
proc `color=`*(self: WalletAccountItem, value: string) {.inline.} =
self.color = value
proc walletType*(self: WalletAccountItem): string {.inline.} =
return self.walletType
proc path*(self: WalletAccountItem): string {.inline.} =
return self.path
proc keyUid*(self: WalletAccountItem): string {.inline.} =
return self.keyUid