2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2020-08-13 08:24:51 +00:00
|
|
|
import QtQuick.Layouts 1.13
|
2020-08-20 04:45:29 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
2022-03-18 14:47:51 +00:00
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-12-08 21:20:43 +00:00
|
|
|
import shared.stores 1.0
|
2021-10-21 15:07:13 +00:00
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
2022-03-18 14:47:51 +00:00
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2021-10-21 15:07:13 +00:00
|
|
|
|
2021-10-14 09:20:18 +00:00
|
|
|
import "../panels"
|
2021-10-14 10:12:22 +00:00
|
|
|
import "../controls"
|
2021-10-14 13:45:08 +00:00
|
|
|
import "../views"
|
2020-05-27 20:50:39 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
StatusModal {
|
|
|
|
id: popup
|
2022-01-04 12:06:05 +00:00
|
|
|
|
2020-10-28 07:44:09 +00:00
|
|
|
property alias stack: stack
|
2020-06-26 16:08:51 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
property var store
|
|
|
|
property var contactsStore
|
|
|
|
property var preSelectedAccount
|
|
|
|
property var preSelectedRecipient
|
|
|
|
property bool launchedFromChat: false
|
2020-08-20 04:45:29 +00:00
|
|
|
property MessageDialog sendingError: MessageDialog {
|
|
|
|
id: sendingError
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "Error sending the transaction"
|
|
|
|
title: qsTrId("error-sending-the-transaction")
|
2020-08-20 04:45:29 +00:00
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
2020-05-27 20:50:39 +00:00
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
|
|
|
|
function sendTransaction() {
|
2022-02-01 21:03:47 +00:00
|
|
|
stack.currentGroup.isPending = true
|
|
|
|
let success = false
|
2022-05-19 08:53:57 +00:00
|
|
|
success = popup.store.transfer(
|
|
|
|
advancedHeader.accountSelector.selectedAccount.address,
|
|
|
|
advancedHeader.recipientSelector.selectedRecipient.address,
|
|
|
|
advancedHeader.assetSelector.selectedAsset.symbol,
|
|
|
|
advancedHeader.amountToSendInput.text,
|
|
|
|
gasSelector.selectedGasLimit,
|
|
|
|
gasSelector.suggestedFees.eip1559Enabled ? "" : gasSelector.selectedGasPrice,
|
|
|
|
gasSelector.selectedTipLimit,
|
|
|
|
gasSelector.selectedOverallLimit,
|
|
|
|
transactionSigner.enteredPassword,
|
|
|
|
networkSelector.selectedNetwork.chainId || Global.currentChainId,
|
|
|
|
stack.uuid,
|
|
|
|
gasSelector.suggestedFees.eip1559Enabled,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
property var recalculateRoutesAndFees: Backpressure.debounce(popup, 600, function() {
|
|
|
|
if (!popup.store.isMultiNetworkEnabled) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
networkSelector.suggestedRoutes = popup.store.suggestedRoutes(
|
|
|
|
advancedHeader.accountSelector.selectedAccount.address, advancedHeader.amountToSendInput.text, advancedHeader.assetSelector.selectedAsset.symbol
|
|
|
|
)
|
|
|
|
if (networkSelector.suggestedRoutes.length) {
|
|
|
|
networkSelector.selectedNetwork = networkSelector.suggestedRoutes[0]
|
|
|
|
gasSelector.suggestedFees = popup.store.suggestedFees(networkSelector.suggestedRoutes[0].chainId)
|
|
|
|
gasSelector.checkOptimal()
|
|
|
|
gasSelector.visible = true
|
2022-02-01 21:03:47 +00:00
|
|
|
} else {
|
2022-05-19 08:53:57 +00:00
|
|
|
networkSelector.selectedNetwork = ""
|
|
|
|
gasSelector.visible = false
|
2022-02-01 21:03:47 +00:00
|
|
|
}
|
2022-05-19 08:53:57 +00:00
|
|
|
})
|
2022-03-18 14:47:51 +00:00
|
|
|
|
|
|
|
width: 556
|
|
|
|
// To-Do as per design once the account selector become floating the heigth can be as defined in design as 595
|
|
|
|
height: 670
|
|
|
|
showHeader: false
|
|
|
|
showFooter: false
|
|
|
|
showAdvancedFooter: !!popup.advancedHeader ? popup.advancedHeader.isReady && gasValidator.isValid : false
|
|
|
|
showAdvancedHeader: true
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
if(!!advancedHeader) {
|
|
|
|
advancedHeader.amountToSendInput.input.edit.forceActiveFocus()
|
2021-06-29 13:25:05 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
if(popup.launchedFromChat) {
|
|
|
|
advancedHeader.recipientSelector.selectedType = RecipientSelector.Type.Contact
|
|
|
|
advancedHeader.recipientSelector.readOnly = true
|
|
|
|
advancedHeader.recipientSelector.selectedRecipient = popup.preSelectedRecipient
|
2022-05-19 08:53:57 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
}
|
|
|
|
if(popup.preSelectedAccount) {
|
|
|
|
advancedHeader.accountSelector.selectedAccount = popup.preSelectedAccount
|
|
|
|
}
|
|
|
|
}
|
2022-05-19 08:53:57 +00:00
|
|
|
|
|
|
|
if (popup.store.isMultiNetworkEnabled) {
|
|
|
|
popup.recalculateRoutesAndFees()
|
|
|
|
} else {
|
|
|
|
gasSelector.suggestedFees = popup.store.suggestedFees(Global.currentChainId)
|
|
|
|
gasSelector.checkOptimal()
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 08:53:57 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
advancedHeaderComponent: SendModalHeader {
|
|
|
|
store: popup.store
|
|
|
|
contactsStore: popup.contactsStore
|
|
|
|
estimateGas: function() {
|
|
|
|
if(popup.contentItem.currentGroup.isValid)
|
|
|
|
gasSelector.estimateGas()
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2022-05-19 08:53:57 +00:00
|
|
|
|
|
|
|
onAssetChanged: function() {
|
|
|
|
popup.recalculateRoutesAndFees()
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedAccountChanged: function() {
|
|
|
|
popup.recalculateRoutesAndFees()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAmountToSendChanged: function() {
|
|
|
|
popup.recalculateRoutesAndFees()
|
|
|
|
}
|
2022-03-18 14:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: TransactionStackView {
|
|
|
|
id: stack
|
|
|
|
property alias currentGroup: stack.currentGroup
|
|
|
|
anchors.leftMargin: Style.current.xlPadding
|
|
|
|
anchors.topMargin: (!!advancedHeader ? advancedHeader.height: 0) + Style.current.smallPadding
|
|
|
|
anchors.rightMargin: Style.current.xlPadding
|
|
|
|
anchors.bottomMargin: popup.showAdvancedFooter && !!advancedFooter ? advancedFooter.height : Style.current.padding
|
2020-08-20 04:45:29 +00:00
|
|
|
TransactionFormGroup {
|
|
|
|
id: group1
|
2022-03-18 14:47:51 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
ScrollView {
|
|
|
|
height: stack.height
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
|
|
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
2022-05-19 08:53:57 +00:00
|
|
|
contentHeight: addressSelector.height + networkSelector.height + gasSelector.height + gasValidator.height
|
2022-03-18 14:47:51 +00:00
|
|
|
clip: true
|
|
|
|
|
|
|
|
TabAddressSelectorView {
|
|
|
|
id: addressSelector
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
store: popup.store
|
|
|
|
onContactSelected: {
|
|
|
|
if(!!popup.advancedHeader)
|
|
|
|
advancedHeader.recipientSelector.input.text = address
|
2021-04-22 04:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 21:20:43 +00:00
|
|
|
|
2022-05-19 08:53:57 +00:00
|
|
|
NetworkSelector {
|
|
|
|
id: networkSelector
|
2022-03-18 14:47:51 +00:00
|
|
|
anchors.top: addressSelector.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
visible: popup.store.isMultiNetworkEnabled
|
2022-05-19 08:53:57 +00:00
|
|
|
onNetworkChanged: function(chainId) {
|
|
|
|
gasSelector.suggestedFees = popup.store.suggestedFees(chainId)
|
|
|
|
}
|
2022-03-18 14:47:51 +00:00
|
|
|
}
|
2021-12-08 21:20:43 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
GasSelector {
|
|
|
|
id: gasSelector
|
2022-05-19 08:53:57 +00:00
|
|
|
anchors.top: networkSelector.bottom
|
2022-03-18 14:47:51 +00:00
|
|
|
getGasEthValue: popup.store.getGasEthValue
|
|
|
|
getFiatValue: popup.store.getFiatValue
|
|
|
|
defaultCurrency: popup.store.currentCurrency
|
|
|
|
|
|
|
|
width: stack.width
|
|
|
|
property var estimateGas: Backpressure.debounce(gasSelector, 600, function() {
|
|
|
|
if (!(advancedHeader.accountSelector.selectedAccount && advancedHeader.accountSelector.selectedAccount.address &&
|
2022-05-19 08:53:57 +00:00
|
|
|
advancedHeader.recipientSelector.selectedRecipient && advancedHeader.recipientSelector.selectedRecipient.address &&
|
|
|
|
advancedHeader.assetSelector.selectedAsset && advancedHeader.assetSelector.selectedAsset.symbol &&
|
|
|
|
advancedHeader.amountToSendInput.text)) {
|
2022-03-18 14:47:51 +00:00
|
|
|
selectedGasLimit = 250000
|
|
|
|
defaultGasLimit = selectedGasLimit
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let gasEstimate = JSON.parse(popup.store.estimateGas(
|
2022-05-19 08:53:57 +00:00
|
|
|
advancedHeader.accountSelector.selectedAccount.address,
|
|
|
|
advancedHeader.recipientSelector.selectedRecipient.address,
|
|
|
|
advancedHeader.assetSelector.selectedAsset.symbol,
|
|
|
|
advancedHeader.amountToSendInput.text,
|
|
|
|
networkSelector.selectedNetwork.chainId || Global.currentChainId,
|
|
|
|
""))
|
2022-03-18 14:47:51 +00:00
|
|
|
|
|
|
|
if (!gasEstimate.success) {
|
2022-05-19 08:53:57 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
//% "Error estimating gas: %1"
|
|
|
|
console.warn(qsTrId("error-estimating-gas---1").arg(gasEstimate.error.message))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedGasLimit = gasEstimate.result
|
|
|
|
defaultGasLimit = selectedGasLimit
|
|
|
|
})
|
|
|
|
}
|
2022-05-19 08:53:57 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
GasValidator {
|
|
|
|
id: gasValidator
|
|
|
|
anchors.top: gasSelector.bottom
|
|
|
|
selectedAccount: advancedHeader.accountSelector.selectedAccount
|
2022-04-13 07:41:23 +00:00
|
|
|
selectedAmount: advancedHeader.amountToSendInput.text === "" ? 0.0
|
|
|
|
: parseFloat(advancedHeader.amountToSendInput.text)
|
2022-03-18 14:47:51 +00:00
|
|
|
selectedAsset: advancedHeader.assetSelector.selectedAsset
|
|
|
|
selectedGasEthValue: gasSelector.selectedGasEthValue
|
2022-05-19 08:53:57 +00:00
|
|
|
selectedNetwork: networkSelector.selectedNetwork
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2020-10-19 09:39:07 +00:00
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
TransactionFormGroup {
|
|
|
|
id: group4
|
2022-03-18 14:47:51 +00:00
|
|
|
|
|
|
|
StackView.onActivated: {
|
|
|
|
transactionSigner.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
2020-05-27 20:50:39 +00:00
|
|
|
|
2020-08-20 04:45:29 +00:00
|
|
|
TransactionSigner {
|
|
|
|
id: transactionSigner
|
2022-03-18 14:47:51 +00:00
|
|
|
Layout.topMargin: Style.current.smallPadding
|
2020-08-20 04:45:29 +00:00
|
|
|
width: stack.width
|
2022-03-18 14:47:51 +00:00
|
|
|
signingPhrase: popup.store.signingPhrase
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2020-07-01 14:24:07 +00:00
|
|
|
}
|
2020-05-27 20:50:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
advancedFooterComponent: SendModalFooter {
|
|
|
|
maxFiatFees: gasSelector.maxFiatFees
|
|
|
|
currentGroupPending: popup.contentItem.currentGroup.isPending
|
|
|
|
currentGroupValid: popup.contentItem.currentGroup.isValid
|
|
|
|
isLastGroup: popup.contentItem.isLastGroup
|
|
|
|
onNextButtonClicked: {
|
|
|
|
const validity = popup.contentItem.currentGroup.validate()
|
|
|
|
if (validity.isValid && !validity.isPending) {
|
|
|
|
if (popup.contentItem.isLastGroup) {
|
|
|
|
return popup.sendTransaction()
|
|
|
|
}
|
2021-07-05 12:34:56 +00:00
|
|
|
|
2022-05-19 08:53:57 +00:00
|
|
|
if(gasSelector.suggestedFees.eip1559Enabled && popup.contentItem.currentGroup === group1 && gasSelector.advancedMode){
|
2022-03-18 14:47:51 +00:00
|
|
|
if(gasSelector.showPriceLimitWarning || gasSelector.showTipLimitWarning){
|
|
|
|
Global.openPopup(transactionSettingsConfirmationPopupComponent, {
|
2022-03-23 08:32:25 +00:00
|
|
|
currentBaseFee: gasSelector.suggestedFees.baseFee,
|
2022-03-18 14:47:51 +00:00
|
|
|
currentMinimumTip: gasSelector.perGasTipLimitFloor,
|
|
|
|
currentAverageTip: gasSelector.perGasTipLimitAverage,
|
|
|
|
tipLimit: gasSelector.selectedTipLimit,
|
|
|
|
suggestedTipLimit: gasSelector.perGasTipLimitFloor,
|
|
|
|
priceLimit: gasSelector.selectedOverallLimit,
|
2022-03-23 08:32:25 +00:00
|
|
|
suggestedPriceLimit: gasSelector.suggestedFees.baseFee + gasSelector.perGasTipLimitFloor,
|
2022-03-18 14:47:51 +00:00
|
|
|
showPriceLimitWarning: gasSelector.showPriceLimitWarning,
|
|
|
|
showTipLimitWarning: gasSelector.showTipLimitWarning,
|
|
|
|
onConfirm: function(){
|
|
|
|
popup.contentItem.next();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-12-08 21:20:43 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
popup.contentItem.next()
|
2021-07-05 12:34:56 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-18 14:47:51 +00:00
|
|
|
}
|
2021-07-05 12:34:56 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
Component {
|
|
|
|
id: transactionSettingsConfirmationPopupComponent
|
|
|
|
TransactionSettingsConfirmationPopup {}
|
|
|
|
}
|
2021-07-05 12:34:56 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
Connections {
|
|
|
|
target: advancedHeader
|
|
|
|
onIsReadyChanged: {
|
|
|
|
if(!advancedHeader.isReady && popup.contentItem.isLastGroup)
|
|
|
|
popup.contentItem.back()
|
2021-07-05 12:34:56 +00:00
|
|
|
|
2020-09-10 18:55:24 +00:00
|
|
|
}
|
2022-03-18 14:47:51 +00:00
|
|
|
}
|
2020-09-14 14:58:21 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
Connections {
|
|
|
|
target: popup.store.walletSectionTransactionsInst
|
|
|
|
onTransactionSent: {
|
|
|
|
try {
|
|
|
|
let response = JSON.parse(txResult)
|
|
|
|
if (response.uuid !== stack.uuid) return
|
|
|
|
|
|
|
|
stack.currentGroup.isPending = false
|
2021-12-08 21:20:43 +00:00
|
|
|
|
2022-03-18 14:47:51 +00:00
|
|
|
if (!response.success) {
|
|
|
|
if (Utils.isInvalidPasswordMessage(response.result)){
|
|
|
|
//% "Wrong password"
|
|
|
|
transactionSigner.validationError = qsTrId("wrong-password")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sendingError.text = response.result
|
|
|
|
return sendingError.open()
|
2022-02-24 19:24:58 +00:00
|
|
|
}
|
2022-03-18 14:47:51 +00:00
|
|
|
|
2022-05-05 10:28:54 +00:00
|
|
|
let url = `${popup.store.getEtherscanLink()}/${response.result}`
|
|
|
|
Global.displayToastMessage(qsTr("Transaction pending..."),
|
2022-05-19 08:53:57 +00:00
|
|
|
qsTr("View on etherscan"),
|
2022-05-05 10:28:54 +00:00
|
|
|
"",
|
|
|
|
true,
|
|
|
|
Constants.ephemeralNotificationType.normal,
|
|
|
|
url)
|
2022-03-18 14:47:51 +00:00
|
|
|
popup.close()
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing the response', e)
|
2022-02-24 19:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-18 14:47:51 +00:00
|
|
|
// Not Refactored Yet
|
|
|
|
// onTransactionCompleted: {
|
|
|
|
// if (success) {
|
|
|
|
// //% "Transaction completed"
|
|
|
|
// Global.toastMessage.title = qsTrId("transaction-completed")
|
|
|
|
// Global.toastMessage.source = Style.svg("check-circle")
|
|
|
|
// Global.toastMessage.iconColor = Style.current.success
|
|
|
|
// } else {
|
|
|
|
// //% "Transaction failed"
|
|
|
|
// Global.toastMessage.title = qsTrId("ens-registration-failed-title")
|
|
|
|
// Global.toastMessage.source = Style.svg("block-icon")
|
|
|
|
// Global.toastMessage.iconColor = Style.current.danger
|
|
|
|
// }
|
|
|
|
// Global.toastMessage.link = `${walletModel.utilsView.etherscanLink}/${txHash}`
|
|
|
|
// Global.toastMessage.open()
|
|
|
|
// }
|
2020-05-27 20:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|