From 39b9b5ee91d5f0038233d2040f4b5c31fc08f4fa Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 27 Apr 2023 15:22:27 +0200 Subject: [PATCH] feat(@wallet): add wallet filter --- src/app/modules/main/io_interface.nim | 3 - src/app/modules/main/module.nim | 11 --- .../add_account/io_interface.nim | 4 +- .../wallet_section/add_account/module.nim | 11 +-- .../main/wallet_section/assets/controller.nim | 10 +-- .../wallet_section/assets/io_interface.nim | 6 +- .../main/wallet_section/assets/module.nim | 67 ++-------------- .../collectibles/controller.nim | 4 +- .../collectibles/io_interface.nim | 2 +- .../wallet_section/collectibles/module.nim | 11 +-- .../main/wallet_section/controller.nim | 18 ++++- .../modules/main/wallet_section/filter.nim | 44 +++++++++++ .../main/wallet_section/io_interface.nim | 10 +-- .../modules/main/wallet_section/module.nim | 73 ++++++++++++------ .../networks/controller.nim | 19 ++--- .../networks/io_interface.nim | 3 - .../{ => wallet_section}/networks/item.nim | 7 -- .../{ => wallet_section}/networks/model.nim | 5 -- .../{ => wallet_section}/networks/module.nim | 30 +++----- .../{ => wallet_section}/networks/view.nim | 17 ++--- .../wallet_section/overview/controller.nim | 11 +-- .../wallet_section/overview/io_interface.nim | 6 +- .../main/wallet_section/overview/module.nim | 76 ++----------------- .../transactions/controller.nim | 4 +- .../transactions/io_interface.nim | 2 +- .../wallet_section/transactions/module.nim | 4 +- src/app/modules/main/wallet_section/view.nim | 7 +- storybook/pages/ProfileDialogViewPage.qml | 4 +- ui/app/AppLayouts/Chat/stores/RootStore.qml | 7 -- ui/app/AppLayouts/Wallet/WalletLayout.qml | 7 +- ui/app/AppLayouts/Wallet/stores/RootStore.qml | 7 +- .../AppLayouts/Wallet/views/LeftTabView.qml | 2 +- ui/app/AppLayouts/stores/RootStore.qml | 7 -- ui/imports/shared/stores/TransactionStore.qml | 7 -- .../views/profile/ProfileShowcaseView.qml | 3 +- 35 files changed, 192 insertions(+), 317 deletions(-) create mode 100644 src/app/modules/main/wallet_section/filter.nim rename src/app/modules/main/{ => wallet_section}/networks/controller.nim (64%) rename src/app/modules/main/{ => wallet_section}/networks/io_interface.nim (83%) rename src/app/modules/main/{ => wallet_section}/networks/item.nim (94%) rename src/app/modules/main/{ => wallet_section}/networks/model.nim (97%) rename src/app/modules/main/{ => wallet_section}/networks/module.nim (70%) rename src/app/modules/main/{ => wallet_section}/networks/view.nim (88%) diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 4dcc878a5a..7f9781d4b8 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -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") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index a553593d74..adaba1137c 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -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() diff --git a/src/app/modules/main/wallet_section/add_account/io_interface.nim b/src/app/modules/main/wallet_section/add_account/io_interface.nim index ab26f4e9ec..d3c1246dcc 100644 --- a/src/app/modules/main/wallet_section/add_account/io_interface.nim +++ b/src/app/modules/main/wallet_section/add_account/io_interface.nim @@ -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) \ No newline at end of file + c.destroyAddAccountPopup() \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/add_account/module.nim b/src/app/modules/main/wallet_section/add_account/module.nim index 426c812a3e..cafe3b5834 100644 --- a/src/app/modules/main/wallet_section/add_account/module.nim +++ b/src/app/modules/main/wallet_section/add_account/module.nim @@ -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() diff --git a/src/app/modules/main/wallet_section/assets/controller.nim b/src/app/modules/main/wallet_section/assets/controller.nim index 31023849e4..a51d31ac4e 100644 --- a/src/app/modules/main/wallet_section/assets/controller.nim +++ b/src/app/modules/main/wallet_section/assets/controller.nim @@ -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() diff --git a/src/app/modules/main/wallet_section/assets/io_interface.nim b/src/app/modules/main/wallet_section/assets/io_interface.nim index e6e5627585..06b942cce1 100644 --- a/src/app/modules/main/wallet_section/assets/io_interface.nim +++ b/src/app/modules/main/wallet_section/assets/io_interface.nim @@ -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") \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/assets/module.nim b/src/app/modules/main/wallet_section/assets/module.nim index 544ae04bf7..b77e12c03e 100644 --- a/src/app/modules/main/wallet_section/assets/module.nim +++ b/src/app/modules/main/wallet_section/assets/module.nim @@ -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) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/controller.nim b/src/app/modules/main/wallet_section/collectibles/controller.nim index 14b6c00961..a63dad996f 100644 --- a/src/app/modules/main/wallet_section/collectibles/controller.nim +++ b/src/app/modules/main/wallet_section/collectibles/controller.nim @@ -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() diff --git a/src/app/modules/main/wallet_section/collectibles/io_interface.nim b/src/app/modules/main/wallet_section/collectibles/io_interface.nim index 01609a61c3..00b7d3a08b 100644 --- a/src/app/modules/main/wallet_section/collectibles/io_interface.nim +++ b/src/app/modules/main/wallet_section/collectibles/io_interface.nim @@ -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.} = diff --git a/src/app/modules/main/wallet_section/collectibles/module.nim b/src/app/modules/main/wallet_section/collectibles/module.nim index 5eef295229..171e117f17 100644 --- a/src/app/modules/main/wallet_section/collectibles/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/module.nim @@ -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) diff --git a/src/app/modules/main/wallet_section/controller.nim b/src/app/modules/main/wallet_section/controller.nim index c72938bc0f..f1eb75daa5 100644 --- a/src/app/modules/main/wallet_section/controller.nim +++ b/src/app/modules/main/wallet_section/controller.nim @@ -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) \ No newline at end of file +# 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) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/filter.nim b/src/app/modules/main/wallet_section/filter.nim new file mode 100644 index 0000000000..7d29831366 --- /dev/null +++ b/src/app/modules/main/wallet_section/filter.nim @@ -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() \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/io_interface.nim b/src/app/modules/main/wallet_section/io_interface.nim index e0b35771db..01ef2bb9df 100644 --- a/src/app/modules/main/wallet_section/io_interface.nim +++ b/src/app/modules/main/wallet_section/io_interface.nim @@ -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") \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index 43099ea5a9..b8827fffc7 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -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() diff --git a/src/app/modules/main/networks/controller.nim b/src/app/modules/main/wallet_section/networks/controller.nim similarity index 64% rename from src/app/modules/main/networks/controller.nim rename to src/app/modules/main/wallet_section/networks/controller.nim index dd8a3bb50e..8f0fe1ab66 100644 --- a/src/app/modules/main/networks/controller.nim +++ b/src/app/modules/main/wallet_section/networks/controller.nim @@ -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) \ No newline at end of file + return self.settingsService.areTestNetworksEnabled() \ No newline at end of file diff --git a/src/app/modules/main/networks/io_interface.nim b/src/app/modules/main/wallet_section/networks/io_interface.nim similarity index 83% rename from src/app/modules/main/networks/io_interface.nim rename to src/app/modules/main/wallet_section/networks/io_interface.nim index 7d44b2f19e..d1c94efee8 100644 --- a/src/app/modules/main/networks/io_interface.nim +++ b/src/app/modules/main/wallet_section/networks/io_interface.nim @@ -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") \ No newline at end of file diff --git a/src/app/modules/main/networks/item.nim b/src/app/modules/main/wallet_section/networks/item.nim similarity index 94% rename from src/app/modules/main/networks/item.nim rename to src/app/modules/main/wallet_section/networks/item.nim index 91549ade56..242dce6b0f 100644 --- a/src/app/modules/main/networks/item.nim +++ b/src/app/modules/main/wallet_section/networks/item.nim @@ -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 diff --git a/src/app/modules/main/networks/model.nim b/src/app/modules/main/wallet_section/networks/model.nim similarity index 97% rename from src/app/modules/main/networks/model.nim rename to src/app/modules/main/wallet_section/networks/model.nim index a33743ddc2..f5daf1f291 100644 --- a/src/app/modules/main/networks/model.nim +++ b/src/app/modules/main/wallet_section/networks/model.nim @@ -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]) = diff --git a/src/app/modules/main/networks/module.nim b/src/app/modules/main/wallet_section/networks/module.nim similarity index 70% rename from src/app/modules/main/networks/module.nim rename to src/app/modules/main/wallet_section/networks/module.nim index 414632e92c..70a948f471 100644 --- a/src/app/modules/main/networks/module.nim +++ b/src/app/modules/main/wallet_section/networks/module.nim @@ -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() \ No newline at end of file + self.controller.setNetworksState(chainIds, enabled) \ No newline at end of file diff --git a/src/app/modules/main/networks/view.nim b/src/app/modules/main/wallet_section/networks/view.nim similarity index 88% rename from src/app/modules/main/networks/view.nim rename to src/app/modules/main/wallet_section/networks/view.nim index 625afb223c..c05a3a27f7 100644 --- a/src/app/modules/main/networks/view.nim +++ b/src/app/modules/main/wallet_section/networks/view.nim @@ -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) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/overview/controller.nim b/src/app/modules/main/wallet_section/overview/controller.nim index 0f424715f9..1e392f25d7 100644 --- a/src/app/modules/main/wallet_section/overview/controller.nim +++ b/src/app/modules/main/wallet_section/overview/controller.nim @@ -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() diff --git a/src/app/modules/main/wallet_section/overview/io_interface.nim b/src/app/modules/main/wallet_section/overview/io_interface.nim index e6e5627585..b8ebd4ec40 100644 --- a/src/app/modules/main/wallet_section/overview/io_interface.nim +++ b/src/app/modules/main/wallet_section/overview/io_interface.nim @@ -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") diff --git a/src/app/modules/main/wallet_section/overview/module.nim b/src/app/modules/main/wallet_section/overview/module.nim index a1e8a6319d..1e0d7b4e8f 100644 --- a/src/app/modules/main/wallet_section/overview/module.nim +++ b/src/app/modules/main/wallet_section/overview/module.nim @@ -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) diff --git a/src/app/modules/main/wallet_section/transactions/controller.nim b/src/app/modules/main/wallet_section/transactions/controller.nim index 322e979235..fd8b2d517a 100644 --- a/src/app/modules/main/wallet_section/transactions/controller.nim +++ b/src/app/modules/main/wallet_section/transactions/controller.nim @@ -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) diff --git a/src/app/modules/main/wallet_section/transactions/io_interface.nim b/src/app/modules/main/wallet_section/transactions/io_interface.nim index 1d60ab1b54..cacbf8d4b5 100644 --- a/src/app/modules/main/wallet_section/transactions/io_interface.nim +++ b/src/app/modules/main/wallet_section/transactions/io_interface.nim @@ -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.} = diff --git a/src/app/modules/main/wallet_section/transactions/module.nim b/src/app/modules/main/wallet_section/transactions/module.nim index b81fd2a5bb..5fb45d17bc 100644 --- a/src/app/modules/main/wallet_section/transactions/module.nim +++ b/src/app/modules/main/wallet_section/transactions/module.nim @@ -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) = diff --git a/src/app/modules/main/wallet_section/view.nim b/src/app/modules/main/wallet_section/view.nim index 73410111e9..a3b1a71bd7 100644 --- a/src/app/modules/main/wallet_section/view.nim +++ b/src/app/modules/main/wallet_section/view.nim @@ -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 diff --git a/storybook/pages/ProfileDialogViewPage.qml b/storybook/pages/ProfileDialogViewPage.qml index 5bb25eaed0..77665b7889 100644 --- a/storybook/pages/ProfileDialogViewPage.qml +++ b/storybook/pages/ProfileDialogViewPage.qml @@ -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) { diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 30e09f21c8..1dc41710d3 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -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() } diff --git a/ui/app/AppLayouts/Wallet/WalletLayout.qml b/ui/app/AppLayouts/Wallet/WalletLayout.qml index e5ea16ee95..b6301e5e63 100644 --- a/ui/app/AppLayouts/Wallet/WalletLayout.qml +++ b/ui/app/AppLayouts/Wallet/WalletLayout.qml @@ -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: { diff --git a/ui/app/AppLayouts/Wallet/stores/RootStore.qml b/ui/app/AppLayouts/Wallet/stores/RootStore.qml index c547bb5bde..1396127889 100644 --- a/ui/app/AppLayouts/Wallet/stores/RootStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/RootStore.qml @@ -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) { diff --git a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml index cc905f7132..fd1b859f57 100644 --- a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml @@ -268,7 +268,7 @@ Rectangle { accountContextMenu.item.popup(mouse.x, mouse.y) return } - changeSelectedAccount(index) + changeSelectedAccount(model.address) showSavedAddresses = false } components: [ diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index 8af00ac1d8..454a5aaf6f 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -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, "") } diff --git a/ui/imports/shared/stores/TransactionStore.qml b/ui/imports/shared/stores/TransactionStore.qml index 06a3e7e968..d05eff5f5e 100644 --- a/ui/imports/shared/stores/TransactionStore.qml +++ b/ui/imports/shared/stores/TransactionStore.qml @@ -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, "") } diff --git a/ui/imports/shared/views/profile/ProfileShowcaseView.qml b/ui/imports/shared/views/profile/ProfileShowcaseView.qml index 6b368bb278..919aac265d 100644 --- a/ui/imports/shared/views/profile/ProfileShowcaseView.qml +++ b/ui/imports/shared/views/profile/ProfileShowcaseView.qml @@ -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) } } }