chore(MintingToken): Refactor access to stores in minting components

- Refactored minting components store access, since some panels were accessing stores directly. Now `CommunitySettingsView` is the single place where stores are accessed.
- Renamed store `CommunitesStore` to `CommunityTokensStore` for handling minting / airdrop actions / request models.
- `NetworkFilter` refactored to prevent direct access to store inside the component.

Closes #9663
This commit is contained in:
Noelia 2023-03-08 14:44:47 +01:00 committed by Noelia
parent 5db989db6e
commit c7f18978de
12 changed files with 139 additions and 83 deletions

View File

@ -23,28 +23,16 @@ SplitView {
CommunityMintTokensSettingsPanel { CommunityMintTokensSettingsPanel {
anchors.fill: parent anchors.fill: parent
anchors.topMargin: 50 anchors.topMargin: 50
transactionStore: QtObject {
readonly property var currentAccount: QtObject {
readonly property string address: "0x0000001"
}
}
communitiesStore: QtObject {
readonly property TokenHoldersModel holdersModel: TokenHoldersModel {}
property var layer1Networks: NetworksModel.layer1Networks
property var layer2Networks: NetworksModel.layer2Networks
property var testNetworks: NetworksModel.testNetworks
property var enabledNetworks: NetworksModel.enabledNetworks
property var allNetworks: enabledNetworks
function mintCollectible(communityId, address, artworkSource, name, symbol, description, supply,
infiniteSupply, transferable, selfDestruct, chainId)
{
logs.logEvent("CommunityMintTokensSettingsPanel::mintCollectible")
}
}
tokensModel: ListModel {} tokensModel: ListModel {}
} holdersModel: TokenHoldersModel {}
layer1Networks: NetworksModel.layer1Networks
layer2Networks: NetworksModel.layer2Networks
testNetworks: NetworksModel.testNetworks
enabledNetworks: NetworksModel.enabledNetworks
allNetworks: enabledNetworks
onMintCollectible: ogs.logEvent("CommunityMintTokensSettingsPanel::mintCollectible")
}
} }
LogsAndControlsPanel { LogsAndControlsPanel {

View File

@ -27,13 +27,11 @@ SplitView {
CommunityNewCollectibleView { CommunityNewCollectibleView {
anchors.fill: parent anchors.fill: parent
anchors.margins: 50 anchors.margins: 50
store: QtObject { layer1Networks: NetworksModel.layer1Networks
property var layer1Networks: NetworksModel.layer1Networks layer2Networks: NetworksModel.layer2Networks
property var layer2Networks: NetworksModel.layer2Networks testNetworks: NetworksModel.testNetworks
property var testNetworks: NetworksModel.testNetworks enabledNetworks: NetworksModel.enabledNetworks
property var enabledNetworks: NetworksModel.enabledNetworks allNetworks: enabledNetworks
property var allNetworks: enabledNetworks
}
onPreviewClicked: logs.logEvent("CommunityNewCollectibleView::previewClicked") onPreviewClicked: logs.logEvent("CommunityNewCollectibleView::previewClicked")
} }

View File

@ -112,7 +112,6 @@ StackLayout {
sourceComponent: CommunitySettingsView { sourceComponent: CommunitySettingsView {
rootStore: root.rootStore rootStore: root.rootStore
communityStore: CommunitiesStore {}
hasAddedContacts: root.contactsStore.myContactsModel.count > 0 hasAddedContacts: root.contactsStore.myContactsModel.count > 0
chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule

View File

@ -13,12 +13,36 @@ import utils 1.0
SettingsPageLayout { SettingsPageLayout {
id: root id: root
property string communityId // Models:
property var tokensModel property var tokensModel
property var communitiesStore property var holdersModel
property var transactionStore
// Network related properties:
property var layer1Networks
property var layer2Networks
property var testNetworks
property var enabledNetworks
property var allNetworks
// Other properties:
property alias chainName: collectibleItem.chainName
property alias chainIcon: collectibleItem.chainIcon
property int viewWidth: 560 // by design property int viewWidth: 560 // by design
signal mintCollectible(url artworkSource,
string name,
string symbol,
string description,
int supply,
bool infiniteSupply,
bool transferable,
bool selfDestruct,
int chainId)
signal requestChainName(int chainId)
signal requestChainIcon(int chainId)
function navigateBack() { function navigateBack() {
if (root.state === d.newCollectibleViewState) { if (root.state === d.newCollectibleViewState) {
root.state = d.initialState root.state = d.initialState
@ -86,12 +110,12 @@ SettingsPageLayout {
supplyText = model.supply.toString() supplyText = model.supply.toString()
infiniteSupply = model.infiniteSupply infiniteSupply = model.infiniteSupply
transferable = model.transferable transferable = model.transferable
chainName = communitiesStore.getChainName(model.chainId)
chainIcon = communitiesStore.getChainIcon(model.chainId)
artworkSource = model.image artworkSource = model.image
symbol = model.symbol symbol = model.symbol
selfDestruct = model.remoteSelfDestruct selfDestruct = model.remoteSelfDestruct
chainId = model.chainId chainId = model.chainId
requestChainName(model.chainId)
requestChainIcon(model.chainId)
} }
} }
@ -174,7 +198,11 @@ SettingsPageLayout {
CommunityNewCollectibleView { CommunityNewCollectibleView {
anchors.fill: parent anchors.fill: parent
store: root.communitiesStore layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
enabledNetworks: root.testNetworks
allNetworks: root.allNetworks
name: collectibleItem.collectibleName name: collectibleItem.collectibleName
artworkSource: collectibleItem.artworkSource artworkSource: collectibleItem.artworkSource
symbol: collectibleItem.symbol symbol: collectibleItem.symbol
@ -208,7 +236,7 @@ SettingsPageLayout {
CommunityCollectibleView { CommunityCollectibleView {
anchors.fill: parent anchors.fill: parent
preview: d.preview preview: d.preview
holdersModel: root.communitiesStore.holdersModel holdersModel: root.holdersModel
deployState: collectibleItem.deployState deployState: collectibleItem.deployState
name: collectibleItem.collectibleName name: collectibleItem.collectibleName
artworkSource: collectibleItem.artworkSource artworkSource: collectibleItem.artworkSource
@ -222,18 +250,16 @@ SettingsPageLayout {
chainName: collectibleItem.chainName chainName: collectibleItem.chainName
chainIcon: collectibleItem.chainIcon chainIcon: collectibleItem.chainIcon
onDeployCollectible: { onMintCollectible: {
root.communitiesStore.deployCollectible(root.communityId, root.mintCollectible(artworkSource,
root.transactionStore.currentAccount.address, /*TODO use address from SendModal*/ name,
name, symbol,
symbol, description,
description, supply,
supply, infiniteSupply,
infiniteSupply, transferable,
transferable, selfDestruct,
selfDestruct, chainId)
chainId,
artworkSource)
root.state = d.mintedCollectibleViewState root.state = d.mintedCollectibleViewState
} }

View File

@ -15,6 +15,8 @@ QtObject {
chatCommunitySectionModuleInst: chatCommunitySectionModule chatCommunitySectionModuleInst: chatCommunitySectionModule
} }
readonly property CommunityTokensStore communityTokensStore: CommunityTokensStore {}
property bool openCreateChat: false property bool openCreateChat: false
property string createChatInitMessage: "" property string createChatInitMessage: ""
property var createChatFileUrls: [] property var createChatFileUrls: []

View File

@ -1,4 +1,5 @@
CommunitiesStore 1.0 CommunitiesStore.qml CommunitiesStore 1.0 CommunitiesStore.qml
CommunityTokensStore 1.0 CommunityTokensStore.qml
PermissionsStore 1.0 PermissionsStore.qml PermissionsStore 1.0 PermissionsStore.qml
RootStore 1.0 RootStore.qml RootStore 1.0 RootStore.qml
StickerData 1.0 StickerData.qml StickerData 1.0 StickerData.qml

View File

@ -34,19 +34,16 @@ StatusSectionLayout {
onNotificationButtonClicked: Global.openActivityCenterPopup() onNotificationButtonClicked: Global.openActivityCenterPopup()
// TODO: get this model from backend? // TODO: get this model from backend?
property var settingsMenuModel: [{name: qsTr("Overview"), icon: "show", enabled: true}, property var settingsMenuModel: [{name: qsTr("Overview"), icon: "show", enabled: true},
{name: qsTr("Members"), icon: "group-chat", enabled: true}, {name: qsTr("Members"), icon: "group-chat", enabled: true},
{name: qsTr("Permissions"), icon: "objects", enabled: root.rootStore.communityPermissionsEnabled}, {name: qsTr("Permissions"), icon: "objects", enabled: root.rootStore.communityPermissionsEnabled},
{name: qsTr("Mint Tokens"), icon: "token", enabled: root.rootStore.communityTokensEnabled}] {name: qsTr("Mint Tokens"), icon: "token", enabled: root.rootStore.communityTokensEnabled}]
// TODO: Next community settings options: // TODO: Next community settings options:
// {name: qsTr("Airdrops"), icon: "airdrop"}, // {name: qsTr("Airdrops"), icon: "airdrop"},
// {name: qsTr("Token sales"), icon: "token-sale"}, // {name: qsTr("Token sales"), icon: "token-sale"},
// {name: qsTr("Subscriptions"), icon: "subscription"}, // {name: qsTr("Subscriptions"), icon: "subscription"},
property var rootStore property var rootStore
property var community property var community
property var chatCommunitySectionModule property var chatCommunitySectionModule
required property CommunitiesStore communityStore
property bool hasAddedContacts: false property bool hasAddedContacts: false
property var transactionStore: TransactionStore {} property var transactionStore: TransactionStore {}
@ -198,18 +195,18 @@ StatusSectionLayout {
onEdited: { onEdited: {
const error = root.chatCommunitySectionModule.editCommunity( const error = root.chatCommunitySectionModule.editCommunity(
StatusQUtils.Utils.filterXSS(item.name), StatusQUtils.Utils.filterXSS(item.name),
StatusQUtils.Utils.filterXSS(item.description), StatusQUtils.Utils.filterXSS(item.description),
StatusQUtils.Utils.filterXSS(item.introMessage), StatusQUtils.Utils.filterXSS(item.introMessage),
StatusQUtils.Utils.filterXSS(item.outroMessage), StatusQUtils.Utils.filterXSS(item.outroMessage),
item.options.requestToJoinEnabled ? Constants.communityChatOnRequestAccess : Constants.communityChatPublicAccess, item.options.requestToJoinEnabled ? Constants.communityChatOnRequestAccess : Constants.communityChatPublicAccess,
item.color.toString().toUpperCase(), item.color.toString().toUpperCase(),
item.selectedTags, item.selectedTags,
Utils.getImageAndCropInfoJson(item.logoImagePath, item.logoCropRect), Utils.getImageAndCropInfoJson(item.logoImagePath, item.logoCropRect),
Utils.getImageAndCropInfoJson(item.bannerPath, item.bannerCropRect), Utils.getImageAndCropInfoJson(item.bannerPath, item.bannerCropRect),
item.options.archiveSupportEnabled, item.options.archiveSupportEnabled,
item.options.pinMessagesEnabled item.options.pinMessagesEnabled
) )
if (error) { if (error) {
errorDialog.text = error.error errorDialog.text = error.error
errorDialog.open() errorDialog.open()
@ -225,8 +222,8 @@ StatusSectionLayout {
onAirdropTokensClicked: { /* TODO in future */ } onAirdropTokensClicked: { /* TODO in future */ }
onBackUpClicked: { onBackUpClicked: {
Global.openPopup(transferOwnershipPopup, { Global.openPopup(transferOwnershipPopup, {
privateKey: root.chatCommunitySectionModule.exportCommunity(root.communityId), privateKey: root.chatCommunitySectionModule.exportCommunity(root.communityId),
}) })
} }
onPreviousPageNameChanged: root.backButtonName = previousPageName onPreviousPageNameChanged: root.backButtonName = previousPageName
} }
@ -286,11 +283,35 @@ StatusSectionLayout {
} }
CommunityMintTokensSettingsPanel { CommunityMintTokensSettingsPanel {
communityId: root.community.id readonly property CommunityTokensStore communityTokensStore:
communitiesStore: root.communityStore rootStore.communityTokensStore
transactionStore: root.transactionStore
tokensModel: root.community.communityTokens tokensModel: root.community.communityTokens
holdersModel: communityTokensStore.holdersModel
layer1Networks: communityTokensStore.layer1Networks
layer2Networks: communityTokensStore.layer2Networks
testNetworks: communityTokensStore.testNetworks
enabledNetworks: communityTokensStore.enabledNetworks
allNetworks: communityTokensStore.allNetworks
onPreviousPageNameChanged: root.backButtonName = previousPageName onPreviousPageNameChanged: root.backButtonName = previousPageName
onRequestChainName: chainName = communityTokensStore.getChainName(chainId)
onRequestChainIcon: chainIcon = communityTokensStore.getChainIcon(chainId)
onMintCollectible: {
communityTokensStore.deployCollectible(root.community.id,
root.transactionStore.currentAccount.address, /*TODO use address from SendModal*/
name,
symbol,
description,
supply,
infiniteSupply,
transferable,
selfDestruct,
chainId,
artworkSource)
root.state = d.mintedCollectibleViewState
}
} }
onCurrentIndexChanged: root.backButtonName = centerPanelContentLoader.item.children[d.currentIndex].previousPageName onCurrentIndexChanged: root.backButtonName = centerPanelContentLoader.item.children[d.currentIndex].previousPageName

View File

@ -32,7 +32,7 @@ StatusScrollView {
property string chainIcon property string chainIcon
property int deployState property int deployState
signal deployCollectible(url artworkSource, signal mintCollectible(url artworkSource,
string name, string name,
string symbol, string symbol,
string description, string description,
@ -231,7 +231,7 @@ StatusScrollView {
text: qsTr("Mint") text: qsTr("Mint")
onClicked: { onClicked: {
root.deployCollectible(root.artworkSource, root.mintCollectible(root.artworkSource,
root.name, root.name,
root.symbol, root.symbol,
root.description, root.description,

View File

@ -14,7 +14,6 @@ import shared.panels 1.0
StatusScrollView { StatusScrollView {
id: root id: root
property var store
property int viewWidth: 560 // by design property int viewWidth: 560 // by design
// Collectible properties // Collectible properties
@ -30,6 +29,13 @@ StatusScrollView {
property string chainName property string chainName
property string chainIcon property string chainIcon
// Network related properties:
property var layer1Networks
property var layer2Networks
property var testNetworks
property var enabledNetworks
property var allNetworks
signal chooseArtWork signal chooseArtWork
signal previewClicked signal previewClicked
@ -159,7 +165,11 @@ StatusScrollView {
NetworkFilter { NetworkFilter {
visible: !rowComponent.isSwitchCase visible: !rowComponent.isSwitchCase
Layout.preferredWidth: 160 Layout.preferredWidth: 160
store: root.store layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
enabledNetworks: root.testNetworks
allNetworks: root.allNetworks
isChainVisible: false isChainVisible: false
multiSelection: false multiSelection: false

View File

@ -16,10 +16,15 @@ Item {
implicitWidth: 130 implicitWidth: 130
implicitHeight: parent.height implicitHeight: parent.height
property var store property var layer1Networks
property var layer2Networks
property var testNetworks
property var enabledNetworks
property var allNetworks
property bool isChainVisible: true property bool isChainVisible: true
property bool multiSelection: true property bool multiSelection: true
signal toggleNetwork(int chainId)
signal singleNetworkSelected(int chainId, string chainName, string chainIcon) signal singleNetworkSelected(int chainId, string chainName, string chainIcon)
QtObject { QtObject {
@ -47,7 +52,7 @@ Item {
statusListItemTitle.font.pixelSize: 13 statusListItemTitle.font.pixelSize: 13
statusListItemTitle.font.weight: Font.Medium statusListItemTitle.font.weight: Font.Medium
statusListItemTitle.color: Theme.palette.baseColor1 statusListItemTitle.color: Theme.palette.baseColor1
title: root.multiSelection ? (store.enabledNetworks.count === store.allNetworks.count ? qsTr("All networks") : qsTr("%n network(s)", "", store.enabledNetworks.count)) : title: root.multiSelection ? (root.enabledNetworks.count === root.allNetworks.count ? qsTr("All networks") : qsTr("%n network(s)", "", root.enabledNetworks.count)) :
d.selectedChainName d.selectedChainName
asset.height: 24 asset.height: 24
asset.width: asset.height asset.width: asset.height
@ -80,7 +85,7 @@ Item {
Repeater { Repeater {
id: chainRepeater id: chainRepeater
model: store.enabledNetworks model: root.enabledNetworks
delegate: InformationTag { delegate: InformationTag {
tagPrimaryLabel.text: model.shortName tagPrimaryLabel.text: model.shortName
tagPrimaryLabel.color: model.chainColor tagPrimaryLabel.color: model.chainColor
@ -93,13 +98,13 @@ Item {
id: selectPopup id: selectPopup
x: (parent.width - width + 5) x: (parent.width - width + 5)
y: (selectRectangleItem.height + 5) y: (selectRectangleItem.height + 5)
layer1Networks: store.layer1Networks layer1Networks: root.layer1Networks
layer2Networks: store.layer2Networks layer2Networks: root.layer2Networks
testNetworks: store.testNetworks testNetworks: root.testNetworks
multiSelection: root.multiSelection multiSelection: root.multiSelection
onToggleNetwork: { onToggleNetwork: {
store.toggleNetwork(network.chainId) root.toggleNetwork(network.chainId)
} }
onSingleNetworkSelected: { onSingleNetworkSelected: {

View File

@ -55,7 +55,13 @@ Item {
id: networkFilter id: networkFilter
Layout.alignment: Qt.AlignTrailing Layout.alignment: Qt.AlignTrailing
Layout.rowSpan: 2 Layout.rowSpan: 2
store: root.walletStore layer1Networks: walletStore.layer1Networks
layer2Networks: walletStore.layer2Networks
testNetworks: walletStore.testNetworks
enabledNetworks: walletStore.enabledNetworks
allNetworks: walletStore.allNetworks
onToggleNetwork: walletStore.toggleNetwork(chainId)
} }
StatusAddressPanel { StatusAddressPanel {