diff --git a/src/app/modules/main/profile_section/profile/models/profile_preferences_asset_item.nim b/src/app/modules/main/profile_section/profile/models/profile_preferences_asset_item.nim index 4536626b5d..eee201e608 100644 --- a/src/app/modules/main/profile_section/profile/models/profile_preferences_asset_item.nim +++ b/src/app/modules/main/profile_section/profile/models/profile_preferences_asset_item.nim @@ -18,6 +18,7 @@ type name*: string enabledNetworkBalance*: CurrencyAmount color*: string + decimals*: int proc initProfileShowcaseAssetItem*(token: WalletTokenDto, visibility: ProfileShowcaseVisibility, order: int): ProfileShowcaseAssetItem = result = ProfileShowcaseAssetItem() @@ -29,6 +30,7 @@ proc initProfileShowcaseAssetItem*(token: WalletTokenDto, visibility: ProfileSho result.name = token.name result.enabledNetworkBalance = newCurrencyAmount(token.getTotalBalanceOfSupportedChains(), token.symbol, token.decimals, false) result.color = token.color + result.decimals = token.decimals proc toProfileShowcaseAssetItem*(jsonObj: JsonNode): ProfileShowcaseAssetItem = result = ProfileShowcaseAssetItem() @@ -43,8 +45,9 @@ proc toProfileShowcaseAssetItem*(jsonObj: JsonNode): ProfileShowcaseAssetItem = discard jsonObj.getProp("symbol", result.symbol) discard jsonObj.getProp("name", result.name) discard jsonObj.getProp("color", result.color) + discard jsonObj.getProp("decimals", result.decimals) - result.enabledNetworkBalance = jsonObj{"enabledNetworkBalance"}.toCurrencyAmount() + result.enabledNetworkBalance = newCurrencyAmount(jsonObj{"enabledNetworkBalance"}.getFloat, result.symbol, result.decimals, false) proc toShowcasePreferenceItem*(self: ProfileShowcaseAssetItem): ProfileShowcaseAssetPreference = result = ProfileShowcaseAssetPreference() diff --git a/src/app/modules/main/profile_section/profile/models/profile_preferences_assets_model.nim b/src/app/modules/main/profile_section/profile/models/profile_preferences_assets_model.nim index 792b6612cf..2fe17f8bd6 100644 --- a/src/app/modules/main/profile_section/profile/models/profile_preferences_assets_model.nim +++ b/src/app/modules/main/profile_section/profile/models/profile_preferences_assets_model.nim @@ -12,6 +12,7 @@ type Name EnabledNetworkBalance Color + Decimals QtObject: type @@ -55,6 +56,7 @@ QtObject: ModelRole.Name.int: "name", ModelRole.EnabledNetworkBalance.int: "enabledNetworkBalance", ModelRole.Color.int: "color", + ModelRole.Decimals.int: "decimals", }.toTable method data(self: ProfileShowcaseAssetsModel, index: QModelIndex, role: int): QVariant = @@ -80,6 +82,8 @@ QtObject: result = newQVariant(item.enabledNetworkBalance) of ModelRole.Color: result = newQVariant(item.color) + of ModelRole.Decimals: + result = newQVariant(item.decimals) proc findIndexForAsset(self: ProfileShowcaseAssetsModel, symbol: string): int = for i in 0 ..< self.items.len: @@ -120,6 +124,7 @@ QtObject: ModelRole.Name.int, ModelRole.EnabledNetworkBalance.int, ModelRole.Color.int, + ModelRole.Decimals.int, ]) proc upsertItemJson(self: ProfileShowcaseAssetsModel, itemJson: string) {.slot.} = diff --git a/storybook/pages/ProfileShowcaseAssetsPanelPage.qml b/storybook/pages/ProfileShowcaseAssetsPanelPage.qml index 217dd4e46c..2c435784c5 100644 --- a/storybook/pages/ProfileShowcaseAssetsPanelPage.qml +++ b/storybook/pages/ProfileShowcaseAssetsPanelPage.qml @@ -13,6 +13,8 @@ import utils 1.0 import Storybook 1.0 import Models 1.0 +import AppLayouts.Wallet.stores 1.0 + SplitView { id: root @@ -26,63 +28,8 @@ SplitView { communityTokensStore: CommunityTokensStore {} } - ListModel { - id: assetsModel - - readonly property var data: [ - { - name: "Decentraland", - symbol: "MANA", - enabledNetworkBalance: { - amount: 301, - symbol: "MANA" - }, - changePct24hour: -2.1, - }, - { - name: "Ave Maria", - symbol: "AAVE", - enabledNetworkBalance: { - amount: 23.3, - symbol: "AAVE" - }, - changePct24hour: 4.56, - }, - { - name: "Polymorphism", - symbol: "POLY", - enabledNetworkBalance: { - amount: 3590, - symbol: "POLY" - }, - changePct24hour: -11.6789, - }, - { - name: "Common DDT", - symbol: "CDT", - enabledNetworkBalance: { - amount: 1000, - symbol: "CDT" - }, - changePct24hour: 0, - }, - { - name: "Makers' choice", - symbol: "MKR", - enabledNetworkBalance: { - amount: 1.3, - symbol: "MKR" - }, - changePct24hour: -1, - }, - { - name: "GetOuttaHere", - symbol: "InvisibleHere", - enabledNetworkBalance: {}, - changePct24hour: 0, - } - ] - Component.onCompleted: append(data) + readonly property WalletAssetsStore walletAssetStore: WalletAssetsStore { + assetsWithFilteredBalances: walletAssetStore.groupedAccountsAssetsModel } ListModel { @@ -126,8 +73,14 @@ SplitView { ProfileShowcaseAssetsPanel { id: showcasePanel width: 500 - baseModel: assetsModel + baseModel: walletAssetStore.groupedAccountAssetsModel showcaseModel: inShowcaseAssetsModel + formatCurrencyAmount: function (amount, symbol) { + return ({amount: amount, + symbol: symbol.toUpperCase(), + displayDecimals: 4, + stripTrailingZeroes: false}) + } } } diff --git a/ui/app/AppLayouts/Profile/ProfileLayout.qml b/ui/app/AppLayouts/Profile/ProfileLayout.qml index 8960d268c2..23ae1f8d71 100644 --- a/ui/app/AppLayouts/Profile/ProfileLayout.qml +++ b/ui/app/AppLayouts/Profile/ProfileLayout.qml @@ -34,6 +34,8 @@ StatusSectionLayout { property var networkConnectionStore required property TokensStore tokensStore required property TransactionStore transactionStore + required property WalletAssetsStore walletAssetsStore + required property SharedStores.CurrenciesStore currencyStore backButtonName: root.store.backButtonName notificationCount: activityCenterStore.unreadNotificationsCount @@ -124,6 +126,8 @@ StatusSectionLayout { implicitWidth: parent.width implicitHeight: parent.height + walletAssetsStore: root.walletAssetsStore + currencyStore: root.currencyStore walletStore: root.store.walletStore profileStore: root.store.profileStore privacyStore: root.store.privacyStore diff --git a/ui/app/AppLayouts/Profile/controls/AssetShowcaseDelegate.qml b/ui/app/AppLayouts/Profile/controls/AssetShowcaseDelegate.qml index 7169359519..4f9d0473a9 100644 --- a/ui/app/AppLayouts/Profile/controls/AssetShowcaseDelegate.qml +++ b/ui/app/AppLayouts/Profile/controls/AssetShowcaseDelegate.qml @@ -1,12 +1,26 @@ import QtQuick 2.15 +import StatusQ 0.1 import StatusQ.Core 0.1 import utils 1.0 ShowcaseDelegate { + id: root + + property var formatCurrencyAmount: function(amount, symbol){} + property double totalValue: !!showcaseObj && !!showcaseObj.decimals ? balancesAggregator.value/(10 ** showcaseObj.decimals): 0 + title: !!showcaseObj && !!showcaseObj.name ? showcaseObj.name : "" - secondaryTitle: !!showcaseObj ? LocaleUtils.currencyAmountToLocaleString(showcaseObj.enabledNetworkBalance) : Qt.locale().zeroDigit + secondaryTitle: !!showcaseObj && !!showcaseObj.enabledNetworkBalance ? + LocaleUtils.currencyAmountToLocaleString(showcaseObj.enabledNetworkBalance) : + !!showcaseObj && !!showcaseObj.symbol ? formatCurrencyAmount(totalValue, showcaseObj.symbol): Qt.locale().zeroDigit hasImage: true icon.source: !!showcaseObj ? Constants.tokenIcon(showcaseObj.symbol) : "" + + SumAggregator { + id: balancesAggregator + model: !!showcaseObj && !!showcaseObj.balances ? showcaseObj.balances: null + roleName: "balance" + } } diff --git a/ui/app/AppLayouts/Profile/panels/ProfileShowcaseAssetsPanel.qml b/ui/app/AppLayouts/Profile/panels/ProfileShowcaseAssetsPanel.qml index dbcaea5876..4aceb423b6 100644 --- a/ui/app/AppLayouts/Profile/panels/ProfileShowcaseAssetsPanel.qml +++ b/ui/app/AppLayouts/Profile/panels/ProfileShowcaseAssetsPanel.qml @@ -7,8 +7,10 @@ import AppLayouts.Profile.controls 1.0 ProfileShowcasePanel { id: root + property var formatCurrencyAmount: function(amount, symbol){} + keyRole: "symbol" - roleNames: ["symbol", "name", "enabledNetworkBalance"].concat(showcaseRoles) + roleNames: ["symbol", "name", "enabledNetworkBalance", "decimals"].concat(showcaseRoles) filterFunc: (modelData) => modelData.symbol !== "" && !showcaseModel.hasItemInShowcase(modelData.symbol) hiddenPlaceholderBanner: qsTr("Assets here will show on your profile") showcasePlaceholderBanner: qsTr("Assets here will be hidden from your profile") @@ -18,6 +20,9 @@ ProfileShowcasePanel { showcaseObj: modelData dragParent: dragParentData visualIndex: visualIndexData + formatCurrencyAmount: function(amount, symbol) { + return root.formatCurrencyAmount(amount, symbol) + } onShowcaseVisibilityRequested: { var tmpObj = Object() root.roleNames.forEach(role => tmpObj[role] = showcaseObj[role]) diff --git a/ui/app/AppLayouts/Profile/panels/ProfileShowcasePanel.qml b/ui/app/AppLayouts/Profile/panels/ProfileShowcasePanel.qml index 21eb2b764a..8a4fe9d6fd 100644 --- a/ui/app/AppLayouts/Profile/panels/ProfileShowcasePanel.qml +++ b/ui/app/AppLayouts/Profile/panels/ProfileShowcasePanel.qml @@ -80,6 +80,11 @@ Control { onDropped: function(drop) { var showcaseObj = drop.source.showcaseObj + // need to set total balance for an asset + if (drop.source.totalValue !== undefined) { + showcaseObj.enabledNetworkBalance = drop.source.totalValue + } + var tmpObj = Object() root.roleNames.forEach(role => tmpObj[role] = showcaseObj[role]) tmpObj.showcaseVisibility = visibilityDropAreaLocal.showcaseVisibility diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index 5449396683..40ac9c4e00 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -25,7 +25,6 @@ QtObject { } // TODO(alaibe): there should be no access to wallet section, create collectible in profile property var overview: walletSectionOverview - property var assets: walletSectionAssets.assets property var accounts: Global.appIsReady? accountsModule.accounts : null property var originModel: accountsModule.keyPairModel diff --git a/ui/app/AppLayouts/Profile/views/MyProfileView.qml b/ui/app/AppLayouts/Profile/views/MyProfileView.qml index c33c337069..f1da1e8abc 100644 --- a/ui/app/AppLayouts/Profile/views/MyProfileView.qml +++ b/ui/app/AppLayouts/Profile/views/MyProfileView.qml @@ -6,6 +6,7 @@ import utils 1.0 import shared 1.0 import shared.panels 1.0 import shared.popups 1.0 +import shared.stores 1.0 import shared.controls.chat 1.0 import "../popups" @@ -18,6 +19,8 @@ import StatusQ.Core.Theme 0.1 import StatusQ.Components 0.1 import StatusQ.Controls 0.1 +import AppLayouts.Wallet.stores 1.0 + SettingsContentBase { id: root @@ -25,6 +28,9 @@ SettingsContentBase { property ProfileStore profileStore property PrivacyStore privacyStore property ContactsStore contactsStore + required property WalletAssetsStore walletAssetsStore + required property CurrenciesStore currencyStore + property var communitiesModel titleRowComponentLoader.sourceComponent: StatusButton { @@ -75,6 +81,8 @@ SettingsContentBase { privacyStore: root.privacyStore walletStore: root.walletStore communitiesModel: root.communitiesModel + walletAssetsStore: root.walletAssetsStore + currencyStore: root.currencyStore onVisibleChanged: if (visible) stackLayout.Layout.preferredHeight = settingsView.implicitHeight Component.onCompleted: stackLayout.Layout.preferredHeight = Qt.binding(() => settingsView.implicitHeight) diff --git a/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml b/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml index adec91e558..fd38e33c5a 100644 --- a/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml +++ b/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml @@ -4,6 +4,7 @@ import QtQuick.Layouts 1.13 import utils 1.0 import shared 1.0 +import shared.stores 1.0 import shared.panels 1.0 import shared.popups 1.0 import shared.controls.chat 1.0 @@ -18,6 +19,8 @@ import StatusQ.Core.Theme 0.1 import StatusQ.Components 0.1 import StatusQ.Controls 0.1 +import AppLayouts.Wallet.stores 1.0 + ColumnLayout { id: root @@ -26,6 +29,8 @@ ColumnLayout { property PrivacyStore privacyStore property ProfileStore profileStore property WalletStore walletStore + required property WalletAssetsStore walletAssetsStore + required property CurrenciesStore currencyStore property var communitiesModel property bool hasAnyProfileShowcaseChanges: false @@ -244,9 +249,12 @@ ColumnLayout { id: profileShowcaseAssetsPanel Layout.minimumHeight: implicitHeight Layout.maximumHeight: implicitHeight - baseModel: root.walletStore.assets + baseModel: root.walletAssetsStore.groupedAccountAssetsModel showcaseModel: root.profileStore.profileShowcaseAssetsModel onShowcaseEntryChanged: hasAnyProfileShowcaseChanges = true + formatCurrencyAmount: function(amount, symbol) { + return root.currencyStore.formatCurrencyAmount(amount, symbol) + } } } } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 7cbd29ad80..f323dc0049 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -1301,6 +1301,8 @@ Item { networkConnectionStore: appMain.networkConnectionStore tokensStore: appMain.tokensStore transactionStore: appMain.transactionStore + walletAssetsStore: appMain.walletAssetsStore + currencyStore: appMain.currencyStore } }