2020-08-13 07:27:53 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import "../imports"
|
2020-09-17 15:04:38 +00:00
|
|
|
import "./status"
|
2020-08-13 07:27:53 +00:00
|
|
|
import "./"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2021-05-21 20:19:03 +00:00
|
|
|
width: parent.width
|
|
|
|
height: Style.current.smallPadding + prioritytext.height +
|
|
|
|
(advancedMode ? advancedModeItemGroup.height : selectorButtons.height)
|
|
|
|
|
2020-08-13 07:27:53 +00:00
|
|
|
property double slowestGasPrice: 0
|
|
|
|
property double fastestGasPrice: 100
|
|
|
|
property double stepSize: ((root.fastestGasPrice - root.slowestGasPrice) / 10).toFixed(1)
|
|
|
|
property var getGasEthValue: function () {}
|
|
|
|
property var getFiatValue: function () {}
|
|
|
|
property string defaultCurrency: "USD"
|
|
|
|
property alias selectedGasPrice: inputGasPrice.text
|
|
|
|
property alias selectedGasLimit: inputGasLimit.text
|
2020-09-01 03:49:05 +00:00
|
|
|
property double selectedGasEthValue
|
|
|
|
property double selectedGasFiatValue
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "Must be greater than 0"
|
|
|
|
property string greaterThan0ErrorMessage: qsTrId("must-be-greater-than-0")
|
2020-08-20 04:45:29 +00:00
|
|
|
//% "This needs to be a number"
|
|
|
|
property string invalidInputErrorMessage: qsTrId("this-needs-to-be-a-number")
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "Please enter an amount"
|
|
|
|
property string noInputErrorMessage: qsTrId("please-enter-an-amount")
|
2020-08-20 04:45:29 +00:00
|
|
|
property bool isValid: true
|
2020-12-14 05:50:47 +00:00
|
|
|
readonly property string uuid: Utils.uuid()
|
2020-08-13 07:27:53 +00:00
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
property bool advancedMode: false
|
|
|
|
|
2020-08-13 07:27:53 +00:00
|
|
|
function updateGasEthValue() {
|
2020-08-13 08:24:51 +00:00
|
|
|
// causes error on application load without this null check
|
|
|
|
if (!inputGasPrice || !inputGasLimit) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-13 07:27:53 +00:00
|
|
|
let ethValue = root.getGasEthValue(inputGasPrice.text, inputGasLimit.text)
|
|
|
|
let fiatValue = root.getFiatValue(ethValue, "ETH", root.defaultCurrency)
|
2021-05-21 20:19:03 +00:00
|
|
|
|
2020-09-01 03:49:05 +00:00
|
|
|
selectedGasEthValue = ethValue
|
|
|
|
selectedGasFiatValue = fiatValue
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 14:58:53 +00:00
|
|
|
Component.onCompleted: updateGasEthValue()
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
function validate() {
|
|
|
|
// causes error on application load without a null check
|
|
|
|
if (!inputGasLimit || !inputGasPrice) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
inputGasLimit.validationError = ""
|
|
|
|
inputGasPrice.validationError = ""
|
|
|
|
const noInputLimit = inputGasLimit.text === ""
|
|
|
|
const noInputPrice = inputGasPrice.text === ""
|
|
|
|
if (noInputLimit) {
|
|
|
|
inputGasLimit.validationError = root.noInputErrorMessage
|
|
|
|
}
|
|
|
|
if (noInputPrice) {
|
|
|
|
inputGasPrice.validationError = root.noInputErrorMessage
|
|
|
|
}
|
|
|
|
if (isNaN(inputGasLimit.text)) {
|
|
|
|
inputGasLimit.validationError = invalidInputErrorMessage
|
|
|
|
}
|
|
|
|
if (isNaN(inputGasPrice.text)) {
|
|
|
|
inputGasPrice.validationError = invalidInputErrorMessage
|
|
|
|
}
|
|
|
|
let inputLimit = parseFloat(inputGasLimit.text || "0.00")
|
|
|
|
let inputPrice = parseFloat(inputGasPrice.text || "0.00")
|
2021-07-05 10:59:50 +00:00
|
|
|
if (inputLimit <= 0) {
|
2021-05-21 20:19:03 +00:00
|
|
|
inputGasLimit.validationError = root.greaterThan0ErrorMessage
|
|
|
|
}
|
2021-07-05 10:59:50 +00:00
|
|
|
if (inputPrice <= 0) {
|
2021-05-21 20:19:03 +00:00
|
|
|
inputGasPrice.validationError = root.greaterThan0ErrorMessage
|
|
|
|
}
|
|
|
|
const isValid = inputGasLimit.validationError === "" && inputGasPrice.validationError === ""
|
|
|
|
return isValid
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-13 07:27:53 +00:00
|
|
|
StyledText {
|
2021-05-21 20:19:03 +00:00
|
|
|
id: prioritytext
|
2020-08-13 07:27:53 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Priority"
|
|
|
|
text: qsTrId("priority")
|
2020-08-13 07:27:53 +00:00
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.textColor
|
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
StatusButton {
|
|
|
|
id: buttonAdvanced
|
|
|
|
anchors.verticalCenter: prioritytext.verticalCenter
|
2020-08-13 07:27:53 +00:00
|
|
|
anchors.right: parent.right
|
2021-07-19 21:57:57 +00:00
|
|
|
text: advancedMode ?
|
|
|
|
//% "Use suggestions"
|
|
|
|
qsTrId("use-suggestions") :
|
|
|
|
//% "Use custom"
|
|
|
|
qsTrId("use-custom")
|
2021-05-21 20:19:03 +00:00
|
|
|
flat: true
|
2020-08-13 07:27:53 +00:00
|
|
|
font.pixelSize: 13
|
2021-05-21 20:19:03 +00:00
|
|
|
onClicked: advancedMode = !advancedMode
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
Row {
|
|
|
|
id: selectorButtons
|
|
|
|
visible: !advancedMode
|
|
|
|
anchors.top: prioritytext.bottom
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
spacing: 11
|
2020-08-13 07:27:53 +00:00
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
ButtonGroup {
|
|
|
|
id: gasGroup
|
|
|
|
onClicked: updateGasEthValue()
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
GasSelectorButton {
|
|
|
|
buttonGroup: gasGroup
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Low"
|
|
|
|
text: qsTrId("low")
|
2021-05-21 20:19:03 +00:00
|
|
|
price: slowestGasPrice
|
|
|
|
gasLimit: inputGasLimit ? inputGasLimit.text : ""
|
|
|
|
getGasEthValue: root.getGasEthValue
|
|
|
|
getFiatValue: root.getFiatValue
|
|
|
|
defaultCurrency: root.defaultCurrency
|
|
|
|
onChecked: inputGasPrice.text = price
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
2021-05-21 20:19:03 +00:00
|
|
|
GasSelectorButton {
|
2021-05-25 14:58:53 +00:00
|
|
|
id: optimalGasButton
|
2021-05-21 20:19:03 +00:00
|
|
|
buttonGroup: gasGroup
|
|
|
|
checkedByDefault: true
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Optimal"
|
|
|
|
text: qsTrId("optimal")
|
2021-06-22 17:17:37 +00:00
|
|
|
price: {
|
|
|
|
const price = (fastestGasPrice + slowestGasPrice) / 2
|
|
|
|
// Setting the gas price field here because the binding didn't work
|
|
|
|
inputGasPrice.text = price
|
|
|
|
return price
|
|
|
|
}
|
2021-05-21 20:19:03 +00:00
|
|
|
gasLimit: inputGasLimit ? inputGasLimit.text : ""
|
|
|
|
getGasEthValue: root.getGasEthValue
|
|
|
|
getFiatValue: root.getFiatValue
|
|
|
|
defaultCurrency: root.defaultCurrency
|
|
|
|
onChecked: inputGasPrice.text = price
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
GasSelectorButton {
|
|
|
|
buttonGroup: gasGroup
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "High"
|
|
|
|
text: qsTrId("high")
|
2021-05-21 20:19:03 +00:00
|
|
|
price: fastestGasPrice
|
|
|
|
gasLimit: inputGasLimit ? inputGasLimit.text : ""
|
|
|
|
getGasEthValue: root.getGasEthValue
|
|
|
|
getFiatValue: root.getFiatValue
|
|
|
|
defaultCurrency: root.defaultCurrency
|
|
|
|
onChecked: inputGasPrice.text = price
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
Item {
|
|
|
|
id: advancedModeItemGroup
|
|
|
|
anchors.top: prioritytext.bottom
|
|
|
|
anchors.topMargin: 14
|
|
|
|
visible: root.advancedMode
|
|
|
|
width: parent.width
|
|
|
|
height: childrenRect.height
|
2020-08-20 04:45:29 +00:00
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
Input {
|
|
|
|
id: inputGasLimit
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Gas amount limit"
|
|
|
|
label: qsTrId("gas-amount-limit")
|
2021-05-21 20:19:03 +00:00
|
|
|
text: "21000"
|
|
|
|
customHeight: 56
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: inputGasPrice.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
placeholderText: "21000"
|
|
|
|
validationErrorAlignment: TextEdit.AlignRight
|
|
|
|
validationErrorTopMargin: 8
|
|
|
|
onTextChanged: {
|
|
|
|
if (root.validate()) {
|
|
|
|
root.updateGasEthValue()
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-13 07:27:53 +00:00
|
|
|
|
|
|
|
Input {
|
2021-05-21 20:19:03 +00:00
|
|
|
id: inputGasPrice
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Per-gas overall limit"
|
|
|
|
label: qsTrId("per-gas-overall-limit")
|
2021-05-21 20:19:03 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: undefined
|
|
|
|
anchors.right: parent.right
|
|
|
|
width: 130
|
|
|
|
customHeight: 56
|
|
|
|
placeholderText: "20"
|
|
|
|
onTextChanged: {
|
|
|
|
if (root.validate()) {
|
|
|
|
root.updateGasEthValue()
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
StyledText {
|
|
|
|
color: Style.current.secondaryText
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Gwei"
|
|
|
|
text: qsTrId("gwei")
|
2020-08-13 07:27:53 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 42
|
2021-05-21 20:19:03 +00:00
|
|
|
anchors.right: inputGasPrice.right
|
2020-08-13 07:27:53 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
2021-05-21 20:19:03 +00:00
|
|
|
id: maxPriorityFeeText
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Maximum priority fee: %1 ETH"
|
|
|
|
text: qsTrId("maximum-priority-fee---1-eth").arg(selectedGasEthValue)
|
2021-05-21 20:19:03 +00:00
|
|
|
anchors.top: inputGasLimit.bottom
|
|
|
|
anchors.topMargin: 19
|
2020-08-13 07:27:53 +00:00
|
|
|
font.pixelSize: 13
|
2021-05-21 20:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: maxPriorityFeeFiatText
|
|
|
|
text: `${selectedGasFiatValue} ${root.defaultCurrency}`
|
|
|
|
anchors.verticalCenter: maxPriorityFeeText.verticalCenter
|
|
|
|
anchors.left: maxPriorityFeeText.right
|
|
|
|
anchors.leftMargin: 6
|
2020-08-13 07:27:53 +00:00
|
|
|
color: Style.current.secondaryText
|
2021-05-21 20:19:03 +00:00
|
|
|
anchors.topMargin: 19
|
|
|
|
font.pixelSize: 13
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
StyledText {
|
|
|
|
id: maxPriorityFeeDetailsText
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Maximum overall price for the transaction. If the block base fee exceeds this, it will be included in a following block with a lower base fee."
|
|
|
|
text: qsTrId("maximum-overall-price-for-the-transaction--if-the-block-base-fee-exceeds-this--it-will-be-included-in-a-following-block-with-a-lower-base-fee-")
|
2021-05-21 20:19:03 +00:00
|
|
|
width: parent.width
|
|
|
|
anchors.top: maxPriorityFeeText.bottom
|
|
|
|
anchors.topMargin: Style.current.smallPadding
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
wrapMode: Text.WordWrap
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|