From 1d00614e0a23e5ce2d13c0b4121c424a7e6873a2 Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Mon, 11 Nov 2024 14:10:27 +0100 Subject: [PATCH] wip: Request payment modal 2 --- storybook/pages/RequestPaymentModalPage.qml | 31 +------- .../shared/stores/RequestPaymentStore.qml | 1 + .../Chat/popups/RequestPaymentModal.qml | 79 +++++-------------- .../shared/stores/RequestPaymentStore.qml | 1 + 4 files changed, 26 insertions(+), 86 deletions(-) diff --git a/storybook/pages/RequestPaymentModalPage.qml b/storybook/pages/RequestPaymentModalPage.qml index dc3935f3b9..2fbdbb88da 100644 --- a/storybook/pages/RequestPaymentModalPage.qml +++ b/storybook/pages/RequestPaymentModalPage.qml @@ -29,31 +29,6 @@ SplitView { orientation: Qt.Horizontal - ListModel { - id: plainTokensModel - ListElement { - key: "aave" - name: "Aave" - symbol: "AAVE" - image: "https://cryptologos.cc/logos/aave-aave-logo.png" - communityId: "" - } - ListElement { - key: "usdc" - name: "USDC" - symbol: "USDC" - image: "" - communityId: "" - } - ListElement { - key: "hst" - name: "Decision Token" - symbol: "HST" - image: "https://etherscan.io/token/images/horizonstate2_28.png" - communityId: "" - } - } - QtObject { id: d readonly property var tokenBySymbolModel: TokensBySymbolModel {} @@ -70,7 +45,6 @@ SplitView { walletTokensStore: WalletStores.TokensStore { plainTokensBySymbolModel: TokensBySymbolModel {} } - readonly property var baseGroupedAccountAssetModel: GroupedAccountsAssetsModel {} assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel } @@ -80,7 +54,8 @@ SplitView { readonly property SharedStores.RequestPaymentStore requestPaymentStore: SharedStores.RequestPaymentStore { currencyStore: d.currencyStore flatNetworksModel: d.flatNetworks - processedAssetsModel: d.walletAssetsStore.renamedTokensBySymbolModel + processedAssetsModel: d.walletAssetsStore.jointModel + plainAssetsModel: d.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel accountsModel: d.accounts } } @@ -100,7 +75,7 @@ SplitView { onClicked: d.launchPopup() } - Component.onCompleted: d.launchPopup() + Component.onCompleted: Qt.callLater(d.launchPopup) Component { id: requestPaymentModalComponent diff --git a/storybook/stubs/shared/stores/RequestPaymentStore.qml b/storybook/stubs/shared/stores/RequestPaymentStore.qml index 0b9c09840c..bef8b1ebc1 100644 --- a/storybook/stubs/shared/stores/RequestPaymentStore.qml +++ b/storybook/stubs/shared/stores/RequestPaymentStore.qml @@ -4,6 +4,7 @@ QtObject { required property CurrenciesStore currencyStore required property var flatNetworksModel required property var processedAssetsModel + required property var plainAssetsModel required property var accountsModel property var requestPaymentModel: ListModel {} diff --git a/ui/app/AppLayouts/Chat/popups/RequestPaymentModal.qml b/ui/app/AppLayouts/Chat/popups/RequestPaymentModal.qml index b6ed7a67d1..38739bf18b 100644 --- a/ui/app/AppLayouts/Chat/popups/RequestPaymentModal.qml +++ b/ui/app/AppLayouts/Chat/popups/RequestPaymentModal.qml @@ -1,14 +1,11 @@ import QtQuick 2.15 -import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 import QtQml.Models 2.15 -import QtGraphicalEffects 1.15 import StatusQ 0.1 import StatusQ.Controls 0.1 import StatusQ.Core 0.1 import StatusQ.Core.Theme 0.1 -import StatusQ.Core.Utils 0.1 as SQUtils import StatusQ.Components.private 0.1 as SQP import StatusQ.Components 0.1 import StatusQ.Popups.Dialog 0.1 @@ -29,10 +26,9 @@ StatusDialog { property int selectedNetworkChainId: Constants.chains.mainnetChainId property string selectedAccountAddress property string selectedTokenKey: Constants.ethToken - onSelectedTokenKeyChanged: Qt.callLater(d.reevaluateSelectedId) readonly property string amount: { - if (!d.isSelectedHoldingValidAsset || !d.selectedHolding.marketDetails || !d.selectedHolding.marketDetails.currencyPrice) { + if (!d.isSelectedHoldingValidAsset || !d.selectedHolding.item.marketDetails || !d.selectedHolding.item.marketDetails.currencyPrice) { return "0" } return amountToSendInput.text @@ -49,33 +45,32 @@ StatusDialog { title: qsTr("Payment request") + onOpened: { + // Setting value here because to prevent not updating when selected token key is filled + d.selectedHolding.value = Qt.binding(function() { return root.selectedTokenKey }) + + if (!!root.selectedTokenKey) { + holdingSelector.setSelection(d.selectedHolding.item.symbol, d.selectedHolding.item.iconSource, d.selectedHolding.item.tokensKey) + } + } + QtObject { id: d - // FIXME use ModelEntry - property var selectedHolding: SQUtils.ModelUtils.getByKey(holdingSelector.model, "tokensKey", root.selectedTokenKey) - readonly property bool isSelectedHoldingValidAsset: !!selectedHolding + readonly property ModelEntry selectedHolding: ModelEntry { + sourceModel: holdingSelector.model + key: "tokensKey" + } + + readonly property bool isSelectedHoldingValidAsset: !!selectedHolding.item readonly property var adaptor: TokenSelectorViewAdaptor { assetsModel: root.store.processedAssetsModel flatNetworksModel: root.flatNetworksModel currentCurrency: root.store.currencyStore.currentCurrency + plainTokensBySymbolModel: root.store.plainAssetsModel showAllTokens: true } - - // FIXME drop after using ModelEntry, shouldn't be needed - function reevaluateSelectedId() { - const entry = SQUtils.ModelUtils.getByKey(holdingSelector.model, "tokensKey", root.selectedTokenKey) - - if (entry) { - holdingSelector.setSelection(entry.symbol, entry.iconSource, entry.tokensKey) - } else { - root.selectedTokenKey = "" - holdingSelector.reset() - } - - d.selectedHolding = entry - } } footer: StatusDialogFooter { @@ -90,10 +85,7 @@ StatusDialog { disabledColor: Theme.palette.directColor8 enabled: amountToSendInput.valid && !amountToSendInput.empty && amountToSendInput.asNumber > 0 interactive: true - onClicked: { - // TODO_ES handle - root.accept() - } + onClicked: root.accept() } } } @@ -113,51 +105,22 @@ StatusDialog { Layout.fillWidth: true readonly property bool ready: valid && !empty - - readonly property string selectedSymbol: root.selectedTokenKey - - // For backward compatibility. To be removed when - // dependent components (NetworkSelector, AmountToReceive) - // are refactored. readonly property double asNumber: { if (!valid) return 0 return parseFloat(text.replace(LocaleUtils.userInputLocale.decimalPoint, ".")) } - readonly property int minSendCryptoDecimals: - !fiatMode ? LocaleUtils.fractionalPartLength(asNumber) : 0 - readonly property int minReceiveCryptoDecimals: - !fiatMode ? minSendCryptoDecimals + 1 : 0 - readonly property int minSendFiatDecimals: - fiatMode ? LocaleUtils.fractionalPartLength(asNumber) : 0 - readonly property int minReceiveFiatDecimals: - fiatMode ? minSendFiatDecimals + 1 : 0 - // End of to-be-removed part - multiplierIndex: 9 - // !!holdingSelector.selectedItem - // && !!holdingSelector.selectedItem.decimals - // ? holdingSelector.selectedItem.decimals : 0 - - // price: d.isSelectedHoldingValidAsset - // ? (d.selectedHolding ? - // d.selectedHolding.marketDetails.currencyPrice.amount : 1) - // : 1 - price: 1 + multiplierIndex: d.isSelectedHoldingValidAsset && !!d.selectedHolding.item.decimals ? d.selectedHolding.item.decimals : 0 + price: d.isSelectedHoldingValidAsset && !!d.selectedHolding.item.marketDetails ? d.selectedHolding.item.marketDetails.currencyPrice.amount : 1 formatFiat: amount => root.store.currencyStore.formatCurrencyAmount( amount, root.store.currencyStore.currentCurrency) formatBalance: amount => root.store.currencyStore.formatCurrencyAmount( - amount, selectedSymbol) + amount, root.selectedTokenKey) showSeparator: true - onValidChanged: { - - } - onAmountChanged: { - - } AssetSelector { id: holdingSelector diff --git a/ui/imports/shared/stores/RequestPaymentStore.qml b/ui/imports/shared/stores/RequestPaymentStore.qml index c4bd78fa80..add85d4565 100644 --- a/ui/imports/shared/stores/RequestPaymentStore.qml +++ b/ui/imports/shared/stores/RequestPaymentStore.qml @@ -4,6 +4,7 @@ QtObject { required property CurrenciesStore currencyStore required property var flatNetworksModel required property var processedAssetsModel + required property var plainAssetsModel required property var accountsModel property var requestPaymentModel: null