wip: Request payment modal 2

This commit is contained in:
Emil Sawicki 2024-11-11 14:10:27 +01:00
parent 0b87e072cc
commit 2216d21828
4 changed files with 26 additions and 86 deletions

View File

@ -29,31 +29,6 @@ SplitView {
orientation: Qt.Horizontal 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 { QtObject {
id: d id: d
readonly property var tokenBySymbolModel: TokensBySymbolModel {} readonly property var tokenBySymbolModel: TokensBySymbolModel {}
@ -70,7 +45,6 @@ SplitView {
walletTokensStore: WalletStores.TokensStore { walletTokensStore: WalletStores.TokensStore {
plainTokensBySymbolModel: TokensBySymbolModel {} plainTokensBySymbolModel: TokensBySymbolModel {}
} }
readonly property var baseGroupedAccountAssetModel: GroupedAccountsAssetsModel {}
assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel
} }
@ -80,7 +54,8 @@ SplitView {
readonly property SharedStores.RequestPaymentStore requestPaymentStore: SharedStores.RequestPaymentStore { readonly property SharedStores.RequestPaymentStore requestPaymentStore: SharedStores.RequestPaymentStore {
currencyStore: d.currencyStore currencyStore: d.currencyStore
flatNetworksModel: d.flatNetworks flatNetworksModel: d.flatNetworks
processedAssetsModel: d.walletAssetsStore.renamedTokensBySymbolModel processedAssetsModel: d.walletAssetsStore.jointModel
plainAssetsModel: d.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel
accountsModel: d.accounts accountsModel: d.accounts
} }
} }
@ -100,7 +75,7 @@ SplitView {
onClicked: d.launchPopup() onClicked: d.launchPopup()
} }
Component.onCompleted: d.launchPopup() Component.onCompleted: Qt.callLater(d.launchPopup)
Component { Component {
id: requestPaymentModalComponent id: requestPaymentModalComponent

View File

@ -4,5 +4,6 @@ QtObject {
required property CurrenciesStore currencyStore required property CurrenciesStore currencyStore
required property var flatNetworksModel required property var flatNetworksModel
required property var processedAssetsModel required property var processedAssetsModel
required property var plainAssetsModel
required property var accountsModel required property var accountsModel
} }

View File

@ -1,14 +1,11 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtQml.Models 2.15 import QtQml.Models 2.15
import QtGraphicalEffects 1.15
import StatusQ 0.1 import StatusQ 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 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.private 0.1 as SQP
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import StatusQ.Popups.Dialog 0.1 import StatusQ.Popups.Dialog 0.1
@ -29,10 +26,9 @@ StatusDialog {
property int selectedNetworkChainId: Constants.chains.mainnetChainId property int selectedNetworkChainId: Constants.chains.mainnetChainId
property string selectedAccountAddress property string selectedAccountAddress
property string selectedTokenKey: Constants.ethToken property string selectedTokenKey: Constants.ethToken
onSelectedTokenKeyChanged: Qt.callLater(d.reevaluateSelectedId)
readonly property string amount: { 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 "0"
} }
return amountToSendInput.text return amountToSendInput.text
@ -49,33 +45,32 @@ StatusDialog {
title: qsTr("Payment request") 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 { QtObject {
id: d id: d
// FIXME use ModelEntry readonly property ModelEntry selectedHolding: ModelEntry {
property var selectedHolding: SQUtils.ModelUtils.getByKey(holdingSelector.model, "tokensKey", root.selectedTokenKey) sourceModel: holdingSelector.model
readonly property bool isSelectedHoldingValidAsset: !!selectedHolding key: "tokensKey"
}
readonly property bool isSelectedHoldingValidAsset: !!selectedHolding.item
readonly property var adaptor: TokenSelectorViewAdaptor { readonly property var adaptor: TokenSelectorViewAdaptor {
assetsModel: root.store.processedAssetsModel assetsModel: root.store.processedAssetsModel
flatNetworksModel: root.flatNetworksModel flatNetworksModel: root.flatNetworksModel
currentCurrency: root.store.currencyStore.currentCurrency currentCurrency: root.store.currencyStore.currentCurrency
plainTokensBySymbolModel: root.store.plainAssetsModel
showAllTokens: true 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 { footer: StatusDialogFooter {
@ -90,10 +85,7 @@ StatusDialog {
disabledColor: Theme.palette.directColor8 disabledColor: Theme.palette.directColor8
enabled: amountToSendInput.valid && !amountToSendInput.empty && amountToSendInput.asNumber > 0 enabled: amountToSendInput.valid && !amountToSendInput.empty && amountToSendInput.asNumber > 0
interactive: true interactive: true
onClicked: { onClicked: root.accept()
// TODO_ES handle
root.accept()
}
} }
} }
} }
@ -113,51 +105,22 @@ StatusDialog {
Layout.fillWidth: true Layout.fillWidth: true
readonly property bool ready: valid && !empty 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: { readonly property double asNumber: {
if (!valid) if (!valid)
return 0 return 0
return parseFloat(text.replace(LocaleUtils.userInputLocale.decimalPoint, ".")) 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 multiplierIndex: d.isSelectedHoldingValidAsset && !!d.selectedHolding.item.decimals ? d.selectedHolding.item.decimals : 0
// !!holdingSelector.selectedItem price: d.isSelectedHoldingValidAsset && !!d.selectedHolding.item.marketDetails ? d.selectedHolding.item.marketDetails.currencyPrice.amount : 1
// && !!holdingSelector.selectedItem.decimals
// ? holdingSelector.selectedItem.decimals : 0
// price: d.isSelectedHoldingValidAsset
// ? (d.selectedHolding ?
// d.selectedHolding.marketDetails.currencyPrice.amount : 1)
// : 1
price: 1
formatFiat: amount => root.store.currencyStore.formatCurrencyAmount( formatFiat: amount => root.store.currencyStore.formatCurrencyAmount(
amount, root.store.currencyStore.currentCurrency) amount, root.store.currencyStore.currentCurrency)
formatBalance: amount => root.store.currencyStore.formatCurrencyAmount( formatBalance: amount => root.store.currencyStore.formatCurrencyAmount(
amount, selectedSymbol) amount, root.selectedTokenKey)
showSeparator: true showSeparator: true
onValidChanged: {
}
onAmountChanged: {
}
AssetSelector { AssetSelector {
id: holdingSelector id: holdingSelector

View File

@ -4,5 +4,6 @@ QtObject {
required property CurrenciesStore currencyStore required property CurrenciesStore currencyStore
required property var flatNetworksModel required property var flatNetworksModel
required property var processedAssetsModel required property var processedAssetsModel
required property var plainAssetsModel
required property var accountsModel required property var accountsModel
} }