From 38914df0f05a0b8979220ef3e29d3ed2d99286fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Fri, 14 Jun 2024 19:50:52 +0200 Subject: [PATCH] chore(Wallet): Integrate refactored AssetView and related adaptor --- .../Wallet/views/AssetsDetailView.qml | 6 +- .../AppLayouts/Wallet/views/RightTabView.qml | 115 ++++++++++++++---- .../shared/stores/NetworkConnectionStore.qml | 23 ++++ 3 files changed, 116 insertions(+), 28 deletions(-) diff --git a/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml b/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml index 37291d42f4..bed55cd37d 100644 --- a/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml +++ b/ui/app/AppLayouts/Wallet/views/AssetsDetailView.qml @@ -39,7 +39,7 @@ Item { readonly property string symbol: !!root.token? root.token.symbol?? "" : "" property bool marketDetailsLoading: !!root.token? root.token.marketDetailsLoading?? false : false property bool tokenDetailsLoading: !!root.token? root.token.detailsLoading?? false: false - property bool isCommunityAsset: !!root.token && token.isCommunityAsset !== undefined ? token.isCommunityAsset : false + property bool isCommunityAsset: !!root.token && !!token.communityId readonly property LeftJoinModel addressPerChainModel: LeftJoinModel { leftModel: token && token.addressPerChain ? token.addressPerChain: null @@ -79,10 +79,10 @@ Item { } asset.isImage: true primaryText: token && token.name ? token.name : Constants.dummyText - secondaryText: token ? LocaleUtils.currencyAmountToLocaleString(root.currencyStore.getCurrencyAmount(token.currentBalance, token.symbol)) : Constants.dummyText + secondaryText: token ? token.balanceText : Constants.dummyText tertiaryText: { if (!d.isCommunityAsset) { - let totalCurrencyBalance = token && token.currentCurrencyBalance && token.symbol ? token.currentCurrencyBalance : 0 + let totalCurrencyBalance = token ? token.balance * token.marketPrice : 0 return currencyStore.formatCurrencyAmount(totalCurrencyBalance, currencyStore.currentCurrency) } return "" diff --git a/ui/app/AppLayouts/Wallet/views/RightTabView.qml b/ui/app/AppLayouts/Wallet/views/RightTabView.qml index db8bd62554..33ffb1011b 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabView.qml @@ -1,9 +1,10 @@ import QtQuick 2.15 import QtQuick.Layouts 1.15 -import StatusQ.Core 0.1 import StatusQ.Controls 0.1 +import StatusQ.Core 0.1 import StatusQ.Core.Theme 0.1 +import StatusQ.Core.Utils 0.1 import utils 1.0 import shared.controls 1.0 @@ -141,36 +142,100 @@ RightTabBaseView { Component { id: assetsView - AssetsView { - areAssetsLoading: RootStore.overview.balanceLoading - controller: RootStore.walletAssetsStore.assetsController - networkFilters: RootStore.networkFilters - addressFilters: RootStore.addressFilters - overview: RootStore.overview - currencyStore: RootStore.currencyStore - networkConnectionStore: root.networkConnectionStore - tokensStore: RootStore.tokensStore - assetDetailsLaunched: stack.currentIndex === 2 - filterVisible: filterButton.checked + + AssetsViewNew { + + AssetsViewAdaptor { + id: assetsViewAdaptor + + accounts: RootStore.addressFilters + chains: RootStore.networkFilters + + marketValueThreshold: + RootStore.tokensStore.displayAssetsBelowBalance + ? RootStore.tokensStore.getDisplayAssetsBelowBalanceThresholdDisplayAmount() + : 0 + + Connections { + target: RootStore.tokensStore + + function displayAssetsBelowBalanceThresholdChanged() { + assetsViewAdaptor.marketValueThresholdChanged() + } + } + + tokensModel: RootStore.walletAssetsStore.groupedAccountAssetsModel + controller: RootStore.walletAssetsStore.assetsController + + formatBalance: (balance, symbol) => { + return LocaleUtils.currencyAmountToLocaleString( + RootStore.currencyStore.getCurrencyAmount(balance, symbol)) + } + + chainsError: (chains) => { + if (!root.networkConnectionStore) + return "" + return root.networkConnectionStore.getBlockchainNetworkDownText(chains) + } + } + + loading: RootStore.overview.balanceLoading + sorterVisible: filterButton.checked + customOrderAvailable: RootStore.walletAssetsStore.assetsController.hasSettings + model: assetsViewAdaptor.model + + marketDataError: !!root.networkConnectionStore + ? root.networkConnectionStore.getMarketNetworkDownText() + : "" + balanceError: { + if (!root.networkConnectionStore) + return "" + + return (root.networkConnectionStore.noBlockchainConnectionAndNoCache + && !root.networkConnectionStore.noMarketConnectionAndNoCache) + ? root.networkConnectionStore.noBlockchainConnectionAndNoCacheText + : "" + } + + formatFiat: balance => RootStore.currencyStore.formatCurrencyAmount( + balance, RootStore.currencyStore.currentCurrency) + + sendEnabled: root.networkConnectionStore.sendBuyBridgeEnabled && + !RootStore.overview.isWatchOnlyAccount && RootStore.overview.canSend + swapEnabled: !RootStore.overview.isWatchOnlyAccount + swapVisible: Global.featureFlags.swapEnabled + + onSendRequested: { + const symbol = ModelUtils.getByKey(model, "key", key, "symbol") + const modal = root.sendModal + + modal.preSelectedSendType = Constants.SendType.Transfer + modal.preSelectedHoldingID = symbol + modal.preSelectedHoldingType = Constants.TokenType.ERC20 + modal.onlyAssets = true + modal.open() + } + + onSwapRequested: root.launchSwapModal(key) + onReceiveRequested: root.launchShareAddressModal() + onCommunityClicked: Global.switchToCommunity(communityKey) + onManageTokensRequested: Global.changeAppSectionBySectionType( + Constants.appSection.profile, + Constants.settingsSubsection.wallet, + Constants.walletSettingsSubsection.manageAssets) onAssetClicked: { + const token = ModelUtils.getByKey(model, "key", key) + + SharedStores.RootStore.getHistoricalDataForToken( + token.symbol, RootStore.currencyStore.currentCurrency) + assetDetailView.token = token - RootStore.setCurrentViewedHolding(token.symbol, token.tokensKey, Constants.TokenType.ERC20) + RootStore.setCurrentViewedHolding(token.symbol, token.key, Constants.TokenType.ERC20) stack.currentIndex = 2 } - onSendRequested: (symbol) => { - root.sendModal.preSelectedSendType = Constants.SendType.Transfer - root.sendModal.preSelectedHoldingID = symbol - root.sendModal.preSelectedHoldingType = Constants.TokenType.ERC20 - root.sendModal.onlyAssets = true - root.sendModal.open() - } - onReceiveRequested: (symbol) => root.launchShareAddressModal() - onSwitchToCommunityRequested: (communityId) => Global.switchToCommunity(communityId) - onManageTokensRequested: Global.changeAppSectionBySectionType(Constants.appSection.profile, Constants.settingsSubsection.wallet, - Constants.walletSettingsSubsection.manageAssets) - onLaunchSwapModal: root.launchSwapModal(tokensKey) } } + Component { id: collectiblesView CollectiblesView { diff --git a/ui/imports/shared/stores/NetworkConnectionStore.qml b/ui/imports/shared/stores/NetworkConnectionStore.qml index ffe6dd8c01..160562be2e 100644 --- a/ui/imports/shared/stores/NetworkConnectionStore.qml +++ b/ui/imports/shared/stores/NetworkConnectionStore.qml @@ -64,6 +64,7 @@ QtObject { readonly property string stickersNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg(appNetworkName) readonly property string appNetworkName: ModelUtils.getByKey(networksModule.flatNetworks, "chainId", mainModule.appNetworkId, "chainName") + // DEPRECATED, use getBlockchainNetworkDownText instead function getBlockchainNetworkDownTextForToken(balances) { if(!!balances && !networkConnectionModule.blockchainNetworkConnection.completelyDown && !notOnlineWithNoCache) { let chainIdsDown = [] @@ -81,6 +82,28 @@ QtObject { return "" } + function getBlockchainNetworkDownText(chains) { + if (chains.length === 0 + || networkConnectionModule.blockchainNetworkConnection.completelyDown + || notOnlineWithNoCache) + return "" + + let chainIdsDown = [] + + for (let i = 0; i < chains.length; i++) { + const chainId = chains[i] + if(blockchainNetworksDown.includes(chainId)) + chainIdsDown.push(chainId) + } + if(chainIdsDown.length > 0) { + return qsTr("Pocket Network (POKT) & Infura are currently both unavailable for %1. %1 balances are as of %2.") + .arg(getChainIdsJointString(chainIdsDown)) + .arg(LocaleUtils.formatDateTime(new Date(networkConnectionModule.blockchainNetworkConnection.lastCheckedAt * 1000))) + } + + return "" + } + function getMarketNetworkDownText() { if(notOnlineWithNoCache) return notOnlineWithNoCacheText