fix: refactor the token mgmt controller and models placement

put the respective controller instances into WalletAssetsStore and
CollectiblesStore, so that they can be accessed from other places, like
the SendModal or some popups

Iterates #13293
This commit is contained in:
Lukáš Tinkl 2024-01-29 19:02:59 +01:00 committed by Lukáš Tinkl
parent c791173c81
commit 12bbaee43f
8 changed files with 54 additions and 53 deletions

View File

@ -29,6 +29,18 @@ SplitView {
includeCommunityCollectibles: ctrlIncludeCommunityCollectibles.checked
}
RolesRenamingModel {
id: renamedModel
sourceModel: collectiblesModel
mapping: [
RoleRename {
from: "uid"
to: "symbol"
}
]
}
Popups {
popupParent: root
rootStore: QtObject {}
@ -62,7 +74,7 @@ SplitView {
SplitView.fillWidth: true
SplitView.fillHeight: true
collectiblesModel: collectiblesModel
collectiblesModel: renamedModel
networkFilters: d.networksChainsCurrentlySelected
addressFilters: d.addressesSelected
filterVisible: ctrlFilterVisible.checked

View File

@ -35,6 +35,7 @@ StatusSectionLayout {
required property TokensStore tokensStore
required property TransactionStore transactionStore
required property WalletAssetsStore walletAssetsStore
required property CollectiblesStore collectiblesStore
required property SharedStores.CurrenciesStore currencyStore
backButtonName: root.store.backButtonName
@ -195,6 +196,8 @@ StatusSectionLayout {
rootStore: root.store
tokensStore: root.tokensStore
networkConnectionStore: root.networkConnectionStore
assetsStore: root.walletAssetsStore
collectiblesStore: root.collectiblesStore
emojiPopup: root.emojiPopup
sectionTitle: root.store.getNameForSubsection(Constants.settingsSubsection.wallet)
contentWidth: d.contentWidth

View File

@ -34,6 +34,8 @@ SettingsContentBase {
property var walletStore: rootStore.walletStore
required property TokensStore tokensStore
property var networkConnectionStore
required property WalletAssetsStore assetsStore
required property CollectiblesStore collectiblesStore
readonly property int mainViewIndex: 0
readonly property int networksViewIndex: 1
@ -313,10 +315,8 @@ SettingsContentBase {
tokenListUpdatedAt: tokensStore.tokenListUpdatedAt
sourcesOfTokensModel: tokensStore.sourcesOfTokensModel
tokensListModel: tokensStore.extendedFlatTokensModel
baseWalletAssetsModel: RootStore.walletAssetsStore.groupedAccountAssetsModel
baseWalletCollectiblesModel: {
return RootStore.collectiblesStore.allCollectiblesModel
}
baseWalletAssetsModel: root.assetsStore.groupedAccountAssetsModel
baseWalletCollectiblesModel: root.collectiblesStore.allCollectiblesModel
getCurrencyAmount: function (balance, symbol) {
return RootStore.currencyStore.getCurrencyAmount(balance, symbol)
}

View File

@ -38,8 +38,6 @@ Item {
if (tabBar.currentIndex > d.hiddenTabIndex)
return false
// FIXME take advanced settings into account here too (#13178)
if (tabBar.currentIndex === d.collectiblesTabIndex && baseWalletCollectiblesModel.isFetching)
return false
return loader.item && loader.item.dirty
}
@ -76,18 +74,8 @@ Item {
}
// collectibles
readonly property var renamedCollectiblesModel: RolesRenamingModel {
sourceModel: root.baseWalletCollectiblesModel
mapping: [
RoleRename {
from: "uid"
to: "symbol"
}
]
}
readonly property var collectiblesController: ManageTokensController {
sourceModel: d.renamedCollectiblesModel
sourceModel: root.baseWalletCollectiblesModel
settingsKey: "WalletCollectibles"
onTokenHidden: (symbol, name) => Global.displayToastMessage(
qsTr("%1 was successfully hidden").arg(name), "", "checkmark-circle",
@ -101,25 +89,6 @@ Item {
qsTr("%1 community collectibles are now visible").arg(communityName), "", "checkmark-circle",
false, Constants.ephemeralNotificationType.success, "")
}
function checkLoadMoreCollectibles() {
if (tabBar.currentIndex !== collectiblesTabIndex)
return
// If there is no more items to load or we're already fetching, return
if (!root.baseWalletCollectiblesModel.hasMore || root.baseWalletCollectiblesModel.isFetching)
return
root.baseWalletCollectiblesModel.loadMore()
}
}
Connections {
target: root.baseWalletCollectiblesModel
function onHasMoreChanged() {
d.checkLoadMoreCollectibles()
}
function onIsFetchingChanged() {
d.checkLoadMoreCollectibles()
}
}
ColumnLayout {

View File

@ -1,5 +1,8 @@
import QtQuick 2.15
import StatusQ 0.1
import StatusQ.Models 0.1
import QtQuick 2.12
import utils 1.0
QtObject {
@ -10,7 +13,23 @@ QtObject {
/* This list contains the complete list of collectibles with separate
entry per collectible which has a unique [network + contractAddress + tokenID] */
readonly property var allCollectiblesModel: !!root._allCollectiblesModule ? root._allCollectiblesModule.allCollectiblesModel : null
readonly property var _allCollectiblesModel: !!root._allCollectiblesModule ? root._allCollectiblesModule.allCollectiblesModel : null
readonly property var allCollectiblesModel: RolesRenamingModel {
sourceModel: root._allCollectiblesModel
mapping: [
RoleRename {
from: "uid"
to: "symbol"
}
]
}
// custom controller used for sorting/filtering (w/o source model)
readonly property var manageCollectiblesController: ManageTokensController {
settingsKey: "WalletCollectibles"
}
/* The following are used to display the detailed view of a collectible */
readonly property var detailedCollectible: Global.appIsReady ? walletSection.collectibleDetailsController.detailedEntry : null

View File

@ -1,18 +1,25 @@
import QtQuick 2.15
import SortFilterProxyModel 0.2
import StatusQ 0.1
import StatusQ.Models 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
import shared.stores 1.0
import utils 1.0
import SortFilterProxyModel 0.2
QtObject {
id: root
property TokensStore walletTokensStore
// custom controller used for sorting/filtering (w/o source model)
readonly property var manageAssetsController: ManageTokensController {
settingsKey: "WalletAssets"
}
/* PRIVATE: This model renames the role "key" to "tokensKey" in TokensBySymbolModel so that
it can be easily joined with the Account Assets model */
readonly property var _renamedTokensBySymbolModel: RolesRenamingModel {

View File

@ -53,17 +53,6 @@ ColumnLayout {
readonly property bool isCustomView: cmbTokenOrder.currentValue === SortOrderComboBox.TokenOrderCustom
readonly property var renamedModel: RolesRenamingModel {
sourceModel: root.collectiblesModel
mapping: [
RoleRename {
from: "uid"
to: "symbol"
}
]
}
readonly property bool hasCollectibles: nonCommunityModel.count
readonly property bool hasCommunityCollectibles: communityModel.count
@ -71,7 +60,7 @@ ColumnLayout {
readonly property var controller: ManageTokensController {
settingsKey: "WalletCollectibles"
sourceModel: d.renamedModel
sourceModel: root.collectiblesModel
}
readonly property var nwFilters: root.networkFilters.split(":")
@ -96,7 +85,7 @@ ColumnLayout {
id: customFilter
property bool isCommunity
sourceModel: d.renamedModel
sourceModel: root.collectiblesModel
proxyRoles: JoinRole {
name: "groupName"
roleNames: ["collectionName", "communityName"]

View File

@ -72,6 +72,7 @@ Item {
property CommunitiesStore communitiesStore: CommunitiesStore {}
readonly property WalletStore.TokensStore tokensStore: WalletStore.RootStore.tokensStore
readonly property WalletStore.WalletAssetsStore walletAssetsStore: WalletStore.RootStore.walletAssetsStore
readonly property WalletStore.CollectiblesStore walletCollectiblesStore: WalletStore.RootStore.collectiblesStore
readonly property CurrenciesStore currencyStore: CurrenciesStore{}
readonly property TransactionStore transactionStore: TransactionStore {
walletAssetStore: appMain.walletAssetsStore
@ -1302,6 +1303,7 @@ Item {
tokensStore: appMain.tokensStore
transactionStore: appMain.transactionStore
walletAssetsStore: appMain.walletAssetsStore
collectiblesStore: appMain.walletCollectiblesStore
currencyStore: appMain.currencyStore
}
}