feat(@wallet): add wallet filter

This commit is contained in:
Anthony Laibe 2023-04-27 15:22:27 +02:00 committed by Anthony Laibe
parent 162662a09a
commit 39b9b5ee91
35 changed files with 192 additions and 317 deletions

View File

@ -61,9 +61,6 @@ method walletSectionDidLoad*(self: AccessInterface) {.base.} =
method browserSectionDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method networksModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method networkConnectionModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -21,7 +21,6 @@ import stickers/module as stickers_module
import activity_center/module as activity_center_module
import communities/module as communities_module
import node_section/module as node_section_module
import networks/module as networks_module
import communities/tokens/models/token_item
import network_connection/module as network_connection_module
import ../../../app_service/service/contacts/dto/contacts
@ -98,7 +97,6 @@ type
communitiesModule: communities_module.AccessInterface
appSearchModule: app_search_module.AccessInterface
nodeSectionModule: node_section_module.AccessInterface
networksModule: networks_module.AccessInterface
keycardSharedModule: keycard_shared_module.AccessInterface
keycardSharedModuleKeycardSyncPurpose: keycard_shared_module.AccessInterface
networkConnectionModule: network_connection_module.AccessInterface
@ -212,7 +210,6 @@ proc newModule*[T](
result.appSearchModule = app_search_module.newModule(result, events, contactsService, chatService, communityService,
messageService)
result.nodeSectionModule = node_section_module.newModule(result, events, settingsService, nodeService, nodeConfigurationService)
result.networksModule = networks_module.newModule(result, events, networkService, walletAccountService, settingsService)
result.networkConnectionModule = network_connection_module.newModule(result, events, networkConnectionService)
method delete*[T](self: Module[T]) =
@ -228,7 +225,6 @@ method delete*[T](self: Module[T]) =
self.browserSectionModule.delete
self.appSearchModule.delete
self.nodeSectionModule.delete
self.networksModule.delete
if not self.keycardSharedModule.isNil:
self.keycardSharedModule.delete
if not self.keycardSharedModuleKeycardSyncPurpose.isNil:
@ -499,7 +495,6 @@ method load*[T](
self.browserSectionModule.load()
self.profileSectionModule.load()
self.stickersModule.load()
self.networksModule.load()
self.activityCenterModule.load()
self.communitiesModule.load()
self.appSearchModule.load()
@ -667,9 +662,6 @@ proc checkIfModuleDidLoad [T](self: Module[T]) =
if(not self.appSearchModule.isLoaded()):
return
if(not self.networksModule.isLoaded()):
return
if(not self.networkConnectionModule.isLoaded()):
return
@ -709,9 +701,6 @@ method profileSectionDidLoad*[T](self: Module[T]) =
method nodeSectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method networksModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method networkConnectionModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()

View File

@ -16,7 +16,7 @@ method loadForAddingAccount*(self: AccessInterface, addingWatchOnlyAccount: bool
method loadForEditingAccount*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available")
method closeAddAccountPopup*(self: AccessInterface, switchToAccWithAddress: string = "") {.base.} =
method closeAddAccountPopup*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
@ -105,4 +105,4 @@ method buildNewSeedPhraseKeypairAndAddItToOrigin*(self: AccessInterface) {.base.
type
DelegateInterface* = concept c
c.onAddAccountModuleLoaded()
c.destroyAddAccountPopup(string)
c.destroyAddAccountPopup()

View File

@ -169,10 +169,10 @@ proc tryKeycardSync[T](self: Module[T]) =
)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_TRY_KEYCARD_SYNC, dataForKeycardToSync)
method closeAddAccountPopup*[T](self: Module[T], switchToAccWithAddress: string = "") =
method closeAddAccountPopup*[T](self: Module[T]) =
if not self.view.getEditMode():
self.tryKeycardSync()
self.delegate.destroyAddAccountPopup(switchToAccWithAddress)
self.delegate.destroyAddAccountPopup()
method getModuleAsVariant*[T](self: Module[T]): QVariant =
return self.viewVariant
@ -664,10 +664,7 @@ proc doAddAccount[T](self: Module[T]) =
if not success:
error "failed to store account", address=selectedAddrItem.getAddress()
if success:
self.closeAddAccountPopup(address)
else:
self.closeAddAccountPopup()
self.closeAddAccountPopup()
proc doEditAccount[T](self: Module[T]) =
self.view.setDisablePopup(true)
@ -687,7 +684,7 @@ proc doEditAccount[T](self: Module[T]) =
accountName = self.view.getAccountName(),
color = self.view.getSelectedColor(),
emoji = self.view.getSelectedEmoji()):
self.closeAddAccountPopup(address)
self.closeAddAccountPopup()
else:
self.closeAddAccountPopup()

View File

@ -34,18 +34,12 @@ proc delete*(self: Controller) =
proc init*(self: Controller) =
discard
proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts()
proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)
proc getWalletAccountByAddress*(self: Controller, address: string): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getAccountByAddress(address)
proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().map(n => n.chainId)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId)
proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()

View File

@ -11,11 +11,11 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -27,12 +27,8 @@ type
view: View
controller: Controller
moduleLoaded: bool
currentAccountIndex: int
proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool, hasMarketValuesCache: bool)
proc onCurrencyFormatsUpdated(self: Module)
proc onAccountAdded(self: Module, account: WalletAccountDto)
proc onAccountRemoved(self: Module, address: string)
proc onTokensRebuilt(self: Module, hasBalanceCache: bool, hasMarketValuesCache: bool)
proc newModule*(
delegate: delegate_interface.AccessInterface,
@ -45,7 +41,6 @@ proc newModule*(
result = Module()
result.delegate = delegate
result.events = events
result.currentAccountIndex = 0
result.view = newView(result)
result.controller = newController(result, walletAccountService, networkService, tokenService, currencyService)
result.moduleLoaded = false
@ -62,31 +57,10 @@ proc setLoadingAssets(self: Module) =
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAssets", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args):
let args = AccountSaved(e)
self.onAccountAdded(args.account)
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
let args = AccountDeleted(e)
self.onAccountRemoved(args.address)
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
let arg = TokensPerAccountArgs(e)
self.onTokensRebuilt(arg.accountsTokens, arg.hasBalanceCache, arg.hasMarketValuesCache)
self.onTokensRebuilt(arg.hasBalanceCache, arg.hasMarketValuesCache)
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
self.onCurrencyFormatsUpdated()
self.events.on(SIGNAL_NETWORK_DISCONNECTED) do(e: Args):
if self.view.getAssetsModel().getCount() == 0:
self.setLoadingAssets()
@ -106,26 +80,18 @@ method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.assetsModuleDidLoad()
proc setAssetsAndBalance(self: Module, tokens: seq[WalletTokenDto]) =
proc setAssetsAndBalance(self: Module, tokens: seq[WalletTokenDto], enabledChainIds: seq[int]) =
let chainIds = self.controller.getChainIds()
let enabledChainIds = self.controller.getEnabledChainIds()
let currency = self.controller.getCurrentCurrency()
let currencyFormat = self.controller.getCurrencyFormat(currency)
let items = tokens.map(t => walletTokenToItem(t, chainIds, enabledChainIds, currency, currencyFormat, self.controller.getCurrencyFormat(t.symbol)))
let totalCurrencyBalanceForAllAssets = tokens.map(t => t.getCurrencyBalance(enabledChainIds, currency)).foldl(a + b, 0.0)
self.view.getAssetsModel().setItems(items)
method switchAccount*(self: Module, accountIndex: int) =
var walletAccount = self.controller.getWalletAccount(accountIndex)
self.currentAccountIndex = accountIndex
if walletAccount.isNil:
self.currentAccountIndex = 0
walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
let walletAccount = self.controller.getWalletAccountByAddress(addresses[0])
let accountItem = walletAccountToWalletAssetsItem(walletAccount)
self.view.setData(accountItem)
@ -133,25 +99,8 @@ method switchAccount*(self: Module, accountIndex: int) =
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
self.setLoadingAssets()
else:
self.setAssetsAndBalance(walletAccount.tokens)
self.setAssetsAndBalance(walletAccount.tokens, chainIds)
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):
return
proc onTokensRebuilt(self: Module, hasBalanceCache: bool, hasMarketValuesCache: bool) =
self.view.setAssetsLoading(false)
self.setAssetsAndBalance(accountsTokens[walletAccount.address])
self.view.setCacheValues(hasBalanceCache, hasMarketValuesCache)
proc onCurrencyFormatsUpdated(self: Module) =
let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
self.setLoadingAssets()
else:
self.setAssetsAndBalance(walletAccount.tokens)
proc onAccountAdded(self: Module, account: WalletAccountDto) =
self.switchAccount(self.currentAccountIndex)
proc onAccountRemoved(self: Module, address: string) =
self.switchAccount(self.currentAccountIndex)
self.view.setCacheValues(hasBalanceCache, hasMarketValuesCache)

View File

@ -69,8 +69,8 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_REFRESH_COLLECTIBLES) do(e:Args):
self.collectibleService.refetchAllOwnedCollectibles()
proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)
proc getWalletAccountByAddress*(self: Controller, address: string): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getAccountByAddress(address)
proc getNetwork*(self: Controller): network_service.NetworkDto =
return self.networkService.getNetworkForCollectibles()

View File

@ -13,7 +13,7 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} =
raise newException(ValueError, "No implementation available")
method fetchOwnedCollectibles*(self: AccessInterface) {.base.} =

View File

@ -27,10 +27,11 @@ type
controller: Controller
moduleLoaded: bool
currentCollectibleModule: current_collectible_module.AccessInterface
chainId: int
address: string
currentCollectibleModule: current_collectible_module.AccessInterface
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
@ -45,6 +46,8 @@ proc newModule*(
result.view = newView(result)
result.controller = newController(result, events, collectibleService, walletAccountService, networkService, nodeService, networkConnectionService)
result.moduleLoaded = false
result.chainId = 0
result.address = ""
result.currentCollectibleModule = currentCollectibleModule.newModule(result, collectibleService)
method delete*(self: Module) =
@ -80,13 +83,11 @@ method currentCollectibleModuleDidLoad*(self: Module) =
method fetchOwnedCollectibles*(self: Module) =
self.controller.fetchOwnedCollectibles(self.chainId, self.address)
method switchAccount*(self: Module, accountIndex: int) =
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
let network = self.controller.getNetwork()
let account = self.controller.getWalletAccount(accountIndex)
let account = self.controller.getWalletAccountByAddress(addresses[0])
self.chainId = network.chainId
self.address = account.address
self.currentCollectibleModule.setCurrentAddress(network, self.address)
let data = self.controller.getOwnedCollectibles(self.chainId, self.address)

View File

@ -1,7 +1,9 @@
import sequtils, sugar
import io_interface
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 ../../../../app_service/service/network/service as network_service
import ../../shared/wallet_utils
import ../../shared_models/currency_amount
@ -12,18 +14,21 @@ type
settingsService: settings_service.Service
walletAccountService: wallet_account_service.Service
currencyService: currency_service.Service
networkService: network_service.Service
proc newController*(
delegate: io_interface.AccessInterface,
settingsService: settings_service.Service,
walletAccountService: wallet_account_service.Service,
currencyService: currency_service.Service,
networkService: network_service.Service
): Controller =
result = Controller()
result.delegate = delegate
result.settingsService = settingsService
result.walletAccountService = walletAccountService
result.currencyService = currencyService
result.networkService = networkService
proc delete*(self: Controller) =
discard
@ -49,5 +54,14 @@ proc getCurrencyAmount*(self: Controller, amount: float64, symbol: string): Curr
proc updateCurrency*(self: Controller, currency: string) =
self.walletAccountService.updateCurrency(currency)
proc getIndex*(self: Controller, address: string): int =
return self.walletAccountService.getIndex(address)
# proc getIndex*(self: Controller, address: string): int =
# return self.walletAccountService.getIndex(address)
proc getNetworks*(self: Controller): seq[NetworkDto] =
return self.networkService.getNetworks()
proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts()
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId)

View File

@ -0,0 +1,44 @@
import strformat
import ./controller
type Filter* = ref object
controller: Controller
addresses*: seq[string]
chainIds*: seq[int]
proc initFilter*(
controller: Controller,
): Filter =
result = Filter()
result.controller = controller
result.addresses = @[]
result.chainIds = @[]
proc `$`*(self: Filter): string =
result = fmt"""WalletFilter(
addresses: {self.addresses},
chainIds: {self.chainIds},
)"""
proc load*(self: Filter) =
let accounts = self.controller.getWalletAccounts()
self.addresses = @[accounts[0].address]
self.chainIds = self.controller.getEnabledChainIds()
proc setAddress*(self: Filter, address: string) =
self.addresses = @[address]
proc removeAddress*(self: Filter, address: string) =
if len(self.addresses) == 1 and self.addresses[0] == address:
let accounts = self.controller.getWalletAccounts()
self.addresses = @[accounts[0].address]
return
self.addresses.delete(self.addresses.find(address))
proc updateNetworks*(self: Filter) =
self.chainIds = self.controller.getEnabledChainIds()

View File

@ -15,10 +15,7 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccountByAddress*(self: AccessInterface, address: string) {.base.} =
method setFilterAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available")
method updateCurrency*(self: AccessInterface, currency: string) {.base.} =
@ -52,6 +49,9 @@ method assetsModuleDidLoad*(self: AccessInterface) {.base.} =
method transactionsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method networksModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method savedAddressesModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
@ -76,5 +76,5 @@ method getAddAccountModule*(self: AccessInterface): QVariant {.base.} =
method onAddAccountModuleLoaded*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method destroyAddAccountPopup*(self: AccessInterface, switchToAccWithAddress: string = "") {.base.} =
method destroyAddAccountPopup*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,6 @@
import NimQml, chronicles
import ./controller, ./view
import ./controller, ./view, ./filter
import ./io_interface as io_interface
import ../io_interface as delegate_interface
@ -12,6 +12,7 @@ import ./transactions/module as transactions_module
import ./saved_addresses/module as saved_addresses_module
import ./buy_sell_crypto/module as buy_sell_crypto_module
import ./add_account/module as add_account_module
import ./networks/module as networks_module
import ./overview/module as overview_module
import ./send/module as send_module
@ -43,6 +44,7 @@ type
moduleLoaded: bool
controller: Controller
view: View
filter: Filter
accountsModule: accounts_module.AccessInterface
allTokensModule: all_tokens_module.AccessInterface
@ -54,6 +56,7 @@ type
buySellCryptoModule: buy_sell_crypto_module.AccessInterface
addAccountModule: add_account_module.AccessInterface
overviewModule: overview_module.AccessInterface
networksModule: networks_module.AccessInterface
keycardService: keycard_service.Service
accountsService: accounts_service.Service
walletAccountService: wallet_account_service.Service
@ -81,7 +84,7 @@ proc newModule*(
result.accountsService = accountsService
result.walletAccountService = walletAccountService
result.moduleLoaded = false
result.controller = newController(result, settingsService, walletAccountService, currencyService)
result.controller = newController(result, settingsService, walletAccountService, currencyService, networkService)
result.view = newView(result)
result.accountsModule = accounts_module.newModule(result, events, walletAccountService, networkService, currencyService)
@ -92,7 +95,9 @@ proc newModule*(
result.sendModule = send_module.newModule(result, events, walletAccountService, networkService, currencyService, transactionService)
result.savedAddressesModule = saved_addresses_module.newModule(result, events, savedAddressService)
result.buySellCryptoModule = buy_sell_crypto_module.newModule(result, events, transactionService)
result.overviewModule = overview_module.newModule(result, events, walletAccountService, networkService, currencyService)
result.overviewModule = overview_module.newModule(result, events, walletAccountService, currencyService)
result.networksModule = networks_module.newModule(result, events, networkService, walletAccountService, settingsService)
result.filter = initFilter(result.controller)
method delete*(self: Module) =
self.accountsModule.delete
@ -105,46 +110,59 @@ method delete*(self: Module) =
self.sendModule.delete
self.controller.delete
self.view.delete
if not self.addAccountModule.isNil:
self.addAccountModule.delete
method updateCurrency*(self: Module, currency: string) =
self.controller.updateCurrency(currency)
method switchAccount*(self: Module, accountIndex: int) =
self.assetsModule.switchAccount(accountIndex)
self.collectiblesModule.switchAccount(accountIndex)
self.transactionsModule.switchAccount(accountIndex)
self.overviewModule.switchAccount(accountIndex)
self.sendModule.switchAccount(accountIndex)
method switchAccountByAddress*(self: Module, address: string) =
let accountIndex = self.controller.getIndex(address)
self.switchAccount(accountIndex)
method setTotalCurrencyBalance*(self: Module) =
self.view.setTotalCurrencyBalance(self.controller.getCurrencyBalance())
method notifyFilterChanged(self: Module) =
self.overviewModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.assetsModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.collectiblesModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.transactionsModule.filterChanged(self.filter.addresses, self.filter.chainIds)
method getCurrencyAmount*(self: Module, amount: float64, symbol: string): CurrencyAmount =
return self.controller.getCurrencyAmount(amount, symbol)
method setFilterAddress*(self: Module, address: string) =
self.filter.setAddress(address)
self.notifyFilterChanged()
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSection", newQVariant(self.view))
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args):
let args = AccountSaved(e)
self.setTotalCurrencyBalance()
self.filter.setAddress(args.account.address)
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
self.switchAccount(0)
let args = AccountDeleted(e)
self.setTotalCurrencyBalance()
self.filter.removeAddress(args.address)
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.view.setCurrentCurrency(self.controller.getCurrency())
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e:Args):
self.filter.updateNetworks()
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
self.controller.init()
self.view.load()
@ -157,6 +175,7 @@ method load*(self: Module) =
self.buySellCryptoModule.load()
self.overviewModule.load()
self.sendModule.load()
self.networksModule.load()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
@ -189,13 +208,16 @@ proc checkIfModuleDidLoad(self: Module) =
if(not self.sendModule.isLoaded()):
return
self.switchAccount(0)
if(not self.networksModule.isLoaded()):
return
let currency = self.controller.getCurrency()
let signingPhrase = self.controller.getSigningPhrase()
let mnemonicBackedUp = self.controller.isMnemonicBackedUp()
self.view.setData(currency, signingPhrase, mnemonicBackedUp)
self.setTotalCurrencyBalance()
self.filter.load()
self.notifyFilterChanged()
self.moduleLoaded = true
self.delegate.walletSectionDidLoad()
@ -229,13 +251,16 @@ method overviewModuleDidLoad*(self: Module) =
method sendModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method destroyAddAccountPopup*(self: Module, switchToAccWithAddress: string = "") =
if not self.addAccountModule.isNil:
if switchToAccWithAddress.len > 0:
self.switchAccountByAddress(switchToAccWithAddress)
self.view.emitDestroyAddAccountPopup()
self.addAccountModule.delete
self.addAccountModule = nil
method networksModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method destroyAddAccountPopup*(self: Module) =
if self.addAccountModule.isNil:
return
self.view.emitDestroyAddAccountPopup()
self.addAccountModule.delete
self.addAccountModule = nil
method runAddAccountPopup*(self: Module, addingWatchOnlyAccount: bool) =
self.destroyAddAccountPopup()

View File

@ -1,7 +1,7 @@
import ../../../core/eventemitter
import ../../../../app_service/service/network/service as network_service
import ../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../app_service/service/settings/service as settings_service
import ../../../../core/eventemitter
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/settings/service as settings_service
import ./io_interface
@ -34,9 +34,6 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
self.delegate.refreshNetworks()
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
self.delegate.refreshNetworks()
proc getNetworks*(self: Controller): seq[NetworkDto] =
return self.networkService.getNetworks()
@ -44,10 +41,4 @@ proc setNetworksState*(self: Controller, chainIds: seq[int], enabled: bool) =
self.walletAccountService.setNetworksState(chainIds, enabled)
proc areTestNetworksEnabled*(self: Controller): bool =
return self.settingsService.areTestNetworksEnabled()
proc toggleTestNetworksEnabled*(self: Controller) =
self.walletAccountService.toggleTestNetworksEnabled()
proc getNetworkCurrencyBalance*(self: Controller, network: NetworkDto): float64 =
return self.walletAccountService.getNetworkCurrencyBalance(network)
return self.settingsService.areTestNetworksEnabled()

View File

@ -23,7 +23,4 @@ method setNetworksState*(self: AccessInterface, chainIds: seq[int], enable: bool
raise newException(ValueError, "No implementation available")
method refreshNetworks*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleTestNetworksEnabled*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -21,7 +21,6 @@ type
iconUrl: string
chainColor: string
shortName: string
balance: float64
enabledState: UxEnabledState
proc initItem*(
@ -38,7 +37,6 @@ proc initItem*(
iconUrl: string,
chainColor: string,
shortName: string,
balance: float64,
enabledState: UxEnabledState,
): Item =
result.chainId = chainId
@ -54,7 +52,6 @@ proc initItem*(
result.iconUrl = iconUrl
result.chainColor = chainColor
result.shortName = shortName
result.balance = balance
result.enabledState = enabledState
proc `$`*(self: Item): string =
@ -72,7 +69,6 @@ proc `$`*(self: Item): string =
iconUrl:{self.iconUrl},
shortName: {self.shortName},
chainColor: {self.chainColor},
balance: {self.balance},
enabledState: {self.enabledState}
]"""
@ -115,8 +111,5 @@ proc getShortName*(self: Item): string =
proc getChainColor*(self: Item): string =
return self.chainColor
proc getBalance*(self: Item): float64 =
return self.balance
proc getEnabledState*(self: Item): UxEnabledState =
return self.enabledState

View File

@ -19,7 +19,6 @@ type
IconUrl
ChainColor
ShortName
Balance
EnabledState
QtObject:
@ -69,7 +68,6 @@ QtObject:
ModelRole.IconUrl.int:"iconUrl",
ModelRole.ShortName.int: "shortName",
ModelRole.ChainColor.int: "chainColor",
ModelRole.Balance.int: "balance",
ModelRole.EnabledState.int: "enabledState",
}.toTable
@ -110,8 +108,6 @@ QtObject:
result = newQVariant(item.getShortName())
of ModelRole.ChainColor:
result = newQVariant(item.getChainColor())
of ModelRole.Balance:
result = newQVariant(item.getBalance())
of ModelRole.EnabledState:
result = newQVariant(item.getEnabledState().int)
@ -133,7 +129,6 @@ QtObject:
of "iconUrl": result = $item.getIconURL()
of "chainColor": result = $item.getChainColor()
of "shortName": result = $item.getShortName()
of "balance": result = $item.getBalance()
of "enabledState": result = $item.getEnabledState().int
proc setItems*(self: Model, items: seq[Item]) =

View File

@ -1,11 +1,11 @@
import Tables, NimQml
import ../io_interface as delegate_interface
import io_interface, view, controller
import ../../../global/global_singleton
import ../../../core/eventemitter
import ../../../../app_service/service/network/service as network_service
import ../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../app_service/service/settings/service as settings_service
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/settings/service as settings_service
export io_interface
@ -39,20 +39,19 @@ method delete*(self: Module) =
self.controller.delete
method refreshNetworks*(self: Module) =
let networks = newTable[NetworkDto, float64]()
for network in self.controller.getNetworks():
networks[network] = self.controller.getNetworkCurrencyBalance(network)
self.view.load(networks)
self.view.setAreTestNetworksEnabled(self.controller.areTestNetworksEnabled())
self.view.load(self.controller.getNetworks())
method load*(self: Module) =
self.controller.init()
self.view.setAreTestNetworksEnabled(self.controller.areTestNetworksEnabled())
self.refreshNetworks()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method areTestNetworksEnabled*(self: Module): bool =
return self.controller.areTestNetworksEnabled()
proc checkIfModuleDidLoad(self: Module) =
self.moduleLoaded = true
self.delegate.networksModuleDidLoad()
@ -61,11 +60,4 @@ method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method setNetworksState*(self: Module, chainIds: seq[int], enabled: bool) =
self.controller.setNetworksState(chainIds, enabled)
method areTestNetworksEnabled*(self: Module): bool =
return self.controller.areTestNetworksEnabled()
method toggleTestNetworksEnabled*(self: Module) =
self.controller.toggleTestNetworksEnabled()
self.refreshNetworks()
self.controller.setNetworksState(chainIds, enabled)

View File

@ -1,6 +1,7 @@
import Tables, NimQml, sequtils, sugar
import ../../../../app_service/service/network/dto
import ../../../../../app_service/service/network/dto
import ./io_interface
import ./model
import ./item
@ -82,10 +83,10 @@ QtObject:
read = getEnabled
notify = enabledChanged
proc load*(self: View, networks: TableRef[NetworkDto, float64]) =
proc load*(self: View, networks: seq[NetworkDto]) =
var items: seq[Item] = @[]
let allEnabled = areAllEnabled(toSeq(networks.keys))
for n, balance in networks.pairs:
let allEnabled = areAllEnabled(networks)
for n in networks:
items.add(initItem(
n.chainId,
n.nativeCurrencyDecimals,
@ -100,7 +101,6 @@ QtObject:
n.iconUrl,
n.chainColor,
n.shortName,
balance,
# Ensure we mark all as enabled if all are enabled
networkEnabledToUxEnabledState(n.enabled, allEnabled)
))
@ -121,11 +121,6 @@ QtObject:
let (chainIds, enable) = self.all.networksToChangeStateOnUserActionFor(chainId)
self.delegate.setNetworksState(chainIds, enable)
proc toggleTestNetworksEnabled*(self: View) {.slot.} =
self.delegate.toggleTestNetworksEnabled()
self.areTestNetworksEnabled = not self.areTestNetworksEnabled
self.areTestNetworksEnabledChanged()
proc getMainnetChainId*(self: View): int {.slot.} =
return self.layer1.getLayer1Network(self.areTestNetworksEnabled)
@ -138,4 +133,4 @@ proc networkEnabledToUxEnabledState(enabled: bool, allEnabled: bool): UxEnabledS
UxEnabledState.Disabled
proc areAllEnabled(networks: seq[NetworkDto]): bool =
return networks.allIt(it.enabled)
return networks.allIt(it.enabled)

View File

@ -1,26 +1,22 @@
import sugar, sequtils
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/currency/service as currency_service
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.Service
networkService: network_service.Service
currencyService: currency_service.Service
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service,
currencyService: currency_service.Service,
): Controller =
result = Controller()
result.delegate = delegate
result.walletAccountService = walletAccountService
result.networkService = networkService
result.currencyService = currencyService
proc delete*(self: Controller) =
@ -29,11 +25,8 @@ proc delete*(self: Controller) =
proc init*(self: Controller) =
discard
proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId)
proc getWalletAccountByAddress*(self: Controller, address: string): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getAccountByAddress(address)
proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()

View File

@ -11,11 +11,11 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -9,6 +9,7 @@ import ../../../shared/wallet_utils
import ../../../shared_models/currency_amount
import ./item
import ../filter
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
@ -21,26 +22,18 @@ type
view: View
controller: Controller
moduleLoaded: bool
currentAccountIndex: int
proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]])
proc onCurrencyFormatsUpdated(self: Module)
proc onAccountAdded(self: Module, account: WalletAccountDto)
proc onAccountRemoved(self: Module, address: string)
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service,
currencyService: currency_service.Service,
): Module =
result = Module()
result.delegate = delegate
result.events = events
result.currentAccountIndex = 0
result.view = newView(result)
result.controller = newController(result, walletAccountService, networkService, currencyService)
result.controller = newController(result, walletAccountService, currencyService)
result.moduleLoaded = false
method delete*(self: Module) =
@ -48,32 +41,6 @@ method delete*(self: Module) =
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionOverview", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args):
let args = AccountSaved(e)
self.onAccountAdded(args.account)
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
let args = AccountDeleted(e)
self.onAccountRemoved(args.address)
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
let arg = TokensPerAccountArgs(e)
self.onTokensRebuilt(arg.accountsTokens)
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
self.onCurrencyFormatsUpdated()
self.controller.init()
self.view.load()
@ -85,22 +52,16 @@ method viewDidLoad*(self: Module) =
self.view.setCurrencyBalance(newCurrencyAmount())
self.delegate.overviewModuleDidLoad()
proc setBalance(self: Module, tokens: seq[WalletTokenDto]) =
let enabledChainIds = self.controller.getEnabledChainIds()
proc setBalance(self: Module, tokens: seq[WalletTokenDto], chainIds: seq[int]) =
let currency = self.controller.getCurrentCurrency()
let currencyFormat = self.controller.getCurrencyFormat(currency)
let totalCurrencyBalanceForAllAssets = tokens.map(t => t.getCurrencyBalance(enabledChainIds, currency)).foldl(a + b, 0.0)
let totalCurrencyBalanceForAllAssets = tokens.map(t => t.getCurrencyBalance(chainIds, currency)).foldl(a + b, 0.0)
self.view.setCurrencyBalance(currencyAmountToItem(totalCurrencyBalanceForAllAssets, currencyFormat))
# TODO(alaibe): replace with filter logic
method switchAccount*(self: Module, accountIndex: int) =
var walletAccount = self.controller.getWalletAccount(accountIndex)
self.currentAccountIndex = accountIndex
if walletAccount.isNil:
self.currentAccountIndex = 0
walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
let walletAccount = self.controller.getWalletAccountByAddress(addresses[0])
let item = initItem(
walletAccount.name,
walletAccount.mixedCaseAddress,
@ -114,25 +75,4 @@ method switchAccount*(self: Module, accountIndex: int) =
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
self.view.setCurrencyBalance(newCurrencyAmount())
else:
self.setBalance(walletAccount.tokens)
proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]]) =
let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
if not accountsTokens.contains(walletAccount.address):
return
self.setBalance(accountsTokens[walletAccount.address])
self.view.setBalanceLoading(false)
proc onCurrencyFormatsUpdated(self: Module) =
let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex)
if walletAccount.tokens.len == 0 and walletAccount.assetsLoading:
self.view.setCurrencyBalance(newCurrencyAmount())
return
self.setBalance(walletAccount.tokens)
proc onAccountAdded(self: Module, account: WalletAccountDto) =
self.switchAccount(self.currentAccountIndex)
proc onAccountRemoved(self: Module, address: string) =
self.switchAccount(self.currentAccountIndex)
self.setBalance(walletAccount.tokens, chainIds)

View File

@ -94,8 +94,8 @@ proc getPendingTransactions*(self: Controller): seq[TransactionDto] =
proc getWalletAccounts*(self: Controller): seq[WalletAccountDto] =
self.walletAccountService.getWalletAccounts()
proc getWalletAccount*(self: Controller, accountIndex: int): WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)
proc getWalletAccountByAddress*(self: Controller, address: string): WalletAccountDto =
return self.walletAccountService.getAccountByAddress(address)
proc loadTransactions*(self: Controller, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false) =
self.transactionService.loadTransactions(address, toBlock, limit, loadMore)

View File

@ -16,7 +16,7 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} =
raise newException(ValueError, "No implementation available")
method getWalletAccounts*(self: AccessInterface): seq[WalletAccountDto] {.base.} =

View File

@ -114,8 +114,8 @@ method viewDidLoad*(self: Module) =
self.setEnabledChainIds()
self.setPendingTx()
method switchAccount*(self: Module, accountIndex: int) =
let walletAccount = self.controller.getWalletAccount(accountIndex)
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
let walletAccount = self.controller.getWalletAccountByAddress(addresses[0])
self.view.switchAccount(walletAccount)
method loadTransactions*(self: Module, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) =

View File

@ -63,11 +63,8 @@ QtObject:
QtProperty[QVariant] isMnemonicBackedUp:
read = getIsMnemonicBackedUp
proc switchAccount(self: View, accountIndex: int) {.slot.} =
self.delegate.switchAccount(accountIndex)
proc switchAccountByAddress(self: View, address: string) {.slot.} =
self.delegate.switchAccountByAddress(address)
proc setFilterAddress(self: View, address: string) {.slot.} =
self.delegate.setFilterAddress(address)
proc setTotalCurrencyBalance*(self: View, totalCurrencyBalance: CurrencyAmount) =
self.totalCurrencyBalance = totalCurrencyBalance

View File

@ -210,8 +210,8 @@ SplitView {
}
walletStore: QtObject {
function switchAccountByAddress(address) {
logs.logEvent("walletStore::switchAccountByAddress", ["address"], arguments)
function setFilterAddress(address) {
logs.logEvent("walletStore::setFilterAddress", ["address"], arguments)
}
function selectCollectible(slug, id) {

View File

@ -598,13 +598,6 @@ QtObject {
return globalUtilsInst.eth2Wei(eth, 18)
}
function switchAccount(newIndex) {
if(Constants.isCppApp)
walletSectionAccounts.switchAccount(newIndex)
else
walletSection.switchAccount(newIndex)
}
function getEtherscanLink() {
return profileSectionModule.ensUsernamesModule.getEtherscanLink()
}

View File

@ -85,11 +85,8 @@ Item {
leftPanel: LeftTabView {
id: leftTab
anchors.fill: parent
changeSelectedAccount: function(newIndex) {
if (newIndex > RootStore.accounts) {
return
}
RootStore.switchAccount(newIndex)
changeSelectedAccount: function(address) {
RootStore.setFilterAddress(address)
}
onShowSavedAddressesChanged: {

View File

@ -127,12 +127,9 @@ QtObject {
// walletModel.setInitialRange()
}
function switchAccount(newIndex) {
walletSection.switchAccount(newIndex)
}
function switchAccountByAddress(address) {
walletSection.switchAccountByAddress(address)
function setFilterAddress(address) {
walletSection.setFilterAddress(address)
}
function deleteAccount(keyUid, address) {

View File

@ -268,7 +268,7 @@ Rectangle {
accountContextMenu.item.popup(mouse.x, mouse.y)
return
}
changeSelectedAccount(index)
changeSelectedAccount(model.address)
showSavedAddresses = false
}
components: [

View File

@ -145,13 +145,6 @@ QtObject {
mainModuleInst.setActiveSectionById(communityId);
}
function switchAccount(newIndex) {
if(Constants.isCppApp)
walletSectionAccounts.switchAccount(newIndex)
else
walletSection.switchAccount(newIndex)
}
function resolveENS(value) {
mainModuleInst.resolveENS(value, "")
}

View File

@ -100,13 +100,6 @@ QtObject {
return globalUtils.hex2Eth(value)
}
function switchAccount(newIndex) {
if(Constants.isCppApp)
walletSectionAccounts.switchAccount(newIndex)
else
walletSection.switchAccount(newIndex)
}
function resolveENS(value) {
mainModuleInst.resolveENS(value, "")
}

View File

@ -199,7 +199,6 @@ Control {
icon.name: "send"
tooltip.text: qsTr("Send")
onClicked: {
root.walletStore.switchAccountByAddress(model.address)
Global.openSendModal(model.address)
}
},
@ -220,7 +219,7 @@ Control {
onClicked: {
if (root.readOnly)
return
root.walletStore.switchAccountByAddress(model.address)
root.walletStore.setFilterAddress(model.address)
}
}
}