From 542e5fdb6c70b1716e434319199d6bdffbbc2f8e Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 25 Apr 2023 18:54:50 +0200 Subject: [PATCH] feat(@wallet): remove usage of wallet section current --- .../wallet_section/accounts/controller.nim | 3 + .../wallet_section/accounts/io_interface.nim | 3 + .../main/wallet_section/accounts/module.nim | 5 +- .../main/wallet_section/accounts/view.nim | 5 +- .../main/wallet_section/assets/controller.nim | 17 +-- .../wallet_section/assets/io_interface.nim | 9 -- .../main/wallet_section/assets/item.nim | 56 -------- .../main/wallet_section/assets/module.nim | 76 +++-------- .../main/wallet_section/assets/utils.nim | 17 +-- .../main/wallet_section/assets/view.nim | 120 +----------------- .../collectibles/controller.nim | 3 + .../collectibles/io_interface.nim | 3 + .../wallet_section/collectibles/module.nim | 3 + .../main/wallet_section/collectibles/view.nim | 2 + .../modules/main/wallet_section/module.nim | 2 +- .../main/wallet_section/overview/item.nim | 9 +- .../main/wallet_section/overview/module.nim | 8 +- .../main/wallet_section/overview/view.nim | 16 +-- .../wallet_section/send/accounts_model.nim | 2 +- .../modules/main/wallet_section/send/view.nim | 8 ++ .../Browser/popups/BrowserWalletMenu.qml | 4 +- ui/app/AppLayouts/Chat/stores/RootStore.qml | 1 - .../AppLayouts/Profile/stores/WalletStore.qml | 2 + .../Profile/views/EnsDetailsView.qml | 2 +- .../Profile/views/EnsSearchView.qml | 2 +- .../views/EnsTermsAndConditionsView.qml | 2 +- .../views/profile/MyProfileSettingsView.qml | 4 +- .../AppLayouts/Wallet/panels/WalletFooter.qml | 2 +- .../AppLayouts/Wallet/popups/ReceiveModal.qml | 16 +-- ui/app/AppLayouts/Wallet/stores/RootStore.qml | 6 +- .../Wallet/views/AssetsDetailView.qml | 18 +-- .../AppLayouts/Wallet/views/LeftTabView.qml | 4 +- .../AppLayouts/Wallet/views/RightTabView.qml | 10 +- .../Wallet/views/TransactionDetailView.qml | 4 +- ui/app/AppLayouts/stores/RootStore.qml | 1 - .../shared/popups/AccountsModalHeader.qml | 10 +- ui/imports/shared/popups/SendModal.qml | 8 +- .../shared/status/StatusStickerMarket.qml | 2 +- .../status/StatusStickerPackClickPopup.qml | 2 +- .../shared/stores/NetworkConnectionStore.qml | 12 +- ui/imports/shared/stores/RootStore.qml | 1 - ui/imports/shared/stores/TransactionStore.qml | 2 +- ui/imports/shared/views/AssetsView.qml | 4 +- ui/imports/shared/views/HistoryView.qml | 10 +- .../shared/views/NetworkCardsComponent.qml | 2 +- .../views/profile/ProfileShowcaseView.qml | 2 +- 46 files changed, 128 insertions(+), 372 deletions(-) diff --git a/src/app/modules/main/wallet_section/accounts/controller.nim b/src/app/modules/main/wallet_section/accounts/controller.nim index fb9880af82..d6ec9af1cd 100644 --- a/src/app/modules/main/wallet_section/accounts/controller.nim +++ b/src/app/modules/main/wallet_section/accounts/controller.nim @@ -69,3 +69,6 @@ proc getMigratedKeyPairByKeyUid*(self: Controller, keyUid: string): seq[KeyPairD proc getWalletAccount*(self: Controller, address: string): WalletAccountDto = return self.walletAccountService.getAccountByAddress(address) + +proc updateAccount*(self: Controller, address: string, accountName: string, color: string, emoji: string) = + discard self.walletAccountService.updateWalletAccount(address, accountName, color, emoji) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/io_interface.nim b/src/app/modules/main/wallet_section/accounts/io_interface.nim index d935ef5f8a..aa6a1f726e 100644 --- a/src/app/modules/main/wallet_section/accounts/io_interface.nim +++ b/src/app/modules/main/wallet_section/accounts/io_interface.nim @@ -19,6 +19,9 @@ method deleteAccount*(self: AccessInterface, keyUid: string, address: string) {. method refreshWalletAccounts*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method updateAccount*(self: AccessInterface, address: string, accountName: string, color: string, emoji: string) {.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. diff --git a/src/app/modules/main/wallet_section/accounts/module.nim b/src/app/modules/main/wallet_section/accounts/module.nim index 5991f467fd..c0895b25ec 100644 --- a/src/app/modules/main/wallet_section/accounts/module.nim +++ b/src/app/modules/main/wallet_section/accounts/module.nim @@ -148,4 +148,7 @@ method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: if password.len == 0: return let doPasswordHashing = pin.len != PINLengthForStatusApp - self.controller.deleteAccount(self.processingWalletAccount.address, password, doPasswordHashing) \ No newline at end of file + self.controller.deleteAccount(self.processingWalletAccount.address, password, doPasswordHashing) + +method updateAccount*(self: Module, address: string, accountName: string, color: string, emoji: string) = + self.controller.updateAccount(address, accountName, color, emoji) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/view.nim b/src/app/modules/main/wallet_section/accounts/view.nim index 78f3d894ce..e4644fbbfb 100644 --- a/src/app/modules/main/wallet_section/accounts/view.nim +++ b/src/app/modules/main/wallet_section/accounts/view.nim @@ -41,4 +41,7 @@ QtObject: self.accounts.setItems(items) proc deleteAccount*(self: View, keyUid: string, address: string) {.slot.} = - self.delegate.deleteAccount(keyUid, address) \ No newline at end of file + self.delegate.deleteAccount(keyUid, address) + + proc updateAccount(self: View, address: string, accountName: string, color: string, emoji: string) {.slot.} = + self.delegate.updateAccount(address, accountName, color, emoji) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/assets/controller.nim b/src/app/modules/main/wallet_section/assets/controller.nim index cf5037b8d2..31023849e4 100644 --- a/src/app/modules/main/wallet_section/assets/controller.nim +++ b/src/app/modules/main/wallet_section/assets/controller.nim @@ -13,7 +13,6 @@ type networkService: network_service.Service tokenService: token_service.Service currencyService: currency_service.Service - collectibleService: collectible_service.Service proc newController*( delegate: io_interface.AccessInterface, @@ -21,7 +20,6 @@ proc newController*( networkService: network_service.Service, tokenService: token_service.Service, currencyService: currency_service.Service, - collectibleService: collectible_service.Service, ): Controller = result = Controller() result.delegate = delegate @@ -29,7 +27,6 @@ proc newController*( result.networkService = networkService result.tokenService = tokenService result.currencyService = currencyService - result.collectibleService = collectibleService proc delete*(self: Controller) = discard @@ -43,12 +40,6 @@ proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAcco proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto = return self.walletAccountService.getWalletAccount(accountIndex) -proc update*(self: Controller, address: string, accountName: string, color: string, emoji: string) = - discard self.walletAccountService.updateWalletAccount(address, accountName, color, emoji) - -method findTokenSymbolByAddress*(self: Controller, address: string): string = - return self.walletAccountService.findTokenSymbolByAddress(address) - proc getChainIds*(self: Controller): seq[int] = return self.networkService.getNetworks().map(n => n.chainId) @@ -59,10 +50,4 @@ proc getCurrentCurrency*(self: Controller): string = return self.walletAccountService.getCurrency() proc getCurrencyFormat*(self: Controller, symbol: string): CurrencyFormatDto = - return self.currencyService.getCurrencyFormat(symbol) - -proc getAllMigratedKeyPairs*(self: Controller): seq[KeyPairDto] = - return self.walletAccountService.getAllMigratedKeyPairs() - -proc getHasCollectiblesCache*(self: Controller, address: string): bool = - return self.collectibleService.areCollectionsLoaded(address) + return self.currencyService.getCurrencyFormat(symbol) \ No newline at end of file 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 1717bf58a7..e6e5627585 100644 --- a/src/app/modules/main/wallet_section/assets/io_interface.nim +++ b/src/app/modules/main/wallet_section/assets/io_interface.nim @@ -14,15 +14,6 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = raise newException(ValueError, "No implementation available") -method update*(self: AccessInterface, address: string, accountName: string, color: string, emoji: string) {.base.} = - raise newException(ValueError, "No implementation available") - -method findTokenSymbolByAddress*(self: AccessInterface, address: string): string {.base.} = - raise newException(ValueError, "No implementation available") - -method getHasCollectiblesCache*(self: AccessInterface, address: string): bool {.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. diff --git a/src/app/modules/main/wallet_section/assets/item.nim b/src/app/modules/main/wallet_section/assets/item.nim index 34e7237016..891f6f0adb 100644 --- a/src/app/modules/main/wallet_section/assets/item.nim +++ b/src/app/modules/main/wallet_section/assets/item.nim @@ -3,82 +3,26 @@ import ../../../shared_models/currency_amount type Item* = object - name: string - address: string - path: string - color: string - walletType: string - currencyBalance: CurrencyAmount - emoji: string - keyUid: string assetsLoading: bool hasBalanceCache: bool hasMarketValuesCache: bool proc initItem*( - name: string = "", - address: string = "", - path: string = "", - color: string = "", - walletType: string = "", - currencyBalance: CurrencyAmount = nil, - emoji: string = "", - keyUid: string = "", assetsLoading: bool = true, hasBalanceCache: bool = false, hasMarketValuesCache: bool = false ): Item = - result.name = name - result.address = address - result.path = path - result.color = color - result.walletType = walletType - result.currencyBalance = currencyBalance - result.emoji = emoji - result.keyUid = keyUid result.assetsLoading = assetsLoading result.hasBalanceCache = hasBalanceCache result.hasMarketValuesCache = hasMarketValuesCache proc `$`*(self: Item): string = result = fmt"""WalletAccountItem( - name: {self.name}, - address: {self.address}, - path: {self.path}, - color: {self.color}, - walletType: {self.walletType}, - currencyBalance: {self.currencyBalance}, - emoji: {self.emoji}, - keyUid: {self.keyUid}, assetsLoading: {self.assetsLoading}, hasBalanceCache: {self.hasBalanceCache}, hasMarketValuesCache: {self.hasMarketValuesCache}, ]""" -proc getName*(self: Item): string = - return self.name - -proc getAddress*(self: Item): string = - return self.address - -proc getPath*(self: Item): string = - return self.path - -proc getEmoji*(self: Item): string = - return self.emoji - -proc getColor*(self: Item): string = - return self.color - -proc getWalletType*(self: Item): string = - return self.walletType - -proc getCurrencyBalance*(self: Item): CurrencyAmount = - return self.currencyBalance - -proc getKeyUid*(self: Item): string = - return self.keyUid - proc getAssetsLoading*(self: Item): bool = return self.assetsLoading diff --git a/src/app/modules/main/wallet_section/assets/module.nim b/src/app/modules/main/wallet_section/assets/module.nim index 0b1220cfde..b32c1e3d51 100644 --- a/src/app/modules/main/wallet_section/assets/module.nim +++ b/src/app/modules/main/wallet_section/assets/module.nim @@ -6,9 +6,9 @@ import ../../../../../app_service/service/token/service as token_service import ../../../../../app_service/service/currency/service as currency_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/network/service as network_service -import ../../../../../app_service/service/node/service as node_service import ../../../../../app_service/service/network_connection/service as network_connection import ../../../../../app_service/service/collectible/service as collectible_service +import ../../../../../app_service/service/node/service as node_service import ../../../shared_models/currency_amount_utils import ../../../shared_models/currency_amount import ../../../shared_models/token_model as token_model @@ -43,14 +43,13 @@ proc newModule*( networkService: network_service.Service, tokenService: token_service.Service, currencyService: currency_service.Service, - collectibleService: collectible_service.Service, ): Module = result = Module() result.delegate = delegate result.events = events result.currentAccountIndex = 0 result.view = newView(result) - result.controller = newController(result, walletAccountService, networkService, tokenService, currencyService, collectibleService) + result.controller = newController(result, walletAccountService, networkService, tokenService, currencyService) result.moduleLoaded = false method delete*(self: Module) = @@ -61,10 +60,9 @@ proc setLoadingAssets(self: Module) = for i in 0 ..< 25: loadingTokenItems.add(token_item.initLoadingItem()) self.view.getAssetsModel().setItems(loadingTokenItems) - self.view.setCurrencyBalance(newCurrencyAmount()) method load*(self: Module) = - singletonInstance.engine.setRootContextProperty("walletSectionCurrent", newQVariant(self.view)) + 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): @@ -123,59 +121,22 @@ proc setAssetsAndBalance(self: Module, tokens: seq[WalletTokenDto]) = let totalCurrencyBalanceForAllAssets = tokens.map(t => t.getCurrencyBalance(enabledChainIds, currency)).foldl(a + b, 0.0) self.view.getAssetsModel().setItems(items) - self.view.setCurrencyBalance(currencyAmountToItem(totalCurrencyBalanceForAllAssets, currencyFormat)) 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) + + let accountItem = walletAccountToItem(walletAccount) + self.view.setData(accountItem) - let keyPairMigrated = proc(migratedKeyPairs: seq[KeyPairDto], keyUid: string): bool = - for kp in migratedKeyPairs: - if kp.keyUid == keyUid: - return true - return false + if walletAccount.tokens.len == 0 and walletAccount.assetsLoading: + self.setLoadingAssets() + else: + self.setAssetsAndBalance(walletAccount.tokens) - let migratedKeyPairs = self.controller.getAllMigratedKeyPairs() - let currency = self.controller.getCurrentCurrency() - let currencyFormat = self.controller.getCurrencyFormat(currency) - - let chainIds = self.controller.getChainIds() - let enabledChainIds = self.controller.getEnabledChainIds() - - let defaultAccount = self.controller.getWalletAccount(0) # can safely do this as the account will always contain atleast one account - if not defaultAccount.isNil: - let defaultAccountTokenFormats = collect(initTable()): - for t in defaultAccount.tokens: {t.symbol: self.controller.getCurrencyFormat(t.symbol)} - - let defaultAccountItem = walletAccountToItem( - defaultAccount, - enabledChainIds, - currency, - currencyFormat, - ) - - self.view.setDefaultWalletAccount(defaultAccountItem) - - let walletAccount = self.controller.getWalletAccount(accountIndex) - if not walletAccount.isNil: - let accountTokenFormats = collect(initTable()): - for t in walletAccount.tokens: {t.symbol: self.controller.getCurrencyFormat(t.symbol)} - - let accountItem = walletAccountToItem( - walletAccount, - enabledChainIds, - currency, - currencyFormat, - ) - - self.view.setData(accountItem) - - if walletAccount.tokens.len == 0 and walletAccount.assetsLoading: - self.setLoadingAssets() - else: - self.setAssetsAndBalance(walletAccount.tokens) - -method update*(self: Module, address: string, accountName: string, color: string, emoji: string) = - self.controller.update(address, accountName, color, emoji) proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool, hasMarketValuesCache: bool) = let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex) @@ -186,21 +147,14 @@ proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[Wall self.view.setCacheValues(hasBalanceCache, hasMarketValuesCache) proc onCurrencyFormatsUpdated(self: Module) = - # Update assets let walletAccount = self.controller.getWalletAccount(self.currentAccountIndex) if walletAccount.tokens.len == 0 and walletAccount.assetsLoading: self.setLoadingAssets() else: self.setAssetsAndBalance(walletAccount.tokens) -method findTokenSymbolByAddress*(self: Module, address: string): string = - return self.controller.findTokenSymbolByAddress(address) - proc onAccountAdded(self: Module, account: WalletAccountDto) = self.switchAccount(self.currentAccountIndex) proc onAccountRemoved(self: Module, account: WalletAccountDto) = - self.switchAccount(self.currentAccountIndex) - -method getHasCollectiblesCache*(self: Module, address: string): bool = - return self.controller.getHasCollectiblesCache(address) + self.switchAccount(self.currentAccountIndex) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/assets/utils.nim b/src/app/modules/main/wallet_section/assets/utils.nim index b260a556e1..94f6591f49 100644 --- a/src/app/modules/main/wallet_section/assets/utils.nim +++ b/src/app/modules/main/wallet_section/assets/utils.nim @@ -1,25 +1,10 @@ import ./item import ../../../../../app_service/service/wallet_account/dto -import ../../../../../app_service/service/currency/dto as currency_dto -import ../../../shared_models/currency_amount -import ../../../shared_models/currency_amount_utils - proc walletAccountToItem*( w: WalletAccountDto, - enabledChainIds: seq[int], - currency: string, - currencyFormat: CurrencyFormatDto, - ) : item.Item = +) : item.Item = return item.initItem( - w.name, - w.address, - w.path, - w.color, - w.walletType, - currencyAmountToItem(w.getCurrencyBalance(enabledChainIds, currency), currencyFormat), - w.emoji, - w.keyUid, w.assetsLoading, ) diff --git a/src/app/modules/main/wallet_section/assets/view.nim b/src/app/modules/main/wallet_section/assets/view.nim index 9fb5883ea1..c34bfce0ac 100644 --- a/src/app/modules/main/wallet_section/assets/view.nim +++ b/src/app/modules/main/wallet_section/assets/view.nim @@ -3,27 +3,14 @@ import NimQml, sequtils, sugar, json import ./io_interface import ../../../shared_models/token_model as token_model import ../../../shared_models/token_item as token_item -import ../../../shared_models/currency_amount import ./item as account_item -const GENERATED = "generated" -const GENERATED_FROM_IMPORTED = "generated from imported accounts" - QtObject: type View* = ref object of QObject delegate: io_interface.AccessInterface - defaultAccount: account_item.Item - name: string - keyUid: string - address: string - path: string - color: string - walletType: string - currencyBalance: CurrencyAmount assets: token_model.Model - emoji: string assetsLoading: bool hasBalanceCache: bool hasMarketValuesCache: bool @@ -44,66 +31,6 @@ QtObject: proc load*(self: View) = self.delegate.viewDidLoad() - proc getName(self: View): QVariant {.slot.} = - return newQVariant(self.name) - - proc nameChanged(self: View) {.signal.} - - QtProperty[QVariant] name: - read = getName - notify = nameChanged - - proc getKeyUid(self: View): QVariant {.slot.} = - return newQVariant(self.keyUid) - proc keyUidChanged(self: View) {.signal.} - QtProperty[QVariant] keyUid: - read = getKeyUid - notify = keyUidChanged - - proc getAddress(self: View): QVariant {.slot.} = - return newQVariant(self.address) - proc addressChanged(self: View) {.signal.} - QtProperty[QVariant] address: - read = getAddress - notify = addressChanged - - proc getPath(self: View): QVariant {.slot.} = - return newQVariant(self.path) - - proc pathChanged(self: View) {.signal.} - - QtProperty[QVariant] path: - read = getPath - notify = pathChanged - - proc getColor(self: View): QVariant {.slot.} = - return newQVariant(self.color) - - proc colorChanged(self: View) {.signal.} - - QtProperty[QVariant] color: - read = getColor - notify = colorChanged - - proc getWalletType(self: View): QVariant {.slot.} = - return newQVariant(self.walletType) - - proc walletTypeChanged(self: View) {.signal.} - - QtProperty[QVariant] walletType: - read = getWalletType - notify = walletTypeChanged - - proc currencyBalanceChanged(self: View) {.signal.} - proc getCurrencyBalance*(self: View): QVariant {.slot.} = - return newQVariant(self.currencyBalance) - proc setCurrencyBalance*(self: View, value: CurrencyAmount) = - self.currencyBalance = value - self.currencyBalanceChanged() - QtProperty[QVariant] currencyBalance: - read = getCurrencyBalance - notify = currencyBalanceChanged - proc getAssetsModel*(self: View): token_model.Model = return self.assets @@ -114,15 +41,6 @@ QtObject: read = getAssets notify = assetsChanged - proc getEmoji(self: View): QVariant {.slot.} = - return newQVariant(self.emoji) - - proc emojiChanged(self: View) {.signal.} - - QtProperty[QVariant] emoji: - read = getEmoji - notify = emojiChanged - proc getAssetsLoading(self: View): QVariant {.slot.} = return newQVariant(self.assetsLoading) proc assetsLoadingChanged(self: View) {.signal.} @@ -149,51 +67,15 @@ QtObject: read = getHasMarketValuesCache notify = hasMarketValuesCacheChanged - proc update(self: View, address: string, accountName: string, color: string, emoji: string) {.slot.} = - self.delegate.update(address, accountName, color, emoji) - - proc setDefaultWalletAccount*(self: View, default: account_item.Item) = - self.defaultAccount = default - proc setData*(self: View, item: account_item.Item) = - if(self.name != item.getName()): - self.name = item.getName() - self.nameChanged() - if(self.keyUid != item.getKeyUid()): - self.keyUid = item.getKeyUid() - self.keyUidChanged() - if(self.address != item.getAddress()): - self.address = item.getAddress() - self.addressChanged() - if(self.path != item.getPath()): - self.path = item.getPath() - self.pathChanged() - if(self.color != item.getColor()): - self.color = item.getColor() - self.colorChanged() - if(self.walletType != item.getWalletType()): - self.walletType = item.getWalletType() - self.walletTypeChanged() - if(self.emoji != item.getEmoji()): - self.emoji = item.getEmoji() - self.emojiChanged() self.setAssetsLoading(item.getAssetsLoading()) self.hasBalanceCache = item.getHasBalanceCache() self.hasBalanceCacheChanged() self.hasMarketValuesCache = item.getHasMarketValuesCache() self.hasMarketValuesCacheChanged() - proc findTokenSymbolByAddress*(self: View, address: string): string {.slot.} = - return self.delegate.findTokenSymbolByAddress(address) - - proc hasGas*(self: View, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.slot.} = - return self.assets.hasGas(chainId, nativeGasSymbol, requiredGas) - proc setCacheValues*(self: View, hasBalanceCache: bool, hasMarketValuesCache: bool) = self.hasBalanceCache = hasBalanceCache self.hasBalanceCacheChanged() self.hasMarketValuesCache = hasMarketValuesCache - self.hasMarketValuesCacheChanged() - - proc getHasCollectiblesCache(self: View): bool {.slot.} = - return self.delegate.getHasCollectiblesCache(self.address) + self.hasMarketValuesCacheChanged() \ 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 d3feb45124..14b6c00961 100644 --- a/src/app/modules/main/wallet_section/collectibles/controller.nim +++ b/src/app/modules/main/wallet_section/collectibles/controller.nim @@ -89,3 +89,6 @@ proc getCollectible*(self: Controller, chainId: int, id: UniqueID) : Collectible proc getCollection*(self: Controller, chainId: int, slug: string) : CollectionDto = self.collectibleService.getCollection(chainId, slug) + +proc getHasCollectiblesCache*(self: Controller, address: string): bool = + return self.collectibleService.areCollectionsLoaded(address) \ No newline at end of file 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 83b839e36f..01609a61c3 100644 --- a/src/app/modules/main/wallet_section/collectibles/io_interface.nim +++ b/src/app/modules/main/wallet_section/collectibles/io_interface.nim @@ -31,6 +31,9 @@ method appendCollectibles*(self: AccessInterface, chainId: int, address: string, method viewDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method getHasCollectiblesCache*(self: AccessInterface): bool {.base.} = + raise newException(ValueError, "No implementation available") + # Methods called by submodules of this module method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/collectibles/module.nim b/src/app/modules/main/wallet_section/collectibles/module.nim index 7f75e468b0..5eef295229 100644 --- a/src/app/modules/main/wallet_section/collectibles/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/module.nim @@ -142,3 +142,6 @@ method appendCollectibles*(self: Module, chainId: int, address: string, data: Co self.view.appendCollectibles(newCollectibles) self.view.setAllLoaded(data.allLoaded) + +method getHasCollectiblesCache*(self: Module): bool = + return self.controller.getHasCollectiblesCache(self.address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/view.nim b/src/app/modules/main/wallet_section/collectibles/view.nim index 8bc3b63ffc..9e67ba599c 100644 --- a/src/app/modules/main/wallet_section/collectibles/view.nim +++ b/src/app/modules/main/wallet_section/collectibles/view.nim @@ -49,3 +49,5 @@ QtObject: proc appendCollectibles*(self: View, collectibles: seq[Item]) = self.model.appendItems(collectibles) + proc getHasCollectiblesCache(self: View): bool {.slot.} = + return self.delegate.getHasCollectiblesCache() \ 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 9ff04baefe..2e00ca369f 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -87,7 +87,7 @@ proc newModule*( result.accountsModule = accounts_module.newModule(result, events, walletAccountService, networkService, currencyService) result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService) result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService, networkService, nodeService, networkConnectionService) - result.assetsModule = assets_module.newModule(result, events, walletAccountService, networkService, tokenService, currencyService, collectibleService) + result.assetsModule = assets_module.newModule(result, events, walletAccountService, networkService, tokenService, currencyService) result.transactionsModule = transactions_module.newModule(result, events, transactionService, walletAccountService, networkService, currencyService) result.sendModule = send_module.newModule(result, events, walletAccountService, networkService, currencyService, transactionService) result.savedAddressesModule = saved_addresses_module.newModule(result, events, savedAddressService) diff --git a/src/app/modules/main/wallet_section/overview/item.nim b/src/app/modules/main/wallet_section/overview/item.nim index 6a4dde81ab..d7af6a6607 100644 --- a/src/app/modules/main/wallet_section/overview/item.nim +++ b/src/app/modules/main/wallet_section/overview/item.nim @@ -6,20 +6,17 @@ type mixedCaseAddress: string ens: string balanceLoading: bool - hasBalanceCache: bool proc initItem*( name: string = "", mixedCaseAddress: string = "", ens: string = "", balanceLoading: bool = true, - hasBalanceCache: bool = false, ): Item = result.name = name result.mixedCaseAddress = mixedCaseAddress result.ens = ens result.balanceLoading = balanceLoading - result.hasBalanceCache = hasBalanceCache proc `$`*(self: Item): string = result = fmt"""OverviewItem( @@ -27,7 +24,6 @@ proc `$`*(self: Item): string = mixedCaseAddress: {self.mixedCaseAddress}, ens: {self.ens}, balanceLoading: {self.balanceLoading}, - hasBalanceCache: {self.hasBalanceCache}, ]""" proc getName*(self: Item): string = @@ -40,7 +36,4 @@ proc getEns*(self: Item): string = return self.ens proc getBalanceLoading*(self: Item): bool = - return self.balanceLoading - -proc getHasBalanceCache*(self: Item): bool = - return self.hasBalanceCache \ No newline at end of file + return self.balanceLoading \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/overview/module.nim b/src/app/modules/main/wallet_section/overview/module.nim index 6ae66ccef8..78771267aa 100644 --- a/src/app/modules/main/wallet_section/overview/module.nim +++ b/src/app/modules/main/wallet_section/overview/module.nim @@ -23,7 +23,7 @@ type moduleLoaded: bool currentAccountIndex: int -proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool) +proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]]) proc onCurrencyFormatsUpdated(self: Module) proc onAccountAdded(self: Module, account: WalletAccountDto) proc onAccountRemoved(self: Module, account: WalletAccountDto) @@ -69,7 +69,7 @@ method load*(self: Module) = self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args): let arg = TokensPerAccountArgs(e) - self.onTokensRebuilt(arg.accountsTokens, arg.hasBalanceCache) + self.onTokensRebuilt(arg.accountsTokens) self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args): self.onCurrencyFormatsUpdated() @@ -106,7 +106,6 @@ method switchAccount*(self: Module, accountIndex: int) = walletAccount.mixedCaseAddress, walletAccount.ens, walletAccount.assetsLoading, - walletAccount.hasBalanceCache, ) self.view.setData(item) @@ -115,12 +114,11 @@ method switchAccount*(self: Module, accountIndex: int) = else: self.setBalance(walletAccount.tokens) -proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[WalletTokenDto]], hasBalanceCache: bool) = +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.setCacheValues(hasBalanceCache) self.view.setBalanceLoading(false) proc onCurrencyFormatsUpdated(self: Module) = diff --git a/src/app/modules/main/wallet_section/overview/view.nim b/src/app/modules/main/wallet_section/overview/view.nim index f81bd86a85..d56020f807 100644 --- a/src/app/modules/main/wallet_section/overview/view.nim +++ b/src/app/modules/main/wallet_section/overview/view.nim @@ -14,7 +14,6 @@ QtObject: currencyBalance: CurrencyAmount ens: string balanceLoading: bool - hasBalanceCache*: bool proc setup(self: View) = self.QObject.setup @@ -73,13 +72,6 @@ QtObject: self.balanceLoading = balanceLoading self.balanceLoadingChanged() - proc getHasBalanceCache(self: View): QVariant {.slot.} = - return newQVariant(self.hasBalanceCache) - proc hasBalanceCacheChanged(self: View) {.signal.} - QtProperty[QVariant] hasBalanceCache: - read = getHasBalanceCache - notify = hasBalanceCacheChanged - proc setData*(self: View, item: Item) = if(self.name != item.getName()): self.name = item.getName() @@ -90,10 +82,4 @@ QtObject: if(self.ens != item.getEns()): self.ens = item.getEns() self.ensChanged() - self.setBalanceLoading(item.getBalanceLoading()) - self.hasBalanceCache = item.getHasBalanceCache() - self.hasBalanceCacheChanged() - - proc setCacheValues*(self: View, hasBalanceCache: bool) = - self.hasBalanceCache = hasBalanceCache - self.hasBalanceCacheChanged() \ No newline at end of file + self.setBalanceLoading(item.getBalanceLoading()) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/send/accounts_model.nim b/src/app/modules/main/wallet_section/send/accounts_model.nim index ce50caf71f..fca2992b17 100644 --- a/src/app/modules/main/wallet_section/send/accounts_model.nim +++ b/src/app/modules/main/wallet_section/send/accounts_model.nim @@ -16,7 +16,7 @@ type QtObject: type AccountsModel* = ref object of QAbstractListModel - items: seq[AccountItem] + items*: seq[AccountItem] proc delete(self: AccountsModel) = self.items = @[] diff --git a/src/app/modules/main/wallet_section/send/view.nim b/src/app/modules/main/wallet_section/send/view.nim index 4de4a7f48b..aef8c518bc 100644 --- a/src/app/modules/main/wallet_section/send/view.nim +++ b/src/app/modules/main/wallet_section/send/view.nim @@ -1,6 +1,7 @@ import NimQml, sequtils, strutils, stint import ../../../../../app_service/service/wallet_account/service as wallet_account_service +import ../../../shared_models/token_model import ./accounts_model import ./account_item @@ -103,3 +104,10 @@ QtObject: return self.delegate.getEstimatedTime(chainId, maxFeePerGas) proc suggestedRoutesReady*(self: View, suggestedRoutes: string) {.signal.} + + proc hasGas*(self: View, address: string, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.slot.} = + for account in self.accounts.items: + if account.getAddress() == address: + return account.getAssets().hasGas(chainId, nativeGasSymbol, requiredGas) + + return false \ No newline at end of file diff --git a/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml b/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml index 20b239ef55..fcd642fb6f 100644 --- a/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml +++ b/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml @@ -204,11 +204,11 @@ Popup { AssetsView { id: assetsTab - account: WalletStore.dappBrowserAccount + assets: WalletStore.dappBrowserAccount.assets } HistoryView { id: historyTab - assets: WalletStore.dappBrowserAccount + overview: WalletStore.dappBrowserAccount } } } diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 24c885658e..4678fabb3a 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -516,7 +516,6 @@ QtObject { // Needed for TX in chat for stickers and via contact property var accounts: walletSectionSendInst.accounts - property var currentAccount: walletSectionCurrent property string currentCurrency: walletSection.currentCurrency property CurrenciesStore currencyStore: CurrenciesStore {} property var allNetworks: networksModule.all diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index 30306a5be0..a993809af6 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -18,7 +18,9 @@ QtObject { } // TODO(alaibe): there should be no access to wallet section, create collectible in profile + property var overview: walletSectionOverview property var flatCollectibles: Global.appIsReady ? walletSectionCollectibles.model : null + property var accounts: Global.appIsReady? accountsModule.accounts : null function deleteAccount(keyUid, address) { diff --git a/ui/app/AppLayouts/Profile/views/EnsDetailsView.qml b/ui/app/AppLayouts/Profile/views/EnsDetailsView.qml index 22ec55a38a..595f7a0893 100644 --- a/ui/app/AppLayouts/Profile/views/EnsDetailsView.qml +++ b/ui/app/AppLayouts/Profile/views/EnsDetailsView.qml @@ -120,7 +120,7 @@ Item { sendType: Constants.SendType.ENSRelease preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress() preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0) - preSelectedAsset: store.getAsset(releaseEnsModal.store.currentAccount.assets, "ETH") + preSelectedAsset: store.getAsset(releaseEnsModal.store.assets, "ETH") sendTransaction: function() { if(bestRoutes.length === 1) { let path = bestRoutes[0] diff --git a/ui/app/AppLayouts/Profile/views/EnsSearchView.qml b/ui/app/AppLayouts/Profile/views/EnsSearchView.qml index e376306d30..5d0af3977f 100644 --- a/ui/app/AppLayouts/Profile/views/EnsSearchView.qml +++ b/ui/app/AppLayouts/Profile/views/EnsSearchView.qml @@ -66,7 +66,7 @@ Item { sendType: Constants.SendType.ENSSetPubKey preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress() preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0) - preSelectedAsset: store.getAsset(connectEnsModal.store.currentAccount.assets, "ETH") + preSelectedAsset: store.getAsset(connectEnsModal.store.assets, "ETH") sendTransaction: function() { if(bestRoutes.length === 1) { let path = bestRoutes[0] diff --git a/ui/app/AppLayouts/Profile/views/EnsTermsAndConditionsView.qml b/ui/app/AppLayouts/Profile/views/EnsTermsAndConditionsView.qml index e0bf66805a..5742274c5f 100644 --- a/ui/app/AppLayouts/Profile/views/EnsTermsAndConditionsView.qml +++ b/ui/app/AppLayouts/Profile/views/EnsTermsAndConditionsView.qml @@ -50,7 +50,7 @@ Item { sendType: Constants.SendType.ENSRegister preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress() preDefinedAmountToSend: LocaleUtils.numberToLocaleString(10) - preSelectedAsset: store.getAsset(buyEnsModal.store.currentAccount.assets, JSON.parse(root.stickersStore.getStatusToken()).symbol) + preSelectedAsset: store.getAsset(buyEnsModal.store.assets, JSON.parse(root.stickersStore.getStatusToken()).symbol) sendTransaction: function() { if(bestRoutes.length === 1) { let path = bestRoutes[0] diff --git a/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml b/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml index 146cfc00a6..1ad0504f2a 100644 --- a/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml +++ b/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml @@ -205,7 +205,7 @@ ColumnLayout { Layout.minimumHeight: implicitHeight Layout.maximumHeight: implicitHeight baseModel: root.walletStore.accounts - currentWallet: root.walletStore.currentAccount.address + currentWallet: root.walletStore.overview.mixedcaseAddress } ProfileShowcaseCollectiblesPanel { @@ -217,7 +217,7 @@ ColumnLayout { ProfileShowcaseAssetsPanel { Layout.minimumHeight: implicitHeight Layout.maximumHeight: implicitHeight - baseModel: root.walletStore.currentAccount.assets + baseModel: root.walletStore.assets } } } diff --git a/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml b/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml index 1de59bbfd6..c2e4ff78a1 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml @@ -77,7 +77,7 @@ Rectangle { Component { id: receiveModalComponent ReceiveModal { - selectedAccount: walletStore.currentAccount + selectedAddress: walletStore.overview.mixedcaseAddress anchors.centerIn: parent } } diff --git a/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml b/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml index 17b1850cfc..df86875677 100644 --- a/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml +++ b/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml @@ -23,13 +23,13 @@ import "../stores" StatusModal { id: root - property var selectedAccount + property string selectedAddress: "" property string networkPrefix: "" property string completeAddressWithNetworkPrefix - onSelectedAccountChanged: { - if (selectedAccount && selectedAccount.address) { - txtWalletAddress.text = selectedAccount.address + onSelectedAddressChanged: { + if (selectedAddress) { + txtWalletAddress.text = selectedAddress } } @@ -47,9 +47,9 @@ StatusModal { hasFloatingButtons: true advancedHeaderComponent: AccountsModalHeader { model: RootStore.accounts - selectedAccount: root.selectedAccount + currentAddress: root.selectedAddress changeSelectedAccount: function(newAccount, newIndex) { - root.selectedAccount = newAccount + root.selectedAddress = newAccount.address } showAllWalletTypes: true } @@ -302,7 +302,7 @@ StatusModal { } PropertyChanges { target: root - completeAddressWithNetworkPrefix: root.selectedAccount.address + completeAddressWithNetworkPrefix: root.selectedAddress } }, State { @@ -326,7 +326,7 @@ StatusModal { } PropertyChanges { target: root - completeAddressWithNetworkPrefix: root.networkPrefix + root.selectedAccount.address + completeAddressWithNetworkPrefix: root.networkPrefix + root.selectedAddress } } ] diff --git a/ui/app/AppLayouts/Wallet/stores/RootStore.qml b/ui/app/AppLayouts/Wallet/stores/RootStore.qml index 5b96d36f6e..337a2a3438 100644 --- a/ui/app/AppLayouts/Wallet/stores/RootStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/RootStore.qml @@ -18,8 +18,8 @@ QtObject { property string backButtonName: "" property var overview: walletSectionOverview - property var assets: walletSectionCurrent - property var currentAccount: walletSectionCurrent + property var assets: walletSectionAssets.assets + property bool assetsLoading: walletSectionAssets.assetsLoading property var accounts: walletSectionAccounts.accounts property var appSettings: localAppSettings property var accountSensitiveSettings: localAccountSensitiveSettings @@ -138,7 +138,7 @@ QtObject { } function updateCurrentAccount(address, accountName, color, emoji) { - return walletSectionCurrent.update(address, accountName, color, emoji) + return walletSectionAccounts.updateAccount(address, accountName, color, emoji) } function updateCurrency(newCurrency) { diff --git a/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml b/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml index bd55d633bd..2a13a077fe 100644 --- a/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml +++ b/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml @@ -23,7 +23,7 @@ Item { property var token: ({}) property var networkConnectionStore /*required*/ property string address: "" - property var account + property bool assetsLoading: true QtObject { id: d @@ -57,7 +57,7 @@ Item { secondaryText: token ? LocaleUtils.currencyAmountToLocaleString(token.enabledNetworkBalance) : Constants.dummyText tertiaryText: token ? LocaleUtils.currencyAmountToLocaleString(token.enabledNetworkCurrencyBalance) : Constants.dummyText balances: token && token.balances ? token.balances : null - isLoading: account.assetsLoading + isLoading: root.assetsLoading errorTooltipText: token && token.balances ? networkConnectionStore.getBlockchainNetworkDownTextForToken(token.balances): "" getNetworkColor: function(chainId){ return RootStore.getNetworkColor(chainId) @@ -279,19 +279,19 @@ Item { maxWidth: parent.width primaryText: qsTr("Market Cap") secondaryText: token && token.marketCap ? LocaleUtils.currencyAmountToLocaleString(token.marketCap) : Constants.dummyText - isLoading: account.assetsLoading + isLoading: root.assetsLoading } InformationTile { maxWidth: parent.width primaryText: qsTr("Day Low") secondaryText: token && token.lowDay ? LocaleUtils.currencyAmountToLocaleString(token.lowDay) : Constants.dummyText - isLoading: account.assetsLoading + isLoading: root.assetsLoading } InformationTile { maxWidth: parent.width primaryText: qsTr("Day High") secondaryText: token && token.highDay ? LocaleUtils.currencyAmountToLocaleString(token.highDay) : Constants.dummyText - isLoading: account.assetsLoading + isLoading: root.assetsLoading } Item { Layout.fillWidth: true @@ -304,7 +304,7 @@ Item { secondaryLabel.customColor: changePctHour === 0 ? Theme.palette.directColor1 : changePctHour < 0 ? Theme.palette.dangerColor1 : Theme.palette.successColor1 - isLoading: account.assetsLoading + isLoading: root.assetsLoading } InformationTile { readonly property double changePctDay: token.changePctDay ?? 0 @@ -314,7 +314,7 @@ Item { secondaryLabel.customColor: changePctDay === 0 ? Theme.palette.directColor1 : changePctDay < 0 ? Theme.palette.dangerColor1 : Theme.palette.successColor1 - isLoading: account.assetsLoading + isLoading: root.assetsLoading } InformationTile { readonly property double changePct24hour: token.changePct24hour ?? 0 @@ -324,7 +324,7 @@ Item { secondaryLabel.customColor: changePct24hour === 0 ? Theme.palette.directColor1 : changePct24hour < 0 ? Theme.palette.dangerColor1 : Theme.palette.successColor1 - isLoading: account.assetsLoading + isLoading: root.assetsLoading } } @@ -370,7 +370,7 @@ Item { elide: Text.ElideRight wrapMode: Text.Wrap textFormat: Qt.RichText - loading: account.assetsLoading + loading: root.assetsLoading } ColumnLayout { id: tagsLayout diff --git a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml index b2f871b039..b8d520e1f7 100644 --- a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml @@ -244,7 +244,7 @@ Rectangle { readonly property bool itemLoaded: !model.assetsLoading // needed for e2e tests width: ListView.view.width - Style.current.padding * 2 highlighted: !ListView.view.footerItem.button.highlighted && - RootStore.currentAccount.name === model.name + RootStore.overview.name === model.name anchors.horizontalCenter: !!parent ? parent.horizontalCenter : undefined title: model.name subTitle: LocaleUtils.currencyAmountToLocaleString(model.currencyBalance) @@ -258,7 +258,7 @@ Rectangle { asset.bgColor: Theme.palette.primaryColor3 statusListItemTitle.font.weight: Font.Medium color: sensor.containsMouse || highlighted ? Theme.palette.baseColor3 : "transparent" - statusListItemSubTitle.loading: model.assetsLoading + statusListItemSubTitle.loading: !!model.assetsLoading errorMode: networkConnectionStore.accountBalanceNotAvailable errorIcon.tooltip.maxWidth: 300 errorIcon.tooltip.text: networkConnectionStore.accountBalanceNotAvailableText diff --git a/ui/app/AppLayouts/Wallet/views/RightTabView.qml b/ui/app/AppLayouts/Wallet/views/RightTabView.qml index ded6391608..8e0ddc34ee 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabView.qml @@ -87,7 +87,7 @@ Item { currentIndex: walletTabBar.currentIndex AssetsView { - account: RootStore.currentAccount + assets: RootStore.assets networkConnectionStore: root.networkConnectionStore assetDetailsLaunched: stack.currentIndex === 2 onAssetClicked: { @@ -103,7 +103,7 @@ Item { } } HistoryView { - assets: RootStore.assets + overview: RootStore.overview onLaunchTransactionDetail: { transactionDetailView.transaction = transaction stack.currentIndex = 3 @@ -122,10 +122,12 @@ Item { Layout.fillHeight: true visible: (stack.currentIndex === 2) - account: RootStore.currentAccount - address: RootStore.currentAccount.address + assetsLoading: RootStore.assetsLoading + address: RootStore.overview.mixedcaseAddress + networkConnectionStore: root.networkConnectionStore } + TransactionDetailView { id: transactionDetailView Layout.fillWidth: true diff --git a/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml b/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml index 24cacf436e..9265b72804 100644 --- a/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml +++ b/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml @@ -20,7 +20,7 @@ import ".." Item { id: root - property var currentAccount: RootStore.currentAccount + property var overview: WalletStores.RootStore.overview property var contactsStore property var transaction property var sendModal @@ -28,7 +28,7 @@ Item { QtObject { id: d - readonly property bool isIncoming: root.isTransactionValid ? root.transaction.to === currentAccount.address : false + readonly property bool isIncoming: root.isTransactionValid ? root.transaction.to === root.overview.mixedcaseAddress : false readonly property bool isNFT: root.isTransactionValid ? root.transaction.isNFT : false readonly property string savedAddressNameTo: root.isTransactionValid ? d.getNameForSavedWalletAddress(transaction.to) : "" readonly property string savedAddressNameFrom: root.isTransactionValid ? d.getNameForSavedWalletAddress(transaction.from): "" diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index 23462de049..8af00ac1d8 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -53,7 +53,6 @@ QtObject { property var userProfileInst: userProfile property var accounts: walletSectionSendInst.accounts - property var currentAccount: walletSectionCurrent // Not Refactored Yet // property var profileModelInst: profileModel diff --git a/ui/imports/shared/popups/AccountsModalHeader.qml b/ui/imports/shared/popups/AccountsModalHeader.qml index 5c1bdb0091..2275528934 100644 --- a/ui/imports/shared/popups/AccountsModalHeader.qml +++ b/ui/imports/shared/popups/AccountsModalHeader.qml @@ -18,6 +18,7 @@ import "../views" StatusFloatingButtonsSelector { id: root + property string currentAddress property var selectedAccount // Expected signature: function(newAccount) property var changeSelectedAccount: function(){} @@ -50,12 +51,15 @@ StatusFloatingButtonsSelector { } Component.onCompleted: { // on model reset, set the selected account to the one that was previously selected - if(root.selectedAccount === null) { + if(!root.selectedAccount) { if(root.currentIndex === index) { changeSelectedAccount(model) } - } - else { + if(root.currentAddress === model.address) { + root.currentIndex = index + changeSelectedAccount(model) + } + } else { // if the selectedAccount is watch only then select 0th item if(index === 0 && !!root.selectedAccount && root.selectedAccount.walletType === Constants.watchWalletType) { changeSelectedAccount(model) diff --git a/ui/imports/shared/popups/SendModal.qml b/ui/imports/shared/popups/SendModal.qml index 67b01ab745..809cd26436 100644 --- a/ui/imports/shared/popups/SendModal.qml +++ b/ui/imports/shared/popups/SendModal.qml @@ -36,7 +36,7 @@ StatusDialog { property var store: TransactionStore{} property var contactsStore: store.contactStore property var currencyStore: store.currencyStore - property var selectedAccount: store.currentAccount + property var selectedAccount property var bestRoutes property alias addressText: recipientLoader.addressText property bool isLoading: false @@ -159,10 +159,12 @@ StatusDialog { inverted: true } } - selectedAccount: popup.selectedAccount + currentAddress: popup.store.overview.mixedcaseAddress changeSelectedAccount: function(newAccount) { popup.selectedAccount = newAccount - assetSelector.selectedAsset = store.getAsset(selectedAccount.assets, assetSelector.selectedAsset.symbol) + if (assetSelector.selectedAsset) { + assetSelector.selectedAsset = store.getAsset(popup.selectedAccount.assets, assetSelector.selectedAsset.symbol) + } } } diff --git a/ui/imports/shared/status/StatusStickerMarket.qml b/ui/imports/shared/status/StatusStickerMarket.qml index b7b52c9671..5a4a3609fd 100644 --- a/ui/imports/shared/status/StatusStickerMarket.qml +++ b/ui/imports/shared/status/StatusStickerMarket.qml @@ -201,7 +201,7 @@ Item { sendType: Constants.SendType.StickersBuy preSelectedRecipient: root.store.stickersStore.getStickersMarketAddress() preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price)) - preSelectedAsset: store.getAsset(buyStickersModal.store.currentAccount.assets, JSON.parse(root.store.stickersStore.getStatusToken()).symbol) + preSelectedAsset: store.getAsset(buyStickersModal.store.assets, JSON.parse(root.store.stickersStore.getStatusToken()).symbol) sendTransaction: function() { if(bestRoutes.length === 1) { let path = bestRoutes[0] diff --git a/ui/imports/shared/status/StatusStickerPackClickPopup.qml b/ui/imports/shared/status/StatusStickerPackClickPopup.qml index 55be770057..83c81f122a 100644 --- a/ui/imports/shared/status/StatusStickerPackClickPopup.qml +++ b/ui/imports/shared/status/StatusStickerPackClickPopup.qml @@ -71,7 +71,7 @@ ModalPopup { sendType: Constants.SendType.StickersBuy preSelectedRecipient: stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress() preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price)) - preSelectedAsset: store.getAsset(buyStickersPackModal.store.currentAccount.assets, JSON.parse(stickerPackDetailsPopup.store.stickersStore.getStatusToken()).symbol) + preSelectedAsset: store.getAsset(buyStickersPackModal.store.assets, JSON.parse(stickerPackDetailsPopup.store.stickersStore.getStatusToken()).symbol) sendTransaction: function() { if(bestRoutes.length === 1) { let path = bestRoutes[0] diff --git a/ui/imports/shared/stores/NetworkConnectionStore.qml b/ui/imports/shared/stores/NetworkConnectionStore.qml index 75e1688740..4dc27b63ce 100644 --- a/ui/imports/shared/stores/NetworkConnectionStore.qml +++ b/ui/imports/shared/stores/NetworkConnectionStore.qml @@ -11,9 +11,9 @@ QtObject { readonly property bool isOnline: mainModule.isOnline - readonly property bool balanceCache: walletSectionCurrent.hasBalanceCache - readonly property bool marketValuesCache: walletSectionCurrent.hasMarketValuesCache - readonly property bool collectiblesCache: walletSectionCurrent.getHasCollectiblesCache() + readonly property bool balanceCache: walletSectionAssets.hasBalanceCache + readonly property bool marketValuesCache: walletSectionAssets.hasMarketValuesCache + readonly property bool collectiblesCache: walletSectionCollectibles.getHasCollectiblesCache() readonly property var blockchainNetworksDown: !!networkConnectionModule.blockchainNetworkConnection.chainIds ? networkConnectionModule.blockchainNetworkConnection.chainIds.split(";") : [] readonly property bool atleastOneBlockchainNetworkAvailable: blockchainNetworksDown.length < networksModule.all.count @@ -31,13 +31,13 @@ QtObject { networkConnectionModule.marketValuesNetworkConnection.completelyDown ? qsTr("Requires CryptoCompare or CoinGecko, both of which are currently unavailable"): "" - readonly property bool notOnlineWithNoCache: !isOnline && !walletSectionCurrent.hasBalanceCache && !walletSectionCurrent.hasMarketValuesCache + readonly property bool notOnlineWithNoCache: !isOnline && !walletSectionAssets.hasBalanceCache && !walletSectionAssets.hasMarketValuesCache readonly property string notOnlineWithNoCacheText: qsTr("Internet connection lost. Data could not be retrieved.") - readonly property bool noBlockchainConnectionAndNoCache: networkConnectionModule.blockchainNetworkConnection.completelyDown && !walletSectionCurrent.hasBalanceCache + readonly property bool noBlockchainConnectionAndNoCache: networkConnectionModule.blockchainNetworkConnection.completelyDown && !walletSectionAssets.hasBalanceCache readonly property string noBlockchainConnectionAndNoCacheText: qsTr("Token balances are fetched from Pocket Network (POKT) and Infura which are both curently unavailable") - readonly property bool noMarketConnectionAndNoCache: networkConnectionModule.marketValuesNetworkConnection.completelyDown && !walletSectionCurrent.hasMarketValuesCache + readonly property bool noMarketConnectionAndNoCache: networkConnectionModule.marketValuesNetworkConnection.completelyDown && !walletSectionAssets.hasMarketValuesCache readonly property string noMarketConnectionAndNoCacheText: qsTr("Market values are fetched from CryptoCompare and CoinGecko which are both currently unavailable") readonly property bool noBlockchainAndMarketConnectionAndNoCache: noBlockchainConnectionAndNoCache && noMarketConnectionAndNoCache diff --git a/ui/imports/shared/stores/RootStore.qml b/ui/imports/shared/stores/RootStore.qml index 1e5713f57e..f0cac70692 100644 --- a/ui/imports/shared/stores/RootStore.qml +++ b/ui/imports/shared/stores/RootStore.qml @@ -40,7 +40,6 @@ QtObject { property var historyTransactions: Global.appIsReady? walletSectionTransactions.model : null property bool isNonArchivalNode: history ? history.isNonArchivalNode : false - property var currentAccount: Global.appIsReady? walletSectionCurrent : null property var marketValueStore: TokenMarketValuesStore{} function getNetworkColor(chainId) { diff --git a/ui/imports/shared/stores/TransactionStore.qml b/ui/imports/shared/stores/TransactionStore.qml index 9453167b26..8d8a126f8f 100644 --- a/ui/imports/shared/stores/TransactionStore.qml +++ b/ui/imports/shared/stores/TransactionStore.qml @@ -19,8 +19,8 @@ QtObject { property string currentCurrency: walletSection.currentCurrency property var allNetworks: networksModule.all + property var overview: walletSectionOverview property var accounts: walletSectionSendInst.accounts - property var currentAccount: walletSectionCurrent property string signingPhrase: walletSection.signingPhrase property var savedAddressesModel: SortFilterProxyModel { sourceModel: walletSectionSavedAddresses.model diff --git a/ui/imports/shared/views/AssetsView.qml b/ui/imports/shared/views/AssetsView.qml index 97b71010f0..6a66e419b3 100644 --- a/ui/imports/shared/views/AssetsView.qml +++ b/ui/imports/shared/views/AssetsView.qml @@ -16,7 +16,7 @@ import shared.controls 1.0 Item { id: root - property var account + property var assets property var networkConnectionStore property bool assetDetailsLaunched: false @@ -39,7 +39,7 @@ Item { SortFilterProxyModel { id: filteredModel - sourceModel: account.assets + sourceModel: assets filters: [ ExpressionFilter { expression: visibleForNetworkWithPositiveBalance || loading diff --git a/ui/imports/shared/views/HistoryView.qml b/ui/imports/shared/views/HistoryView.qml index 7ca37671a3..1532e921c3 100644 --- a/ui/imports/shared/views/HistoryView.qml +++ b/ui/imports/shared/views/HistoryView.qml @@ -20,15 +20,15 @@ import "../controls" ColumnLayout { id: root - property var assets + property var overview property int pageSize: 20 // number of transactions per page signal launchTransactionDetail(var transaction) function fetchHistory() { - if (!RootStore.isFetchingHistory(root.assets.address)) { + if (!RootStore.isFetchingHistory(root.overview.mixedcaseAddress)) { d.isLoading = true - RootStore.loadTransactionsForAccount(root.assets.address, pageSize) + RootStore.loadTransactionsForAccount(root.overview.mixedcaseAddress, pageSize) } } @@ -40,7 +40,7 @@ ColumnLayout { Connections { target: RootStore.history function onLoadingTrxHistoryChanged(isLoading: bool, address: string) { - if (root.assets.address.toLowerCase() === address.toLowerCase()) { + if (root.overview.mixedcaseAddress.toLowerCase() === address.toLowerCase()) { d.isLoading = isLoading } } @@ -178,7 +178,7 @@ ColumnLayout { TransactionDelegate { width: ListView.view.width modelData: model - isIncoming: isModelDataValid ? modelData.to === root.assets.address: false + isIncoming: isModelDataValid ? modelData.to === root.overview.mixedcaseAddress: false currentCurrency: RootStore.currentCurrency cryptoValue: isModelDataValid ? modelData.value.amount : 0.0 fiatValue: isModelDataValid ? RootStore.getFiatValue(cryptoValue, symbol, currentCurrency): 0.0 diff --git a/ui/imports/shared/views/NetworkCardsComponent.qml b/ui/imports/shared/views/NetworkCardsComponent.qml index 88cba9af0a..5567f31d0f 100644 --- a/ui/imports/shared/views/NetworkCardsComponent.qml +++ b/ui/imports/shared/views/NetworkCardsComponent.qml @@ -99,7 +99,7 @@ Item { property int routeOnNetwork: 0 property bool selectedAssetValid: selectedAccount && selectedAccount !== undefined && selectedAsset !== undefined property double tokenBalanceOnChain: selectedAssetValid ? root.store.getTokenBalanceOnChain(selectedAccount, model.chainId, root.selectedSymbol).amount : 0.0 - property bool hasGas: selectedAssetValid && requiredGasInEth !== undefined ? selectedAccount.hasGas(model.chainId, model.nativeCurrencySymbol, requiredGasInEth) : false + property bool hasGas: selectedAssetValid && requiredGasInEth !== undefined ? root.store.walletSectionSendInst.hasGas(selectedAccount.address, model.chainId, model.nativeCurrencySymbol, requiredGasInEth) : false property double advancedInputCurrencyAmount: selectedAssetValid && advancedInput.valid ? LocaleUtils.numberFromLocaleString(advancedInputText, LocaleUtils.userInputLocale) : 0.0 primaryText: model.chainName diff --git a/ui/imports/shared/views/profile/ProfileShowcaseView.qml b/ui/imports/shared/views/profile/ProfileShowcaseView.qml index a50df8a627..6b368bb278 100644 --- a/ui/imports/shared/views/profile/ProfileShowcaseView.qml +++ b/ui/imports/shared/views/profile/ProfileShowcaseView.qml @@ -335,7 +335,7 @@ Control { visible: count model: SortFilterProxyModel { // TODO show assets for all accounts, not just the current one? - sourceModel: root.isCurrentUser ? root.walletStore.currentAccount.assets : null // TODO show other users too + sourceModel: root.isCurrentUser ? root.walletStore.assets : null // TODO show other users too filters: ValueFilter { roleName: "visibleForNetworkWithPositiveBalance" value: true