From 11f1e1541b168e9026410f42e38dc16e1c4acfa2 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 4 Oct 2024 09:46:53 +0200 Subject: [PATCH] fix: optimizes send modal flow for buying stickers --- ui/app/AppLayouts/Chat/ChatLayout.qml | 2 +- ui/app/AppLayouts/Chat/stores/RootStore.qml | 2 + ui/app/AppLayouts/Chat/views/ChatView.qml | 4 +- ui/app/mainui/AppMain.qml | 2 +- .../shared/status/StatusStickerMarket.qml | 69 +++++++------------ .../status/StatusStickerPackClickPopup.qml | 55 ++++----------- .../shared/status/StatusStickersPopup.qml | 4 +- 7 files changed, 46 insertions(+), 92 deletions(-) diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index 27378dcf9e..d807cc73d3 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -151,11 +151,11 @@ StackLayout { contactsStore: root.contactsStore sharedRootStore: root.sharedRootStore rootStore: root.rootStore - transactionStore: root.transactionStore createChatPropertiesStore: root.createChatPropertiesStore communitiesStore: root.communitiesStore walletAssetsStore: root.walletAssetsStore currencyStore: root.currencyStore + sendModalPopup: root.sendModalPopup sectionItemModel: root.sectionItemModel amIMember: sectionItem.amIMember amISectionAdmin: root.sectionItemModel.memberRole === Constants.memberRole.owner || diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 104c1c0e90..ddfcf37b7c 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -283,6 +283,8 @@ QtObject { property var mainModuleInst: mainModule + readonly property string appNetworkId: mainModuleInst.appNetworkId + property var communitiesModuleInst: communitiesModule property var communitiesList: communitiesModuleInst.model diff --git a/ui/app/AppLayouts/Chat/views/ChatView.qml b/ui/app/AppLayouts/Chat/views/ChatView.qml index 0865bd1dd1..a27b6a96ff 100644 --- a/ui/app/AppLayouts/Chat/views/ChatView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatView.qml @@ -44,11 +44,11 @@ StatusSectionLayout { property SharedStores.RootStore sharedRootStore property ChatStores.RootStore rootStore - required property SendStores.TransactionStore transactionStore property ChatStores.CreateChatPropertiesStore createChatPropertiesStore property CommunitiesStores.CommunitiesStore communitiesStore required property WalletStore.WalletAssetsStore walletAssetsStore required property SharedStores.CurrenciesStore currencyStore + required property var sendModalPopup property var sectionItemModel property var emojiPopup @@ -307,8 +307,8 @@ StatusSectionLayout { Component { id: statusStickerPackClickPopup StatusStickerPackClickPopup{ - transactionStore: root.transactionStore walletAssetsStore: root.walletAssetsStore + sendModalPopup: root.sendModalPopup onClosed: { destroy(); } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 15806ecfe1..f05ac687ff 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -651,8 +651,8 @@ Item { active: appMain.rootStore.mainModuleInst.sectionsLoaded sourceComponent: StatusStickersPopup { store: appMain.rootChatStore - transactionStore: appMain.transactionStore walletAssetsStore: appMain.walletAssetsStore + sendModalPopup: sendModal isWalletEnabled: appMain.rootStore.profileSectionStore.profileStore.isWalletEnabled } diff --git a/ui/imports/shared/status/StatusStickerMarket.qml b/ui/imports/shared/status/StatusStickerMarket.qml index 372e531ace..59c942e4c9 100644 --- a/ui/imports/shared/status/StatusStickerMarket.qml +++ b/ui/imports/shared/status/StatusStickerMarket.qml @@ -25,8 +25,8 @@ Item { property ChatStores.RootStore store property var stickerPacks: ChatStores.StickerPackData {} - required property TransactionStore transactionStore required property WalletAssetsStore walletAssetsStore + required property var sendModalPopup property string packId property bool marketVisible property bool isWalletEnabled @@ -38,6 +38,26 @@ Item { signal updateClicked(string packId) signal buyClicked(string packId) + QtObject { + id: d + + function runSendModal(price, packId) { + + const token = ModelUtils.getByKey(root.walletAssetsStore.groupedAccountAssetsModel, "tokensKey", root.store.stickersStore.getStatusTokenKey()) + + root.sendModalPopup.interactive = false + root.sendModalPopup.preSelectedRecipient = root.store.stickersStore.getStickersMarketAddress() + root.sendModalPopup.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Address + root.sendModalPopup.preSelectedHoldingID = !!token && !!token.symbol ? token.symbol : "" + root.sendModalPopup.preSelectedHoldingType = Constants.TokenType.ERC20 + root.sendModalPopup.preSelectedSendType = Constants.SendType.StickersBuy + root.sendModalPopup.preDefinedAmountToSend = LocaleUtils.numberToLocaleString(parseFloat(price)) + root.sendModalPopup.preSelectedChainId = root.store.appNetworkId + root.sendModalPopup.stickersPackId = packId + root.sendModalPopup.open() + } + } + StatusGridView { id: availableStickerPacks objectName: "stickerMarketStatusGridView" @@ -154,7 +174,7 @@ Item { onCancelClicked: root.cancelClicked(packId) onUpdateClicked: root.updateClicked(packId) onBuyClicked: { - Global.openPopup(stickerPackPurchaseModal, {price, packId}) + d.runSendModal(price, packId) root.buyClicked(packId) } } @@ -187,7 +207,7 @@ Item { onCancelClicked: root.cancelClicked(packId) onUpdateClicked: root.updateClicked(packId) onBuyClicked: { - Global.openPopup(stickerPackPurchaseModal, {price, packId}) + d.runSendModal(price, packId) root.buyClicked(packId) } } @@ -196,49 +216,6 @@ Item { } } - Component { - id: stickerPackPurchaseModal - SendModal { - id: buyStickersModal - - required property int price - required property string packId - - interactive: false - store: root.transactionStore - preSelectedSendType: Constants.SendType.StickersBuy - preSelectedRecipient: root.store.stickersStore.getStickersMarketAddress() - preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price)) - stickersPackId: packId - preSelectedHoldingID: { - let token = ModelUtils.getByKey(root.walletAssetsStore.groupedAccountAssetsModel, "tokensKey", root.store.stickersStore.getStatusTokenKey()) - return !!token && !!token.symbol ? token.symbol : "" - } - preSelectedHoldingType: Constants.TokenType.ERC20 - - Connections { - target: root.store.stickersStore.stickersModule - function onTransactionWasSent(chainId: int, txHash: string, error: string) { - if (!!error) { - if (error.includes(Constants.walletSection.cancelledMessage)) { - return - } - buyStickersModal.sendingError.text = error - return buyStickersModal.sendingError.open() - } - let url = "%1/%2".arg(buyStickersModal.store.getEtherscanLink(chainId)).arg(txHash) - Global.displayToastMessage(qsTr("Transaction pending..."), - qsTr("View on etherscan"), - "", - true, - Constants.ephemeralNotificationType.normal, - url) - buyStickersModal.close() - } - } - } - } - Item { id: footer height: 44 diff --git a/ui/imports/shared/status/StatusStickerPackClickPopup.qml b/ui/imports/shared/status/StatusStickerPackClickPopup.qml index f693574126..3166f1ed31 100644 --- a/ui/imports/shared/status/StatusStickerPackClickPopup.qml +++ b/ui/imports/shared/status/StatusStickerPackClickPopup.qml @@ -25,8 +25,8 @@ ModalPopup { property string packId property ChatStores.RootStore store - required property TransactionStore transactionStore required property WalletAssetsStore walletAssetsStore + required property var sendModalPopup property string thumbnail: "" property string name: "" property string author: "" @@ -72,43 +72,6 @@ ModalPopup { anchors.fill: parent anchors.topMargin: Style.current.padding packId: stickerPackDetailsPopup.packId - Component { - id: stickerPackPurchaseModal - SendModal { - id: buyStickersPackModal - interactive: false - store: stickerPackDetailsPopup.transactionStore - preSelectedSendType: Constants.SendType.StickersBuy - preSelectedRecipient: stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress() - preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price)) - preSelectedHoldingID: { - let token = SQUtils.ModelUtils.getByKey(stickerPackDetailsPopup.walletAssetsStore.groupedAccountAssetsModel, "tokensKey", stickerPackDetailsPopup.store.stickersStore.getStatusTokenKey()) - return !!token && !!token.symbol ? token.symbol : "" - } - preSelectedHoldingType: Constants.TokenType.ERC20 - - Connections { - target: stickerPackDetailsPopup.store.stickersStore.stickersModule - function onTransactionWasSent(chainId: int, txHash: string, error: string) { - if (!!error) { - if (error.includes(Constants.walletSection.cancelledMessage)) { - return - } - buyStickersPackModal.sendingError.text = error - return buyStickersPackModal.sendingError.open() - } - let url = "%1/%2".arg(buyStickersPackModal.store.getEtherscanLink(chainId)).arg(txHash) - Global.displayToastMessage(qsTr("Transaction pending..."), - qsTr("View on etherscan"), - "", - true, - Constants.ephemeralNotificationType.normal, - url) - buyStickersPackModal.close() - } - } - } - } } footer: StatusStickerButton { @@ -131,8 +94,20 @@ ModalPopup { onCancelClicked: function(){} onUpdateClicked: function(){} onBuyClicked: { - Global.openPopup(stickerPackPurchaseModal) - stickerPackDetailsPopup.buyClicked(packId) + const token = SQUtils.ModelUtils.getByKey(stickerPackDetailsPopup.walletAssetsStore.groupedAccountAssetsModel, "tokensKey", stickerPackDetailsPopup.store.stickersStore.getStatusTokenKey()) + + stickerPackDetailsPopup.sendModalPopup.interactive = false + stickerPackDetailsPopup.sendModalPopup.preSelectedRecipient = stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress() + stickerPackDetailsPopup.sendModalPopup.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Address + stickerPackDetailsPopup.sendModalPopup.preSelectedHoldingID = !!token && !!token.symbol ? token.symbol : "" + stickerPackDetailsPopup.sendModalPopup.preSelectedHoldingType = Constants.TokenType.ERC20 + stickerPackDetailsPopup.sendModalPopup.preSelectedSendType = Constants.SendType.StickersBuy + stickerPackDetailsPopup.sendModalPopup.preDefinedAmountToSend = LocaleUtils.numberToLocaleString(parseFloat(stickerPackDetailsPopup.price)) + stickerPackDetailsPopup.sendModalPopup.preSelectedChainId = stickerPackDetailsPopup.store.appNetworkId + stickerPackDetailsPopup.sendModalPopup.stickersPackId = stickerPackDetailsPopup.packId + stickerPackDetailsPopup.sendModalPopup.open() + + stickerPackDetailsPopup.buyClicked(stickerPackDetailsPopup.packId) } } } diff --git a/ui/imports/shared/status/StatusStickersPopup.qml b/ui/imports/shared/status/StatusStickersPopup.qml index 9fbcf70257..50b8ad0396 100644 --- a/ui/imports/shared/status/StatusStickersPopup.qml +++ b/ui/imports/shared/status/StatusStickersPopup.qml @@ -19,8 +19,8 @@ Popup { id: root property ChatStores.RootStore store - required property TransactionStore transactionStore required property WalletAssetsStore walletAssetsStore + required property var sendModalPopup property alias isWalletEnabled: stickerMarket.isWalletEnabled @@ -102,8 +102,8 @@ Popup { Layout.fillWidth: true Layout.fillHeight: true store: root.store - transactionStore: root.transactionStore walletAssetsStore: root.walletAssetsStore + sendModalPopup: root.sendModalPopup stickerPacks: d.stickerPackList packId: stickerPackListView.selectedPackId marketVisible: d.stickerPacksLoaded && d.online