diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index f4c2e3a3f3..f98d03b8b7 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, strformat, strutils, chronicles, json, std/wrapnils, parseUtils, stint, tables +import NimQml, Tables, strformat, strutils, chronicles, json, std/wrapnils, parseUtils, stint, tables, json_serialization import ../../status/[status, wallet, threads] import ../../status/wallet/collectibles as status_collectibles import ../../status/libstatus/accounts/constants @@ -457,11 +457,16 @@ QtObject: proc gasPricePredictionsChanged*(self: WalletView) {.signal.} proc getGasPricePredictions*(self: WalletView) {.slot.} = - let prediction = self.status.wallet.getGasPricePredictions() - self.safeLowGasPrice = $prediction.safeLow - self.standardGasPrice = $prediction.standard - self.fastGasPrice = $prediction.fast - self.fastestGasPrice = $prediction.fastest + let walletModel = self.status.wallet + spawnAndSend(self, "getGasPricePredictionsResult") do: + $ %walletModel.getGasPricePredictions() + + proc getGasPricePredictionsResult(self: WalletView, gasPricePredictionsJson: string) {.slot.} = + let prediction = Json.decode(gasPricePredictionsJson, GasPricePrediction) + self.safeLowGasPrice = fmt"{prediction.safeLow:.3f}" + self.standardGasPrice = fmt"{prediction.standard:.3f}" + self.fastGasPrice = fmt"{prediction.fast:.3f}" + self.fastestGasPrice = fmt"{prediction.fastest:.3f}" self.gasPricePredictionsChanged() proc safeLowGasPrice*(self: WalletView): string {.slot.} = result = ?.self.safeLowGasPrice diff --git a/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml b/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml index f19ce5c49e..c2b32ee630 100644 --- a/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml +++ b/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml @@ -118,10 +118,6 @@ Popup { accounts: walletModel.accounts selectedAccount: walletModel.currentAccount currency: walletModel.defaultCurrency - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - selectedAccount = Qt.binding(function() { return walletModel.currentAccount }) - } onSelectedAccountChanged: { if (!root.currentAddress) { // We just set the account for the first time. Nothing to do here diff --git a/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml b/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml index 3e57fcfdc5..af217bcee7 100644 --- a/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml +++ b/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml @@ -105,10 +105,6 @@ Popup { accounts: walletModel.accounts selectedAccount: walletModel.currentAccount currency: walletModel.defaultCurrency - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - selectedAccount = Qt.binding(function() { return walletModel.currentAccount }) - } onSelectedAccountChanged: { if (!accountSelectorRow.currentAddress) { // We just set the account for the first time. Nothing to do here diff --git a/ui/app/AppLayouts/Browser/SignMessageModal.qml b/ui/app/AppLayouts/Browser/SignMessageModal.qml index ce1e0b2711..ca2c754e08 100644 --- a/ui/app/AppLayouts/Browser/SignMessageModal.qml +++ b/ui/app/AppLayouts/Browser/SignMessageModal.qml @@ -80,9 +80,6 @@ ModalPopup { anchors.top: messageToSign.bottom anchors.topMargin: Style.current.padding * 3 signingPhrase: walletModel.signingPhrase - reset: function() { - signingPhrase = Qt.binding(function() { return walletModel.signingPhrase }) - } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn.qml b/ui/app/AppLayouts/Chat/ChatColumn.qml index c7a638c3c9..6109039a81 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn.qml @@ -55,7 +55,7 @@ StackLayout { address, amount, tokenAddress) - chatCommandModal.close() + txModalLoader.close() } function requestTransaction(address, amount, tokenAddress, tokenDecimals = 18) { amount = utilsModel.eth2Wei(amount.toString(), tokenDecimals) @@ -63,7 +63,7 @@ StackLayout { address, amount, tokenAddress) - chatCommandModal.close() + txModalLoader.close() } @@ -226,7 +226,6 @@ StackLayout { stickerPackList: chatsModel.stickerPacks chatType: chatsModel.activeChannel.chatType onSendTransactionCommandButtonClicked: { - txModalLoader.sourceComponent = undefined if (chatsModel.activeChannel.ensVerified) { txModalLoader.sourceComponent = cmpSendTransactionWithEns } else { @@ -235,7 +234,6 @@ StackLayout { txModalLoader.item.open() } onReceiveTransactionCommandButtonClicked: { - txModalLoader.sourceComponent = undefined txModalLoader.sourceComponent = cmpReceiveTransaction txModalLoader.item.open() } @@ -250,11 +248,24 @@ StackLayout { Loader { id: txModalLoader + function close() { + if (!this.item) { + return + } + this.item.close() + this.closed() + } + function closed() { + this.sourceComponent = undefined + } } Component { id: cmpSendTransactionNoEns ChatCommandModal { id: sendTransactionNoEns + onClosed: { + txModalLoader.closed() + } sendChatCommand: chatColumnLayout.requestAddressForTransaction isRequested: false //% "Send" @@ -273,25 +284,15 @@ StackLayout { } selectRecipient.selectedType: RecipientSelector.Type.Contact selectRecipient.readOnly: true - onReset: { - selectRecipient.selectedRecipient = Qt.binding(function() { - return { - address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet - alias: chatsModel.activeChannel.alias, - identicon: chatsModel.activeChannel.identicon, - name: chatsModel.activeChannel.name, - type: RecipientSelector.Type.Contact - } - }) - selectRecipient.selectedType = RecipientSelector.Type.Contact - selectRecipient.readOnly = true - } } } Component { id: cmpReceiveTransaction ChatCommandModal { id: receiveTransaction + onClosed: { + txModalLoader.closed() + } sendChatCommand: chatColumnLayout.requestTransaction isRequested: true //% "Request" @@ -310,19 +311,6 @@ StackLayout { } selectRecipient.selectedType: RecipientSelector.Type.Contact selectRecipient.readOnly: true - onReset: { - selectRecipient.selectedRecipient = Qt.binding(function() { - return { - address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet - alias: chatsModel.activeChannel.alias, - identicon: chatsModel.activeChannel.identicon, - name: chatsModel.activeChannel.name, - type: RecipientSelector.Type.Contact - } - }) - selectRecipient.selectedType = RecipientSelector.Type.Contact - selectRecipient.readOnly = true - } } } Component { @@ -332,6 +320,9 @@ StackLayout { onOpened: { walletModel.getGasPricePredictions() } + onClosed: { + txModalLoader.closed() + } selectRecipient.readOnly: true selectRecipient.selectedRecipient: { return { @@ -344,20 +335,6 @@ StackLayout { } } selectRecipient.selectedType: RecipientSelector.Type.Contact - onReset: { - selectRecipient.readOnly = true - selectRecipient.selectedRecipient = Qt.binding(function() { - return { - address: "", - alias: chatsModel.activeChannel.alias, - identicon: chatsModel.activeChannel.identicon, - name: chatsModel.activeChannel.name, - type: RecipientSelector.Type.Contact, - ensVerified: true - } - }) - selectRecipient.selectedType = RecipientSelector.Type.Contact - } } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/ChatCommandModal.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/ChatCommandModal.qml index 4e6002deca..857c1381f3 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/ChatCommandModal.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/ChatCommandModal.qml @@ -11,7 +11,6 @@ ModalPopup { property string finalButtonLabel: "Request address" property var sendChatCommand: function () {} property bool isRequested: false - signal reset id: root title: root.commandTitle @@ -19,11 +18,6 @@ ModalPopup { property alias selectRecipient: selectRecipient - onClosed: { - stack.reset() - root.reset() - } - TransactionStackView { id: stack anchors.fill: parent @@ -51,10 +45,6 @@ ModalPopup { //% "From account" qsTrId("from-account") } - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - selectedAccount = Qt.binding(function() { return walletModel.currentAccount }) - } } SeparatorWithIcon { id: separator @@ -86,9 +76,6 @@ ModalPopup { onSelectedRecipientChanged: { addressRequiredValidator.address = root.isRequested ? selectFromAccount.selectedAccount.address : selectRecipient.selectedRecipient.address } - reset: function() { - isValid = true - } } } TransactionFormGroup { @@ -105,9 +92,6 @@ ModalPopup { getCryptoValue: walletModel.getCryptoValue validateBalance: !root.isRequested width: stack.width - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - } } } TransactionFormGroup { @@ -127,20 +111,6 @@ ModalPopup { amount: { "value": txtAmount.selectedAmount, "fiatValue": txtAmount.selectedFiatAmount } toWarn: addressRequiredValidator.isWarn currency: walletModel.defaultCurrency - reset: function() { - fromAccount = Qt.binding(function() { - return root.isRequested ? - selectRecipient.selectedRecipient : - selectFromAccount.selectedAccount - }) - toAccount = Qt.binding(function() { - return root.isRequested ? - selectFromAccount.selectedAccount : - selectRecipient.selectedRecipient - }) - asset = Qt.binding(function() { return txtAmount.selectedAsset }) - amount = Qt.binding(function() { return { "value": txtAmount.selectedAmount, "fiatValue": txtAmount.selectedFiatAmount } }) - } } AddressRequiredValidator { diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml index cbf16c886b..1238167d47 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml @@ -50,7 +50,6 @@ ModalPopup { } onClosed: { - stack.reset() stack.pop(groupPreview, StackView.Immediate) } @@ -91,11 +90,6 @@ ModalPopup { label: qsTrId("choose-account") showBalanceForAssetSymbol: root.selectedAsset.symbol minRequiredAssetBalance: parseFloat(root.selectedAmount) - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - showBalanceForAssetSymbol = Qt.binding(function() { return root.selectedAsset.symbol }) - minRequiredAssetBalance = Qt.binding(function() { return parseFloat(root.selectedAmount) }) - } onSelectedAccountChanged: if (isValid) { gasSelector.estimateGas() } } RecipientSelector { @@ -105,11 +99,6 @@ ModalPopup { contacts: profileModel.addedContacts selectedRecipient: root.selectedRecipient readOnly: true - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - contacts = Qt.binding(function() { return profileModel.addedContacts }) - selectedRecipient = Qt.binding(function() { return root.selectedRecipient }) - } } } TransactionFormGroup { @@ -130,10 +119,6 @@ ModalPopup { getFiatValue: walletModel.getFiatValue defaultCurrency: walletModel.defaultCurrency width: stack.width - reset: function() { - slowestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.safeLowGasPrice) }) - fastestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.fastestGasPrice) }) - } property var estimateGas: Backpressure.debounce(gasSelector, 600, function() { if (!(selectFromAccount.selectedAccount && selectFromAccount.selectedAccount.address && @@ -167,12 +152,6 @@ ModalPopup { selectedAmount: parseFloat(root.selectedAmount) selectedAsset: root.selectedAsset selectedGasEthValue: gasSelector.selectedGasEthValue - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - selectedAmount = Qt.binding(function() { return parseFloat(root.selectedAmount) }) - selectedAsset = Qt.binding(function() { return root.selectedAsset }) - selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue }) - } } } @@ -205,21 +184,6 @@ ModalPopup { isGasEditable: true fromValid: balanceValidator.isValid gasValid: gasValidator.isValid - reset: function() { - fromAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - gas = Qt.binding(function() { - return { - "value": gasSelector.selectedGasEthValue, - "symbol": "ETH", - "fiatValue": gasSelector.selectedGasFiatValue - } - }) - toAccount = Qt.binding(function() { return selectRecipient.selectedRecipient }) - asset = Qt.binding(function() { return root.selectedAsset }) - amount = Qt.binding(function() { return { "value": root.selectedAmount, "fiatValue": root.selectedFiatAmount } }) - fromValid = Qt.binding(function() { return balanceValidator.isValid }) - gasValid = Qt.binding(function() { return gasValidator.isValid }) - } onFromClicked: { stack.push(groupSelectAcct, StackView.Immediate) } onGasClicked: { stack.push(groupSelectGas, StackView.Immediate) } } @@ -230,11 +194,6 @@ ModalPopup { account: selectFromAccount.selectedAccount amount: !!root.selectedAmount ? parseFloat(root.selectedAmount) : 0.0 asset: root.selectedAsset - reset: function() { - account = Qt.binding(function() { return selectFromAccount.selectedAccount }) - amount = Qt.binding(function() { return !!root.selectedAmount ? parseFloat(root.selectedAmount) : 0.0 }) - asset = Qt.binding(function() { return root.selectedAsset }) - } } GasValidator { id: gasValidator2 @@ -245,12 +204,6 @@ ModalPopup { selectedAmount: parseFloat(root.selectedAmount) selectedAsset: root.selectedAsset selectedGasEthValue: gasSelector.selectedGasEthValue - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - selectedAmount = Qt.binding(function() { return parseFloat(root.selectedAmount) }) - selectedAsset = Qt.binding(function() { return root.selectedAsset }) - selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue }) - } } } TransactionFormGroup { @@ -267,9 +220,6 @@ ModalPopup { id: transactionSigner width: stack.width signingPhrase: walletModel.signingPhrase - reset: function() { - signingPhrase = Qt.binding(function() { return walletModel.signingPhrase }) - } } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/AcceptTransaction.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/AcceptTransaction.qml index 4ab3f6a312..86f6951820 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/AcceptTransaction.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/AcceptTransaction.qml @@ -77,24 +77,35 @@ Item { } } - SignTransactionModal { + Loader { id: signTransactionModal - onOpened: { - walletModel.getGasPricePredictions() + function open() { + this.active = true + this.item.open() } - selectedAccount: {} - selectedRecipient: { - return { - address: commandParametersObject.address, - identicon: chatsModel.activeChannel.identicon, - name: chatsModel.activeChannel.name, - type: RecipientSelector.Type.Contact + function closed() { + this.active = false // kill an opened instance + } + sourceComponent: SignTransactionModal { + onOpened: { + walletModel.getGasPricePredictions() } + onClosed: { + signTransactionModal.closed() + } + selectedAccount: {} + selectedRecipient: { + return { + address: commandParametersObject.address, + identicon: chatsModel.activeChannel.identicon, + name: chatsModel.activeChannel.name, + type: RecipientSelector.Type.Contact + } + } + selectedAsset: token + selectedAmount: tokenAmount + selectedFiatAmount: fiatValue } - selectedAsset: token - selectedAmount: tokenAmount - selectedFiatAmount: fiatValue - //outgoing: root.outgoing } SelectAccountModal { diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SelectAccountModal.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SelectAccountModal.qml index 651d207477..200b394543 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SelectAccountModal.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SelectAccountModal.qml @@ -24,9 +24,6 @@ ModalPopup { width: parent.width //% "Choose account" label: qsTr("Select account to share and receive assets") - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SendTransactionButton.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SendTransactionButton.qml index 1d82e01309..bec5875701 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SendTransactionButton.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/TransactionComponents/SendTransactionButton.qml @@ -42,22 +42,34 @@ Item { } } - SignTransactionModal { + Loader { id: signTransactionModal - onOpened: { - walletModel.getGasPricePredictions() + function open() { + this.active = true + this.item.open() } - selectedRecipient: { - return { - address: commandParametersObject.address, - identicon: chatsModel.activeChannel.identicon, - name: chatsModel.activeChannel.name, - type: RecipientSelector.Type.Contact + function closed() { + this.active = false // kill an opened instance + } + sourceComponent: SignTransactionModal { + onOpened: { + walletModel.getGasPricePredictions() } + onClosed: { + signTransactionModal.closed() + } + selectedRecipient: { + return { + address: commandParametersObject.address, + identicon: chatsModel.activeChannel.identicon, + name: chatsModel.activeChannel.name, + type: RecipientSelector.Type.Contact + } + } + selectedAsset: token + selectedAmount: tokenAmount + selectedFiatAmount: fiatValue } - selectedAsset: token - selectedAmount: tokenAmount - selectedFiatAmount: fiatValue } } diff --git a/ui/app/AppLayouts/Profile/Sections/Ens/RegisterENSModal.qml b/ui/app/AppLayouts/Profile/Sections/Ens/RegisterENSModal.qml index d5baa4cb47..d39b9cbfe5 100644 --- a/ui/app/AppLayouts/Profile/Sections/Ens/RegisterENSModal.qml +++ b/ui/app/AppLayouts/Profile/Sections/Ens/RegisterENSModal.qml @@ -23,10 +23,6 @@ ModalPopup { standardButtons: StandardButton.Ok } - onClosed: { - stack.reset() - } - function sendTransaction() { let responseStr = profileModel.ens.registerENS(root.ensUsername, selectFromAccount.selectedAccount.address, @@ -75,12 +71,6 @@ ModalPopup { label: qsTrId("choose-account") showBalanceForAssetSymbol: root.asset.symbol minRequiredAssetBalance: root.ensPrice - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - selectedAccount = Qt.binding(function() { return walletModel.currentAccount }) - showBalanceForAssetSymbol = Qt.binding(function() { return root.asset.symbol }) - minRequiredAssetBalance = Qt.binding(function() { return root.ensPrice }) - } onSelectedAccountChanged: if (isValid) { gasSelector.estimateGas() } } RecipientSelector { @@ -100,10 +90,6 @@ ModalPopup { getGasEthValue: walletModel.getGasEthValue getFiatValue: walletModel.getFiatValue defaultCurrency: walletModel.defaultCurrency - reset: function() { - slowestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.safeLowGasPrice) }) - fastestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.fastestGasPrice) }) - } property var estimateGas: Backpressure.debounce(gasSelector, 600, function() { if (!(root.ensUsername !== "" && selectFromAccount.selectedAccount)) { selectedGasLimit = 380000 @@ -120,12 +106,6 @@ ModalPopup { selectedAsset: root.asset selectedAmount: parseFloat(ensPrice) selectedGasEthValue: gasSelector.selectedGasEthValue - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - selectedAsset = Qt.binding(function() { return root.asset }) - selectedAmount = Qt.binding(function() { return parseFloat(ensPrice) }) - selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue }) - } } } TransactionFormGroup { @@ -151,19 +131,6 @@ ModalPopup { const fiatValue = walletModel.getFiatValue(root.ensPrice || 0, root.asset.symbol, currency) return { "value": root.ensPrice, "fiatValue": fiatValue } } - reset: function() { - fromAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - toAccount = Qt.binding(function() { return selectRecipient.selectedRecipient }) - asset = Qt.binding(function() { return root.asset }) - amount = Qt.binding(function() { return { "value": root.ensPrice, "fiatValue": walletModel.getFiatValue(root.ensPrice, root.asset.symbol, currency) } }) - gas = Qt.binding(function() { - return { - "value": gasSelector.selectedGasEthValue, - "symbol": "ETH", - "fiatValue": gasSelector.selectedGasFiatValue - } - }) - } } } TransactionFormGroup { @@ -177,9 +144,6 @@ ModalPopup { id: transactionSigner width: stack.width signingPhrase: walletModel.signingPhrase - reset: function() { - signingPhrase = Qt.binding(function() { return walletModel.signingPhrase }) - } } } } diff --git a/ui/app/AppLayouts/Profile/Sections/Ens/Search.qml b/ui/app/AppLayouts/Profile/Sections/Ens/Search.qml index ad4fd687aa..cd2d1b502c 100644 --- a/ui/app/AppLayouts/Profile/Sections/Ens/Search.qml +++ b/ui/app/AppLayouts/Profile/Sections/Ens/Search.qml @@ -46,11 +46,23 @@ Item { Qt.callLater(validateENS, ensUsername, isStatus) } - SetPubKeyModal { + Loader { id: transactionDialog - ensUsername: ensUsername.text - width: 400 - height: 400 + function open() { + this.active = true + this.item.open() + } + function closed() { + this.active = false // kill an opened instance + } + sourceComponent: SetPubKeyModal { + onClosed: { + transactionDialog.closed() + } + ensUsername: ensUsername.text + width: 400 + height: 400 + } } StyledText { diff --git a/ui/app/AppLayouts/Profile/Sections/Ens/SetPubKeyModal.qml b/ui/app/AppLayouts/Profile/Sections/Ens/SetPubKeyModal.qml index bdf29f09e3..b22f43578a 100644 --- a/ui/app/AppLayouts/Profile/Sections/Ens/SetPubKeyModal.qml +++ b/ui/app/AppLayouts/Profile/Sections/Ens/SetPubKeyModal.qml @@ -21,10 +21,6 @@ ModalPopup { standardButtons: StandardButton.Ok } - onClosed: { - stack.reset() - } - function sendTransaction() { try { let responseStr = profileModel.ens.setPubKey(root.ensUsername, @@ -79,12 +75,6 @@ ModalPopup { label: qsTrId("choose-account") showBalanceForAssetSymbol: "ETH" minRequiredAssetBalance: 0 - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - selectedAccount = Qt.binding(function() { return walletModel.currentAccount }) - showBalanceForAssetSymbol = Qt.binding(function() { return "ETH" }) - minRequiredAssetBalance = Qt.binding(function() { return 0 }) - } onSelectedAccountChanged: if (isValid) { gasSelector.estimateGas() } } RecipientSelector { @@ -104,10 +94,6 @@ ModalPopup { getGasEthValue: walletModel.getGasEthValue getFiatValue: walletModel.getFiatValue defaultCurrency: walletModel.defaultCurrency - reset: function() { - slowestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.safeLowGasPrice) }) - fastestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.fastestGasPrice) }) - } property var estimateGas: Backpressure.debounce(gasSelector, 600, function() { if (!(root.ensUsername !== "" && selectFromAccount.selectedAccount)) { selectedGasLimit = 80000; @@ -124,12 +110,6 @@ ModalPopup { selectedAsset: root.asset selectedAmount: 0 selectedGasEthValue: gasSelector.selectedGasEthValue - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - selectedAsset = Qt.binding(function() { return root.asset }) - selectedAmount = Qt.binding(function() { return 0 }) - selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue }) - } } } TransactionFormGroup { @@ -155,19 +135,6 @@ ModalPopup { const fiatValue = walletModel.getFiatValue(0, root.asset.symbol, currency) return { "value": 0, "fiatValue": fiatValue } } - reset: function() { - fromAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - toAccount = Qt.binding(function() { return selectRecipient.selectedRecipient }) - asset = Qt.binding(function() { return root.asset }) - amount = Qt.binding(function() { return { "value": 0, "fiatValue": walletModel.getFiatValue(0, root.asset.symbol, currency) } }) - gas = Qt.binding(function() { - return { - "value": gasSelector.selectedGasEthValue, - "symbol": "ETH", - "fiatValue": gasSelector.selectedGasFiatValue - } - }) - } } } TransactionFormGroup { @@ -181,9 +148,6 @@ ModalPopup { id: transactionSigner width: stack.width signingPhrase: walletModel.signingPhrase - reset: function() { - signingPhrase = Qt.binding(function() { return walletModel.signingPhrase }) - } } } } diff --git a/ui/app/AppLayouts/Profile/Sections/Ens/TermsAndConditions.qml b/ui/app/AppLayouts/Profile/Sections/Ens/TermsAndConditions.qml index c561f8fe02..bd3018b183 100644 --- a/ui/app/AppLayouts/Profile/Sections/Ens/TermsAndConditions.qml +++ b/ui/app/AppLayouts/Profile/Sections/Ens/TermsAndConditions.qml @@ -23,11 +23,23 @@ Item { font.pixelSize: 20 } - RegisterENSModal { + Loader { id: transactionDialog - ensUsername: username - width: 400 - height: 400 + function open() { + this.active = true + this.item.open() + } + function closed() { + this.active = false // kill an opened instance + } + sourceComponent: RegisterENSModal { + onClosed: { + transactionDialog.closed() + } + ensUsername: username + width: 400 + height: 400 + } } ModalPopup { diff --git a/ui/app/AppLayouts/Wallet/SendModal.qml b/ui/app/AppLayouts/Wallet/SendModal.qml index a23e8765f9..e23f8ed7c9 100644 --- a/ui/app/AppLayouts/Wallet/SendModal.qml +++ b/ui/app/AppLayouts/Wallet/SendModal.qml @@ -12,7 +12,6 @@ ModalPopup { property alias selectFromAccount: selectFromAccount property alias selectRecipient: selectRecipient property alias stack: stack - signal reset //% "Send" title: qsTrId("command-button-send") @@ -26,11 +25,6 @@ ModalPopup { standardButtons: StandardButton.Ok } - onClosed: { - stack.reset() - root.reset() - } - function sendTransaction() { stack.currentGroup.isPending = true walletModel.sendTransaction(selectFromAccount.selectedAccount.address, @@ -67,10 +61,6 @@ ModalPopup { width: stack.width //% "From account" label: qsTrId("from-account") - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - selectedAccount = Qt.binding(function() { return walletModel.currentAccount }) - } onSelectedAccountChanged: if (isValid) { gasSelector.estimateGas() } } SeparatorWithIcon { @@ -87,11 +77,6 @@ ModalPopup { anchors.top: separator.bottom anchors.topMargin: 10 width: stack.width - reset: function() { - accounts = Qt.binding(function() { return walletModel.accounts }) - contacts = Qt.binding(function() { return profileModel.addedContacts }) - selectedRecipient = undefined - } onSelectedRecipientChanged: if (isValid) { gasSelector.estimateGas() } } } @@ -109,9 +94,6 @@ ModalPopup { getFiatValue: walletModel.getFiatValue getCryptoValue: walletModel.getCryptoValue width: stack.width - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - } onSelectedAssetChanged: if (isValid) { gasSelector.estimateGas() } onSelectedAmountChanged: if (isValid) { gasSelector.estimateGas() } } @@ -125,10 +107,6 @@ ModalPopup { getFiatValue: walletModel.getFiatValue defaultCurrency: walletModel.defaultCurrency width: stack.width - reset: function() { - slowestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.safeLowGasPrice) }) - fastestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.fastestGasPrice) }) - } property var estimateGas: Backpressure.debounce(gasSelector, 600, function() { if (!(selectFromAccount.selectedAccount && selectFromAccount.selectedAccount.address && selectRecipient.selectedRecipient && selectRecipient.selectedRecipient.address && @@ -158,12 +136,6 @@ ModalPopup { selectedAmount: parseFloat(txtAmount.selectedAmount) selectedAsset: txtAmount.selectedAsset selectedGasEthValue: gasSelector.selectedGasEthValue - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - selectedAmount = Qt.binding(function() { return parseFloat(txtAmount.selectedAmount) }) - selectedAsset = Qt.binding(function() { return txtAmount.selectedAsset }) - selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue }) - } } } TransactionFormGroup { @@ -186,27 +158,11 @@ ModalPopup { asset: txtAmount.selectedAsset amount: { "value": txtAmount.selectedAmount, "fiatValue": txtAmount.selectedFiatAmount } currency: walletModel.defaultCurrency - reset: function() { - fromAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - toAccount = Qt.binding(function() { return selectRecipient.selectedRecipient }) - asset = Qt.binding(function() { return txtAmount.selectedAsset }) - amount = Qt.binding(function() { return { "value": txtAmount.selectedAmount, "fiatValue": txtAmount.selectedFiatAmount } }) - gas = Qt.binding(function() { - return { - "value": gasSelector.selectedGasEthValue, - "symbol": "ETH", - "fiatValue": gasSelector.selectedGasFiatValue - } - }) - } } SendToContractWarning { id: sendToContractWarning anchors.top: pvwTransaction.bottom selectedRecipient: selectRecipient.selectedRecipient - reset: function() { - selectedRecipient = Qt.binding(function() { return selectRecipient.selectedRecipient }) - } } } TransactionFormGroup { @@ -220,9 +176,6 @@ ModalPopup { id: transactionSigner width: stack.width signingPhrase: walletModel.signingPhrase - reset: function() { - signingPhrase = Qt.binding(function() { return walletModel.signingPhrase }) - } } } } diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index a30ff2cccf..fc61af5899 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -18,10 +18,24 @@ RowLayout { } // Add SenmdModal here as it is used by the Wallet as well as the Browser - SendModal{ + Loader { id: sendModal - onOpened: { - walletModel.getGasPricePredictions() + + function open() { + this.active = true + this.item.open() + } + function closed() { + // this.sourceComponent = undefined // kill an opened instance + this.active = false + } + sourceComponent: SendModal { + onOpened: { + walletModel.getGasPricePredictions() + } + onClosed: { + sendModal.closed() + } } } diff --git a/ui/shared/AccountSelector.qml b/ui/shared/AccountSelector.qml index 38e5560a87..32823d543a 100644 --- a/ui/shared/AccountSelector.qml +++ b/ui/shared/AccountSelector.qml @@ -25,17 +25,6 @@ Item { property alias dropdownAlignment: select.menuAlignment property bool isValid: true property bool readOnly: false - property var reset: function() {} - - function resetInternal() { - accounts = undefined - selectedAccount = undefined - showBalanceForAssetSymbol = "" - minRequiredAssetBalance = 0 - assetFound = undefined - isValid = true - readOnly = false - } function validate() { if (showBalanceForAssetSymbol == "" || minRequiredAssetBalance == 0 || !assetFound) { diff --git a/ui/shared/AddressSourceSelector.qml b/ui/shared/AddressSourceSelector.qml index 8d2473c14a..856a0907eb 100644 --- a/ui/shared/AddressSourceSelector.qml +++ b/ui/shared/AddressSourceSelector.qml @@ -9,14 +9,8 @@ Item { property var sources: [] property var selectedSource: sources.length ? sources[0] : null property int dropdownWidth: 220 - property var reset: function() {} height: select.height - function resetInternal() { - sources = [] - selectedSource = sources.length ? sources[0] : null - } - Select { id: select anchors.left: parent.left diff --git a/ui/shared/AssetAndAmountInput.qml b/ui/shared/AssetAndAmountInput.qml index 9bb0828414..3fb2aa0100 100644 --- a/ui/shared/AssetAndAmountInput.qml +++ b/ui/shared/AssetAndAmountInput.qml @@ -23,17 +23,6 @@ Item { property bool isDirty: false property bool validateBalance: true property bool isValid: false - property var reset: function() {} - - function resetInternal() { - selectAsset.resetInternal() - selectedAccount = undefined - txtFiatBalance.text = "0.00" - inputAmount.resetInternal() - txtBalanceDesc.color = Style.current.secondaryText - txtBalance.color = Qt.binding(function() { return txtBalance.hovered ? Style.current.textColor : Style.current.secondaryText }) - isValid = false - } id: root diff --git a/ui/shared/BalanceValidator.qml b/ui/shared/BalanceValidator.qml index 5bfb4fa615..09cc876aa8 100644 --- a/ui/shared/BalanceValidator.qml +++ b/ui/shared/BalanceValidator.qml @@ -14,20 +14,12 @@ Column { property double amount property var asset property bool isValid: false - property var reset: function() {} property alias errorMessage: txtValidationError.text onAccountChanged: validate() onAmountChanged: validate() onAssetChanged: validate() - function resetInternal() { - account = undefined - amount = 0 - asset = undefined - isValid = false - } - function validate() { let isValid = true if (!(account && account.assets && asset && amount > 0)) { diff --git a/ui/shared/ContactSelector.qml b/ui/shared/ContactSelector.qml index 0eebd9d25a..a807519e09 100644 --- a/ui/shared/ContactSelector.qml +++ b/ui/shared/ContactSelector.qml @@ -16,22 +16,12 @@ Item { property alias validationErrorAlignment: select.validationErrorAlignment property bool isValid: false property alias isPending: ensResolver.isPending - property var reset: function() {} property bool readOnly: false property bool isResolvedAddress: false //% "Select a contact" property string selectAContact: qsTrId("select-a-contact") property string noEnsAddressMessage: qsTr("Contact does not have an ENS address. Please send a transaction in chat.") - function resetInternal() { - contacts = undefined - selectedContact = undefined - select.validationError = "" - isValid = false - readOnly = false - isResolvedAddress = false - } - function resolveEns() { if (selectedContact.ensVerified) { root.isResolvedAddress = false @@ -139,7 +129,7 @@ Item { anchors.top: select.bottom anchors.right: select.right anchors.topMargin: Style.current.halfPadding - debounceDelay: root.readOnly ? 0 : 600 + debounceDelay: 0 onResolved: { root.isResolvedAddress = true var selectedContact = root.selectedContact diff --git a/ui/shared/FormGroup.qml b/ui/shared/FormGroup.qml index a2451a81c5..4515e3f49a 100644 --- a/ui/shared/FormGroup.qml +++ b/ui/shared/FormGroup.qml @@ -22,22 +22,6 @@ Rectangle { return { isValid, isPending } } color: Style.current.background - function reset() { - for (let i=0; i 0)) { diff --git a/ui/shared/RecipientSelector.qml b/ui/shared/RecipientSelector.qml index cb71227876..42753f66b2 100644 --- a/ui/shared/RecipientSelector.qml +++ b/ui/shared/RecipientSelector.qml @@ -28,11 +28,10 @@ Item { return inpAddress.isPending case RecipientSelector.Type.Contact: return selContact.isPending - default: - return false + case RecipientSelector.Type.Account: + return false // AccountSelector is never pending } } - property var reset: function() {} readonly property var sources: [ //% "Address" { text: qsTrId("address"), value: RecipientSelector.Type.Address, visible: true }, @@ -41,34 +40,6 @@ Item { { text: qsTr("Contact"), value: RecipientSelector.Type.Contact, visible: true } ] property var selectedType: RecipientSelector.Type.Address - - function resetInternal() { - inpAddress.resetInternal() - selContact.resetInternal() - selAccount.resetInternal() - selAddressSource.resetInternal() - isValid = false - isPending = Qt.binding(function() { - if (!selAddressSource.selectedSource) { - return false - } - switch (selAddressSource.selectedSource.value) { - case RecipientSelector.Type.Address: - return inpAddress.isPending - case RecipientSelector.Type.Contact: - return selContact.isPending - case RecipientSelector.Type.Account: - return selAccount.isPending - } - }) - selectedType = RecipientSelector.Type.Address - selectedRecipient = undefined - accounts = undefined - contacts = undefined - selContact.reset() - selAccount.reset() - selAddressSource.reset() - } enum Type { Address, @@ -78,7 +49,10 @@ Item { function validate() { let isValid = true - switch (root.selectedType) { + if (!selAddressSource.selectedSource) { + return root.isValid + } + switch (selAddressSource.selectedSource.value) { case RecipientSelector.Type.Address: isValid = inpAddress.isValid break @@ -190,10 +164,6 @@ Item { Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width Layout.alignment: Qt.AlignTop Layout.fillWidth: true - reset: function() { - contacts = Qt.binding(function() { return root.contacts }) - readOnly = Qt.binding(function() { return root.readOnly }) - } onSelectedContactChanged: { if (!selectedContact || !selAddressSource.selectedSource || !selectedContact.address || (selAddressSource.selectedSource && selAddressSource.selectedSource.value !== RecipientSelector.Type.Contact)) { return @@ -214,9 +184,6 @@ Item { Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width Layout.alignment: Qt.AlignTop Layout.fillWidth: true - reset: function() { - accounts = Qt.binding(function() { return root.accounts }) - } onSelectedAccountChanged: { if (!selectedAccount || !selAddressSource.selectedSource || (selAddressSource.selectedSource && selAddressSource.selectedSource.value !== RecipientSelector.Type.Account)) { return @@ -233,10 +200,6 @@ Item { width: sourceSelectWidth Layout.preferredWidth: root.sourceSelectWidth Layout.alignment: Qt.AlignTop - reset: function() { - sources = Qt.binding(function() { return root.sources.filter(source => source.visible) }) - selectedSource = root.getSourceByType(root.selectedType) - } onSelectedSourceChanged: { if (root.readOnly || !selectedSource) { diff --git a/ui/shared/SendToContractWarning.qml b/ui/shared/SendToContractWarning.qml index e59bd78b9a..c9267773bc 100644 --- a/ui/shared/SendToContractWarning.qml +++ b/ui/shared/SendToContractWarning.qml @@ -11,15 +11,9 @@ Item { property string sendToContractWarningMessage: qsTr("Tokens will be sent directly to a contract address, which may result in a loss of funds. To transfer ERC-20 tokens, ensure the recipient address is the address of the destination wallet.") property var selectedRecipient property bool isValid: true - property var reset: function() {} onSelectedRecipientChanged: validate() - function resetInternal() { - selectedRecipient = undefined - isValid = true - } - function validate() { let isValid = true if (!(selectedRecipient && selectedRecipient.address)) { diff --git a/ui/shared/TransactionPreview.qml b/ui/shared/TransactionPreview.qml index ceeeae8ee5..1d5bb7649b 100644 --- a/ui/shared/TransactionPreview.qml +++ b/ui/shared/TransactionPreview.qml @@ -14,7 +14,6 @@ Item { property string currency: "USD" property var gas height: content.height - property var reset: function() {} signal fromClicked signal gasClicked // Creates a mouse area around the "from account". When clicked, triggers @@ -29,14 +28,6 @@ Item { property bool toWarn: false property bool gasValid: true - function resetInternal() { - fromAccount = undefined - toAccount = undefined - asset = undefined - amount = undefined - gas = undefined - } - Column { id: content anchors.left: parent.left diff --git a/ui/shared/TransactionSigner.qml b/ui/shared/TransactionSigner.qml index 13a384b86b..b3f6d45799 100644 --- a/ui/shared/TransactionSigner.qml +++ b/ui/shared/TransactionSigner.qml @@ -16,14 +16,6 @@ Item { //% "Password needs to be 4 characters or more" property string invalidInputErrorMessage: qsTrId("password-needs-to-be-4-characters-or-more") property bool isValid: false - property var reset: function() {} - - function resetInternal() { - signingPhrase.text = "" - enteredPassword = "" - txtPassword.resetInternal() - isValid = false - } function forceActiveFocus(reason) { txtPassword.forceActiveFocus(reason) diff --git a/ui/shared/TransactionStackView.qml b/ui/shared/TransactionStackView.qml index af146aebac..f6dea883c3 100644 --- a/ui/shared/TransactionStackView.qml +++ b/ui/shared/TransactionStackView.qml @@ -27,14 +27,6 @@ StackView { currentIdx-- } - function reset() { - for (let i=0; i -1 && selectFromAccount.selectedAccount && root.packPrice && parseFloat(root.packPrice) > 0)) { selectedGasLimit = 325000 @@ -124,12 +110,6 @@ ModalPopup { selectedAsset: root.asset selectedAmount: parseFloat(packPrice) selectedGasEthValue: gasSelector.selectedGasEthValue - reset: function() { - selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - selectedAsset = Qt.binding(function() { return root.asset }) - selectedAmount = Qt.binding(function() { return parseFloat(packPrice) }) - selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue }) - } } } TransactionFormGroup { @@ -159,19 +139,6 @@ ModalPopup { const fiatValue = walletModel.getFiatValue(root.packPrice || 0, root.asset.symbol, currency) return { "value": root.packPrice, "fiatValue": fiatValue } } - reset: function() { - fromAccount = Qt.binding(function() { return selectFromAccount.selectedAccount }) - toAccount = Qt.binding(function() { return selectRecipient.selectedRecipient }) - asset = Qt.binding(function() { return root.asset }) - amount = Qt.binding(function() { return { "value": root.packPrice, "fiatValue": walletModel.getFiatValue(root.packPrice, root.asset.symbol, currency) } }) - gas = Qt.binding(function() { - return { - "value": gasSelector.selectedGasEthValue, - "symbol": "ETH", - "fiatValue": gasSelector.selectedGasFiatValue - } - }) - } } } TransactionFormGroup { @@ -185,9 +152,6 @@ ModalPopup { id: transactionSigner width: stack.width signingPhrase: walletModel.signingPhrase - reset: function() { - signingPhrase = Qt.binding(function() { return walletModel.signingPhrase }) - } } } }