refactor(CommunitySettings): Add SFPM for wallet accounts model in a single place

- It adds proxy of wallet accounts only in a single place (wallet root store) and pass the tuned model through the rest of views.

- It updates `storybook` accordingly.

Closes #11829
This commit is contained in:
Noelia 2023-08-09 14:31:58 +02:00 committed by Noelia
parent 23fa2f5df3
commit f721636452
15 changed files with 68 additions and 169 deletions

View File

@ -7,7 +7,8 @@ ListModel {
{ {
name: "helloworld", name: "helloworld",
emoji: "😋", emoji: "😋",
colorId: "primary", colorId: Constants.walletAccountColors.primary,
color: "#2A4AF5",
address: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240", address: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
walletType: "", walletType: "",
position: 0, position: 0,
@ -44,7 +45,8 @@ ListModel {
{ {
name: "Hot wallet (generated)", name: "Hot wallet (generated)",
emoji: "🚗", emoji: "🚗",
colorId: "army", colorId: Constants.walletAccountColors.army,
color: "#216266",
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881", address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881",
walletType: Constants.generatedWalletType, walletType: Constants.generatedWalletType,
position: 3, position: 3,
@ -62,7 +64,9 @@ ListModel {
}, },
{ {
name: "Family (seed)", name: "Family (seed)",
emoji: "🎨", colorId: "magenta", emoji: "🎨",
colorId: Constants.walletAccountColors.magenta,
color: "#EC266C",
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8882", address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8882",
walletType: Constants.seedWalletType, walletType: Constants.seedWalletType,
position: 1, position: 1,
@ -90,7 +94,8 @@ ListModel {
{ {
name: "Tag Heuer (watch)", name: "Tag Heuer (watch)",
emoji: "⌚", emoji: "⌚",
colorId: "copper", colorId: Constants.walletAccountColors.cooper,
color: "#CB6256",
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8883", address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8883",
walletType: Constants.watchWalletType, walletType: Constants.watchWalletType,
position: 2, position: 2,
@ -101,6 +106,7 @@ ListModel {
name: "Fab (key)", name: "Fab (key)",
emoji: "⌚", emoji: "⌚",
colorId: Constants.walletAccountColors.camel, colorId: Constants.walletAccountColors.camel,
color: "#C78F67",
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8884", address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8884",
walletType: Constants.keyWalletType, walletType: Constants.keyWalletType,
position: 4, position: 4,

View File

@ -156,6 +156,7 @@ StackLayout {
sourceComponent: CommunitySettingsView { sourceComponent: CommunitySettingsView {
id: communitySettingsView id: communitySettingsView
rootStore: root.rootStore rootStore: root.rootStore
walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule
community: sectionItemModel community: sectionItemModel
@ -182,7 +183,7 @@ StackLayout {
property string communityId property string communityId
loginType: root.rootStore.loginType loginType: root.rootStore.loginType
walletAccountsModel: WalletStore.RootStore.receiveAccounts walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
permissionsModel: root.permissionsStore.permissionsModel permissionsModel: root.permissionsStore.permissionsModel
assetsModel: root.rootStore.assetsModel assetsModel: root.rootStore.assetsModel
collectiblesModel: root.rootStore.collectiblesModel collectiblesModel: root.rootStore.collectiblesModel

View File

@ -566,27 +566,7 @@ StackView {
communityName: root.communityName communityName: root.communityName
networkName: view.token.chainName networkName: view.token.chainName
accountsModel: SortFilterProxyModel { accountsModel: root.accounts
sourceModel: root.accounts
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
function openPopup(type, userName) { function openPopup(type, userName) {
tokenMasterActionPopup.actionType = type tokenMasterActionPopup.actionType = type

View File

@ -85,7 +85,7 @@ StatusListView {
} }
} }
asset.color: !!model.colorId ? Utils.getColorForId(model.colorId): "" asset.color: !!model.color ? model.color : ""
asset.emoji: model.emoji asset.emoji: model.emoji
asset.name: !model.emoji ? "filled-account": "" asset.name: !model.emoji ? "filled-account": ""
asset.letterSize: 14 asset.letterSize: 14

View File

@ -95,31 +95,7 @@ Control {
Layout.preferredHeight: contentHeight + topMargin + bottomMargin Layout.preferredHeight: contentHeight + topMargin + bottomMargin
Layout.maximumHeight: hasPermissions ? permissionsView.implicitHeight > root.availableHeight / 2 ? root.availableHeight / 2 : root.availableHeight : -1 Layout.maximumHeight: hasPermissions ? permissionsView.implicitHeight > root.availableHeight / 2 ? root.availableHeight / 2 : root.availableHeight : -1
Layout.fillHeight: !hasPermissions Layout.fillHeight: !hasPermissions
model: SortFilterProxyModel { model: root.walletAccountsModel
sourceModel: root.walletAccountsModel
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
sorters: [
ExpressionSorter {
function isGenerated(modelData) {
return modelData.walletType === Constants.generatedWalletType
}
expression: {
return isGenerated(modelLeft)
}
},
RoleSorter {
roleName: "position"
},
RoleSorter {
roleName: "name"
}
]
}
} }
// divider with top rounded corners + drop shadow // divider with top rounded corners + drop shadow

View File

@ -158,27 +158,7 @@ StatusDialog {
accountErrorText: root.feeErrorText accountErrorText: root.feeErrorText
implicitWidth: 0 implicitWidth: 0
model: d.isFormValid ? singleFeeModel : undefined model: d.isFormValid ? singleFeeModel : undefined
accountsSelector.model: SortFilterProxyModel { accountsSelector.model: root.accounts
sourceModel: root.accounts
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
accountsSelector.onCurrentIndexChanged: { accountsSelector.onCurrentIndexChanged: {
if (accountsSelector.currentIndex < 0) if (accountsSelector.currentIndex < 0)

View File

@ -124,7 +124,7 @@ Item {
imageSrc: communityData.image imageSrc: communityData.image
accessType: communityData.access accessType: communityData.access
loginType: root.store.loginType loginType: root.store.loginType
walletAccountsModel: WalletStore.RootStore.receiveAccounts walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
permissionsModel: root.store.permissionsStore.permissionsModel permissionsModel: root.store.permissionsStore.permissionsModel
assetsModel: root.store.assetsModel assetsModel: root.store.assetsModel
collectiblesModel: root.store.collectiblesModel collectiblesModel: root.store.collectiblesModel

View File

@ -35,6 +35,8 @@ StatusSectionLayout {
property var transactionStore: TransactionStore {} property var transactionStore: TransactionStore {}
property bool communitySettingsDisabled property bool communitySettingsDisabled
required property var walletAccountsModel // name, address, emoji, color
readonly property bool isOwner: community.memberRole === Constants.memberRole.owner readonly property bool isOwner: community.memberRole === Constants.memberRole.owner
readonly property bool isAdmin: isOwner || community.memberRole === Constants.memberRole.admin readonly property bool isAdmin: isOwner || community.memberRole === Constants.memberRole.admin
readonly property bool isControlNode: community.isControlNode readonly property bool isControlNode: community.isControlNode
@ -350,7 +352,7 @@ StatusSectionLayout {
layer2Networks: communityTokensStore.layer2Networks layer2Networks: communityTokensStore.layer2Networks
enabledNetworks: communityTokensStore.enabledNetworks enabledNetworks: communityTokensStore.enabledNetworks
allNetworks: communityTokensStore.allNetworks allNetworks: communityTokensStore.allNetworks
accounts: root.rootStore.accounts accounts: root.walletAccountsModel
onDeployFeesRequested: { onDeployFeesRequested: {
feeText = "" feeText = ""
@ -506,27 +508,7 @@ StatusSectionLayout {
collectiblesModel: collectiblesModelLoader.item collectiblesModel: collectiblesModelLoader.item
membersModel: community.members membersModel: community.members
accountsModel: SortFilterProxyModel { accountsModel: root.walletAccountsModel
sourceModel: root.rootStore.accounts
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
onAirdropClicked: communityTokensStore.airdrop( onAirdropClicked: communityTokensStore.airdrop(
root.community.id, airdropTokens, addresses, root.community.id, airdropTokens, addresses,

View File

@ -158,27 +158,7 @@ StatusScrollView {
readonly property bool error: root.feeErrorText !== "" readonly property bool error: root.feeErrorText !== ""
} }
accountsSelector.model: SortFilterProxyModel { accountsSelector.model: root.accounts || null
sourceModel: root.accounts || null
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
Component.onCompleted: { Component.onCompleted: {
const initIndex = StatusQUtils.ModelUtils.indexOf( const initIndex = StatusQUtils.ModelUtils.indexOf(

View File

@ -357,27 +357,7 @@ StatusScrollView {
return true return true
} }
accountsSelector.model: SortFilterProxyModel { accountsSelector.model: root.accounts
sourceModel: root.accounts
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
readonly property TokenObject token: root.isAssetView ? root.asset readonly property TokenObject token: root.isAssetView ? root.asset
: root.collectible : root.collectible

View File

@ -168,27 +168,7 @@ StatusScrollView {
Layout.topMargin: -Style.current.halfPadding Layout.topMargin: -Style.current.halfPadding
currentIndex: (initIndex !== -1) ? initIndex : 0 currentIndex: (initIndex !== -1) ? initIndex : 0
model: SortFilterProxyModel { model: root.accounts
sourceModel: root.accounts
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
type: StatusComboBox.Type.Secondary type: StatusComboBox.Type.Secondary
size: StatusComboBox.Size.Small size: StatusComboBox.Size.Small
implicitHeight: 44 implicitHeight: 44

View File

@ -233,7 +233,7 @@ SettingsContentBase {
} }
loginType: chatStore.loginType loginType: chatStore.loginType
walletAccountsModel: WalletStore.RootStore.receiveAccounts walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
permissionsModel: chatStore.permissionsStore.permissionsModel permissionsModel: chatStore.permissionsStore.permissionsModel
assetsModel: chatStore.assetsModel assetsModel: chatStore.assetsModel
collectiblesModel: chatStore.collectiblesModel collectiblesModel: chatStore.collectiblesModel

View File

@ -44,6 +44,28 @@ QtObject {
] ]
} }
property var watchOnlyAccounts: SortFilterProxyModel {
sourceModel: receiveAccounts
proxyRoles: [
ExpressionRole {
name: "color"
function getColor(colorId) {
return Utils.getColorForId(colorId)
}
// Direct call for singleton function is not handled properly by
// SortFilterProxyModel that's why helper function is used instead.
expression: { return getColor(model.colorId) }
}
]
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
readonly property var currentActivityFiltersStore: { readonly property var currentActivityFiltersStore: {
const address = root.overview.mixedcaseAddress const address = root.overview.mixedcaseAddress
if (address in d.activityFiltersStoreDictionary) { if (address in d.activityFiltersStoreDictionary) {

View File

@ -41,7 +41,7 @@ QtObject {
property var permissionsModel: !!root.communitiesModuleInst.spectatedCommunityPermissionModel ? property var permissionsModel: !!root.communitiesModuleInst.spectatedCommunityPermissionModel ?
root.communitiesModuleInst.spectatedCommunityPermissionModel : null root.communitiesModuleInst.spectatedCommunityPermissionModel : null
property var walletAccountsModel: WalletStore.RootStore.receiveAccounts property var walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
property var assetsModel: SortFilterProxyModel { property var assetsModel: SortFilterProxyModel {
sourceModel: communitiesModuleInst.tokenList sourceModel: communitiesModuleInst.tokenList
proxyRoles: ExpressionRole { proxyRoles: ExpressionRole {

View File

@ -63,13 +63,6 @@ StatusStackModal {
readonly property var tempAddressesModel: SortFilterProxyModel { readonly property var tempAddressesModel: SortFilterProxyModel {
sourceModel: root.walletAccountsModel sourceModel: root.walletAccountsModel
filters: [
ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
]
sorters: [ sorters: [
ExpressionSorter { ExpressionSorter {
function isGenerated(modelData) { function isGenerated(modelData) {
@ -108,7 +101,26 @@ StatusStackModal {
communityName: root.name communityName: root.name
communityIcon: root.imageSrc communityIcon: root.imageSrc
loginType: root.loginType loginType: root.loginType
walletAccountsModel: root.walletAccountsModel walletAccountsModel: SortFilterProxyModel {
sourceModel: root.walletAccountsModel
sorters: [
ExpressionSorter {
function isGenerated(modelData) {
return modelData.walletType === Constants.generatedWalletType
}
expression: {
return isGenerated(modelLeft)
}
},
RoleSorter {
roleName: "position"
},
RoleSorter {
roleName: "name"
}
]
}
permissionsModel: root.permissionsModel permissionsModel: root.permissionsModel
assetsModel: root.assetsModel assetsModel: root.assetsModel
collectiblesModel: root.collectiblesModel collectiblesModel: root.collectiblesModel