chore(@desktop/wallet): wallet improvements
This commit is contained in:
parent
3115b9d19e
commit
20102ebe3b
|
@ -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/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 ../../../shared_models/token_utils
|
||||
|
||||
import ../../wallet_section/accounts/utils
|
||||
|
||||
import ./io_interface, ./view, ./controller
|
||||
import ../io_interface as delegate_interface
|
||||
|
@ -68,7 +66,7 @@ proc switchAccount*(self: Module, accountIndex: int) =
|
|||
|
||||
let currencyFormat = self.controller.getCurrencyFormat(currency)
|
||||
|
||||
let accountItem = walletAccountToItem(
|
||||
let accountItem = walletAccountToWalletAccountsItem(
|
||||
walletAccount,
|
||||
enabledChainIds,
|
||||
currency,
|
||||
|
|
|
@ -121,19 +121,19 @@ QtObject:
|
|||
return self.assets.hasGas(chainId, nativeGasSymbol, requiredGas)
|
||||
|
||||
proc setData*(self: View, item: account_item.Item) =
|
||||
self.name = item.getName()
|
||||
self.name = item.name()
|
||||
self.nameChanged()
|
||||
self.address = item.getAddress()
|
||||
self.address = item.address()
|
||||
self.addressChanged()
|
||||
self.path = item.getPath()
|
||||
self.path = item.path()
|
||||
self.pathChanged()
|
||||
self.color = item.getColor()
|
||||
self.color = item.color()
|
||||
self.colorChanged()
|
||||
self.walletType = item.getWalletType()
|
||||
self.walletType = item.walletType()
|
||||
self.walletTypeChanged()
|
||||
self.currencyBalance = item.getCurrencyBalance()
|
||||
self.currencyBalance = item.currencyBalance()
|
||||
self.currencyBalanceChanged()
|
||||
self.emoji = item.getEmoji()
|
||||
self.emoji = item.emoji()
|
||||
self.emojiChanged()
|
||||
|
||||
proc isAddressCurrentAccount*(self: View, address: string): bool =
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import strformat
|
||||
import ../../../../shared_models/wallet_account_item
|
||||
import ./related_accounts_model as related_accounts_model
|
||||
|
||||
export wallet_account_item
|
||||
|
||||
type
|
||||
Item* = object
|
||||
name*: string
|
||||
address: string
|
||||
color*: string
|
||||
emoji*: string
|
||||
walletType: string
|
||||
path: string
|
||||
Item* = ref object of WalletAccountItem
|
||||
relatedAccounts: related_accounts_model.Model
|
||||
keyUid: string
|
||||
|
||||
proc initItem*(
|
||||
name: string = "",
|
||||
|
@ -22,47 +18,21 @@ proc initItem*(
|
|||
relatedAccounts: related_accounts_model.Model = nil,
|
||||
keyUid: string = "",
|
||||
): Item =
|
||||
result.name = name
|
||||
result.address = address
|
||||
result.path = path
|
||||
result.color = color
|
||||
result.walletType = walletType
|
||||
result.emoji = emoji
|
||||
result = Item()
|
||||
result.WalletAccountItem.setup(name,
|
||||
address,
|
||||
color,
|
||||
emoji,
|
||||
walletType,
|
||||
path,
|
||||
keyUid)
|
||||
result.relatedAccounts = relatedAccounts
|
||||
result.keyUid = keyUid
|
||||
|
||||
|
||||
proc `$`*(self: Item): string =
|
||||
result = fmt"""WalletAccountItem(
|
||||
name: {self.name},
|
||||
address: {self.address},
|
||||
path: {self.path},
|
||||
color: {self.color},
|
||||
walletType: {self.walletType},
|
||||
emoji: {self.emoji},
|
||||
relatedAccounts: {self.relatedAccounts}
|
||||
keyUid: {self.keyUid},
|
||||
]"""
|
||||
result = "ProfileSection-Accounts-Item("
|
||||
result = result & $self.WalletAccountItem
|
||||
result = result & "\nrelatedAccounts: " & $self.relatedAccounts
|
||||
result = result & ")"
|
||||
|
||||
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 getRelatedAccounts*(self: Item): related_accounts_model.Model =
|
||||
return self.relatedAccounts
|
||||
|
||||
proc getKeyUid*(self: Item): string =
|
||||
return self.keyUid
|
||||
proc relatedAccounts*(self: Item): related_accounts_model.Model =
|
||||
return self.relatedAccounts
|
|
@ -66,7 +66,7 @@ QtObject:
|
|||
proc onUpdatedAccount*(self: Model, account: Item) =
|
||||
var i = 0
|
||||
for item in self.items.mitems:
|
||||
if account.getAddress() == item.getAddress():
|
||||
if account.address == item.address:
|
||||
item.name = account.name
|
||||
item.color = account.color
|
||||
item.emoji = account.emoji
|
||||
|
@ -89,18 +89,18 @@ QtObject:
|
|||
|
||||
case enumRole:
|
||||
of ModelRole.Name:
|
||||
result = newQVariant(item.getName())
|
||||
result = newQVariant(item.name())
|
||||
of ModelRole.Address:
|
||||
result = newQVariant(item.getAddress())
|
||||
result = newQVariant(item.address())
|
||||
of ModelRole.Path:
|
||||
result = newQVariant(item.getPath())
|
||||
result = newQVariant(item.path())
|
||||
of ModelRole.Color:
|
||||
result = newQVariant(item.getColor())
|
||||
result = newQVariant(item.color())
|
||||
of ModelRole.WalletType:
|
||||
result = newQVariant(item.getWalletType())
|
||||
result = newQVariant(item.walletType())
|
||||
of ModelRole.Emoji:
|
||||
result = newQVariant(item.getEmoji())
|
||||
result = newQVariant(item.emoji())
|
||||
of ModelRole.RelatedAccounts:
|
||||
result = newQVariant(item.getRelatedAccounts())
|
||||
result = newQVariant(item.relatedAccounts())
|
||||
of ModelRole.KeyUid:
|
||||
result = newQVariant(item.getKeyUid())
|
||||
result = newQVariant(item.keyUid())
|
|
@ -1,7 +1,8 @@
|
|||
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 ../../../../shared/wallet_utils
|
||||
import ../../../../../global/global_singleton
|
||||
import ../../../../../core/eventemitter
|
||||
import ../../../../../../app_service/service/keycard/service as keycard_service
|
||||
|
@ -63,7 +64,7 @@ method refreshWalletAccounts*(self: Module) =
|
|||
let walletAccounts = self.controller.getWalletAccounts()
|
||||
|
||||
let items = walletAccounts.map(w => (block:
|
||||
walletAccountToItem(w)
|
||||
walletAccountToWalletSettingsAccountsItem(w)
|
||||
))
|
||||
|
||||
self.view.setItems(items)
|
||||
|
@ -77,7 +78,7 @@ method load*(self: Module) =
|
|||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
|
||||
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):
|
||||
let args = KeycardActivityArgs(e)
|
||||
|
|
|
@ -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,
|
||||
)
|
|
@ -1,17 +1,13 @@
|
|||
import strformat
|
||||
import ../../../shared_models/wallet_account_item
|
||||
import ../../../shared_models/currency_amount
|
||||
|
||||
export wallet_account_item
|
||||
|
||||
type
|
||||
Item* = object
|
||||
name: string
|
||||
address: string
|
||||
path: string
|
||||
color: string
|
||||
walletType: string
|
||||
currencyBalance: CurrencyAmount
|
||||
emoji: string
|
||||
keyUid: string
|
||||
Item* = ref object of WalletAccountItem
|
||||
assetsLoading: bool
|
||||
currencyBalance: CurrencyAmount
|
||||
|
||||
proc initItem*(
|
||||
name: string = "",
|
||||
|
@ -24,52 +20,26 @@ proc initItem*(
|
|||
keyUid: string = "",
|
||||
assetsLoading: bool = true,
|
||||
): Item =
|
||||
result.name = name
|
||||
result.address = address
|
||||
result.path = path
|
||||
result.color = color
|
||||
result.walletType = walletType
|
||||
result.currencyBalance = currencyBalance
|
||||
result.emoji = emoji
|
||||
result.keyUid = keyUid
|
||||
result = Item()
|
||||
result.WalletAccountItem.setup(name,
|
||||
address,
|
||||
color,
|
||||
emoji,
|
||||
walletType,
|
||||
path,
|
||||
keyUid)
|
||||
result.assetsLoading = assetsLoading
|
||||
|
||||
result.currencyBalance = currencyBalance
|
||||
|
||||
proc `$`*(self: Item): string =
|
||||
result = fmt"""WalletAccountItem(
|
||||
name: {self.name},
|
||||
address: {self.address},
|
||||
path: {self.path},
|
||||
color: {self.color},
|
||||
walletType: {self.walletType},
|
||||
currencyBalance: {self.currencyBalance},
|
||||
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 =
|
||||
result = "WalletSection-Accounts-Item("
|
||||
result = result & $self.WalletAccountItem
|
||||
result = result & "\nassetsLoading: " & $self.assetsLoading
|
||||
result = result & "\ncurrencyBalance: " & $self.currencyBalance
|
||||
result = result & ")"
|
||||
|
||||
proc currencyBalance*(self: Item): CurrencyAmount =
|
||||
return self.currencyBalance
|
||||
|
||||
proc getKeyUid*(self: Item): string =
|
||||
return self.keyUid
|
||||
|
||||
proc getAssetsLoading*(self: Item): bool =
|
||||
proc assetsLoading*(self: Item): bool =
|
||||
return self.assetsLoading
|
||||
|
|
|
@ -80,20 +80,20 @@ QtObject:
|
|||
|
||||
case enumRole:
|
||||
of ModelRole.Name:
|
||||
result = newQVariant(item.getName())
|
||||
result = newQVariant(item.name())
|
||||
of ModelRole.Address:
|
||||
result = newQVariant(item.getAddress())
|
||||
result = newQVariant(item.address())
|
||||
of ModelRole.Path:
|
||||
result = newQVariant(item.getPath())
|
||||
result = newQVariant(item.path())
|
||||
of ModelRole.Color:
|
||||
result = newQVariant(item.getColor())
|
||||
result = newQVariant(item.color())
|
||||
of ModelRole.WalletType:
|
||||
result = newQVariant(item.getWalletType())
|
||||
result = newQVariant(item.walletType())
|
||||
of ModelRole.CurrencyBalance:
|
||||
result = newQVariant(item.getCurrencyBalance())
|
||||
result = newQVariant(item.currencyBalance())
|
||||
of ModelRole.Emoji:
|
||||
result = newQVariant(item.getEmoji())
|
||||
result = newQVariant(item.emoji())
|
||||
of ModelRole.KeyUid:
|
||||
result = newQVariant(item.getKeyUid())
|
||||
result = newQVariant(item.keyUid())
|
||||
of ModelRole.AssetsLoading:
|
||||
result = newQVariant(item.getAssetsLoading())
|
||||
result = newQVariant(item.assetsLoading())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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 ../../../../global/global_singleton
|
||||
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/network/service as network_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
|
||||
|
||||
export io_interface
|
||||
|
@ -64,7 +65,7 @@ method refreshWalletAccounts*(self: Module) =
|
|||
let currencyFormat = self.controller.getCurrencyFormat(currency)
|
||||
|
||||
let items = walletAccounts.map(w => (block:
|
||||
walletAccountToItem(
|
||||
walletAccountToWalletAccountsItem(
|
||||
w,
|
||||
enabledChainIds,
|
||||
currency,
|
||||
|
|
|
@ -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,
|
||||
)
|
|
@ -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/collectible/service as collectible_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/token_model as token_model
|
||||
import ../../../shared_models/token_item as token_item
|
||||
import ../../../shared_models/token_utils
|
||||
import ./item as account_item
|
||||
import ./utils
|
||||
|
||||
import ./io_interface, ./view, ./controller
|
||||
import ../io_interface as delegate_interface
|
||||
|
@ -129,7 +127,7 @@ method switchAccount*(self: Module, accountIndex: int) =
|
|||
self.currentAccountIndex = 0
|
||||
walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
|
||||
|
||||
let accountItem = walletAccountToItem(walletAccount)
|
||||
let accountItem = walletAccountToWalletAssetsItem(walletAccount)
|
||||
self.view.setData(accountItem)
|
||||
|
||||
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
|
||||
|
@ -137,7 +135,6 @@ method switchAccount*(self: Module, accountIndex: int) =
|
|||
else:
|
||||
self.setAssetsAndBalance(walletAccount.tokens)
|
||||
|
||||
|
||||
proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool, hasMarketValuesCache: bool) =
|
||||
let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
|
||||
if not accountsTokens.contains(walletAccount.address):
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import ./item
|
||||
|
||||
import ../../../../../app_service/service/wallet_account/dto
|
||||
|
||||
proc walletAccountToItem*(
|
||||
w: WalletAccountDto,
|
||||
) : item.Item =
|
||||
return item.initItem(
|
||||
w.assetsLoading,
|
||||
)
|
|
@ -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/currency/service as currency_service
|
||||
|
||||
import ../../shared/wallet_utils
|
||||
import ../../shared_models/currency_amount
|
||||
import ../../shared_models/currency_amount_utils
|
||||
|
||||
type
|
||||
Controller* = ref object of RootObj
|
||||
|
|
|
@ -5,7 +5,7 @@ import ../../../../core/eventemitter
|
|||
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 ../../../shared_models/currency_amount_utils
|
||||
import ../../../shared/wallet_utils
|
||||
import ../../../shared_models/currency_amount
|
||||
import ./item
|
||||
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
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
|
||||
|
||||
export wallet_account_item
|
||||
|
||||
type
|
||||
AccountItem* = object
|
||||
name: string
|
||||
address: string
|
||||
color: string
|
||||
walletType: string
|
||||
emoji: string
|
||||
AccountItem* = ref object of WalletAccountItem
|
||||
assets: token_model.Model
|
||||
currencyBalance: CurrencyAmount
|
||||
|
||||
|
||||
proc initAccountItem*(
|
||||
name: string = "",
|
||||
address: string = "",
|
||||
|
@ -22,42 +19,26 @@ proc initAccountItem*(
|
|||
assets: token_model.Model = nil,
|
||||
currencyBalance: CurrencyAmount = nil,
|
||||
): AccountItem =
|
||||
result.name = name
|
||||
result.address = address
|
||||
result.color = color
|
||||
result.walletType = walletType
|
||||
result.emoji = emoji
|
||||
result = AccountItem()
|
||||
result.WalletAccountItem.setup(name,
|
||||
address,
|
||||
color,
|
||||
emoji,
|
||||
walletType,
|
||||
path = "",
|
||||
keyUid = "")
|
||||
result.assets = assets
|
||||
result.currencyBalance = currencyBalance
|
||||
|
||||
|
||||
proc `$`*(self: AccountItem): string =
|
||||
result = fmt"""WalletAccountItem(
|
||||
name: {self.name},
|
||||
address: {self.address},
|
||||
color: {self.color},
|
||||
walletType: {self.walletType},
|
||||
emoji: {self.emoji},
|
||||
assets: {self.assets},
|
||||
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 =
|
||||
result = "WalletSection-Send-Item("
|
||||
result = result & $self.WalletAccountItem
|
||||
result = result & "\nassets: " & $self.assets
|
||||
result = result & "\ncurrencyBalance: " & $self.currencyBalance
|
||||
result = result & ")"
|
||||
|
||||
proc assets*(self: AccountItem): token_model.Model =
|
||||
return self.assets
|
||||
|
||||
proc getCurrencyBalance*(self: AccountItem): CurrencyAmount =
|
||||
return self.currencyBalance
|
||||
proc currencyBalance*(self: AccountItem): CurrencyAmount =
|
||||
return self.currencyBalance
|
||||
|
|
|
@ -75,17 +75,17 @@ QtObject:
|
|||
|
||||
case enumRole:
|
||||
of ModelRole.Name:
|
||||
result = newQVariant(item.getName())
|
||||
result = newQVariant(item.name())
|
||||
of ModelRole.Address:
|
||||
result = newQVariant(item.getAddress())
|
||||
result = newQVariant(item.address())
|
||||
of ModelRole.Color:
|
||||
result = newQVariant(item.getColor())
|
||||
result = newQVariant(item.color())
|
||||
of ModelRole.WalletType:
|
||||
result = newQVariant(item.getWalletType())
|
||||
result = newQVariant(item.walletType())
|
||||
of ModelRole.Emoji:
|
||||
result = newQVariant(item.getEmoji())
|
||||
result = newQVariant(item.emoji())
|
||||
of ModelRole.Assets:
|
||||
result = newQVariant(item.getAssets())
|
||||
result = newQVariant(item.assets())
|
||||
of ModelRole.CurrencyBalance:
|
||||
result = newQVariant(item.getCurrencyBalance())
|
||||
result = newQVariant(item.currencyBalance())
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import ../../../../../app_service/service/currency/service as currency_service
|
|||
import ../../../../../app_service/service/currency/dto as currency_dto
|
||||
|
||||
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_utils
|
||||
|
||||
import ../../../../core/eventemitter
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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 ../../../../global/global_singleton
|
||||
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/currency/service as currency_service
|
||||
import ../../../../../app_service/service/transaction/service as transaction_service
|
||||
import ../../../shared/wallet_utils
|
||||
|
||||
export io_interface
|
||||
|
||||
|
@ -61,7 +62,7 @@ method refreshWalletAccounts*(self: Module) =
|
|||
let tokenFormats = collect(initTable()):
|
||||
for t in w.tokens: {t.symbol: self.controller.getCurrencyFormat(t.symbol)}
|
||||
|
||||
walletAccountToItem(
|
||||
walletAccountToWalletSendAccountItem(
|
||||
w,
|
||||
chainIds,
|
||||
enabledChainIds,
|
||||
|
|
|
@ -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),
|
||||
)
|
|
@ -107,7 +107,7 @@ QtObject:
|
|||
|
||||
proc hasGas*(self: View, address: string, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.slot.} =
|
||||
for account in self.accounts.items:
|
||||
if account.getAddress() == address:
|
||||
return account.getAssets().hasGas(chainId, nativeGasSymbol, requiredGas)
|
||||
if account.address() == address:
|
||||
return account.assets().hasGas(chainId, nativeGasSymbol, requiredGas)
|
||||
|
||||
return false
|
|
@ -4,8 +4,8 @@ import ../../../../global/global_singleton
|
|||
import ../../../../../app_service/service/transaction/dto
|
||||
import ../../../../../app_service/service/currency/dto as currency_dto
|
||||
import ../../../../../app_service/service/collectible/dto as collectible_dto
|
||||
import ../../../shared/wallet_utils
|
||||
import ../../../shared_models/currency_amount
|
||||
import ../../../shared_models/currency_amount_utils
|
||||
|
||||
import ./item
|
||||
import ./multi_transaction_item
|
||||
|
|
|
@ -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),
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
Loading…
Reference in New Issue