2020-08-13 07:27:53 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import "../imports"
|
|
|
|
import "./"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
height: sliderWrapper.height + Style.current.smallPadding + txtNetworkFee.height + buttonAdvanced.height
|
2020-08-18 11:38:16 +00:00
|
|
|
property string validationError: "Please enter a number"
|
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
|
|
|
|
|
|
|
|
function defaultGasPrice() {
|
|
|
|
return ((50 * (root.fastestGasPrice - root.slowestGasPrice) / 100) + root.slowestGasPrice)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-08-13 08:24:51 +00:00
|
|
|
let summary = Utils.stripTrailingZeros(ethValue) + " ETH ~" + fiatValue + " " + root.defaultCurrency.toUpperCase()
|
2020-08-13 07:27:53 +00:00
|
|
|
labelGasPriceSummary.text = summary
|
|
|
|
labelGasPriceSummaryAdvanced.text = summary
|
|
|
|
}
|
|
|
|
|
2020-08-18 11:38:16 +00:00
|
|
|
function validate(value) {
|
|
|
|
return !isNaN(value)
|
|
|
|
}
|
|
|
|
|
2020-08-13 07:27:53 +00:00
|
|
|
StyledText {
|
|
|
|
id: txtNetworkFee
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Network fee"
|
|
|
|
text: qsTrId("network-fee")
|
2020-08-13 07:27:53 +00:00
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.textColor
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: labelGasPriceSummary
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: sliderWrapper
|
|
|
|
anchors.topMargin: Style.current.smallPadding
|
|
|
|
anchors.top: labelGasPriceSummary.bottom
|
|
|
|
height: sliderWrapper.visible ? gasSlider.height + labelSlow.height + Style.current.padding : 0
|
|
|
|
width: parent.width
|
|
|
|
visible: Number(root.selectedGasPrice) >= Number(root.slowestGasPrice) && Number(root.selectedGasPrice) <= Number(root.fastestGasPrice)
|
|
|
|
|
|
|
|
StatusSlider {
|
|
|
|
id: gasSlider
|
|
|
|
minimumValue: root.slowestGasPrice
|
|
|
|
maximumValue: root.fastestGasPrice
|
|
|
|
stepSize: root.stepSize
|
|
|
|
value: root.defaultGasPrice()
|
|
|
|
onValueChanged: {
|
|
|
|
if (!isNaN(gasSlider.value)) {
|
|
|
|
inputGasPrice.text = gasSlider.value + ""
|
|
|
|
root.updateGasEthValue()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
visible: parent.visible
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: labelSlow
|
|
|
|
anchors.top: gasSlider.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
anchors.left: parent.left
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Slow"
|
|
|
|
text: qsTrId("slow")
|
2020-08-13 07:27:53 +00:00
|
|
|
font.pixelSize: 15
|
|
|
|
color: Style.current.textColor
|
|
|
|
visible: parent.visible
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: labelOptimal
|
|
|
|
anchors.top: gasSlider.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
anchors.horizontalCenter: gasSlider.horizontalCenter
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Optimal"
|
|
|
|
text: qsTrId("optimal")
|
2020-08-13 07:27:53 +00:00
|
|
|
font.pixelSize: 15
|
|
|
|
color: Style.current.textColor
|
|
|
|
visible: parent.visible
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: labelFast
|
|
|
|
anchors.top: gasSlider.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
anchors.right: parent.right
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Fast"
|
|
|
|
text: qsTrId("fast")
|
2020-08-13 07:27:53 +00:00
|
|
|
font.pixelSize: 15
|
|
|
|
color: Style.current.textColor
|
|
|
|
visible: parent.visible
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledButton {
|
|
|
|
id: buttonReset
|
|
|
|
anchors.top: sliderWrapper.bottom
|
|
|
|
anchors.topMargin: sliderWrapper.visible ? Style.current.smallPadding : 0
|
|
|
|
anchors.right: buttonAdvanced.left
|
|
|
|
anchors.rightMargin: -Style.current.padding
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Reset"
|
|
|
|
label: qsTrId("reset")
|
2020-08-13 07:27:53 +00:00
|
|
|
btnColor: "transparent"
|
|
|
|
textSize: 13
|
|
|
|
visible: !sliderWrapper.visible
|
|
|
|
onClicked: {
|
|
|
|
gasSlider.value = root.defaultGasPrice()
|
|
|
|
inputGasPrice.text = root.defaultGasPrice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledButton {
|
|
|
|
id: buttonAdvanced
|
|
|
|
anchors.top: sliderWrapper.bottom
|
|
|
|
anchors.topMargin: sliderWrapper.visible ? Style.current.smallPadding : 0
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: -Style.current.padding
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Advanced"
|
|
|
|
label: qsTrId("advanced")
|
2020-08-13 07:27:53 +00:00
|
|
|
btnColor: "transparent"
|
|
|
|
textSize: 13
|
|
|
|
onClicked: {
|
|
|
|
customNetworkFeeDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModalPopup {
|
|
|
|
id: customNetworkFeeDialog
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Custom Network Fee"
|
|
|
|
title: qsTrId("custom-network-fee")
|
2020-08-18 11:38:16 +00:00
|
|
|
height: 286
|
|
|
|
width: 400
|
2020-08-13 07:27:53 +00:00
|
|
|
|
|
|
|
Input {
|
|
|
|
id: inputGasLimit
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Gas limit"
|
|
|
|
label: qsTrId("gas-limit")
|
2020-08-13 07:27:53 +00:00
|
|
|
text: "22000"
|
|
|
|
customHeight: 56
|
|
|
|
anchors.top: parent.top
|
2020-08-18 11:38:16 +00:00
|
|
|
anchors.left: parent.left
|
2020-08-19 13:36:56 +00:00
|
|
|
anchors.right: inputGasPrice.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-08-13 07:27:53 +00:00
|
|
|
onTextChanged: {
|
2020-08-18 11:38:16 +00:00
|
|
|
if (root.validate(inputGasLimit.text.trim())) {
|
|
|
|
inputGasLimit.validationError = ""
|
|
|
|
root.updateGasEthValue()
|
|
|
|
return
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
2020-08-18 11:38:16 +00:00
|
|
|
inputGasLimit.validationError = root.validationError
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: inputGasPrice
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Gas price"
|
|
|
|
label: qsTrId("gas-price")
|
2020-08-18 11:38:16 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: undefined
|
|
|
|
anchors.right: parent.right
|
|
|
|
width: 130
|
2020-08-13 07:27:53 +00:00
|
|
|
customHeight: 56
|
|
|
|
text: root.defaultGasPrice()
|
|
|
|
onTextChanged: {
|
2020-08-18 11:38:16 +00:00
|
|
|
if (root.validate(inputGasPrice.text.trim())) {
|
|
|
|
inputGasPrice.validationError = ""
|
|
|
|
root.updateGasEthValue()
|
|
|
|
return
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
2020-08-18 11:38:16 +00:00
|
|
|
inputGasPrice.validationError = root.validationError
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
color: Style.current.darkGrey
|
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
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: labelGasPriceSummaryAdvanced
|
2020-08-18 11:38:16 +00:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: Style.current.smallPadding
|
2020-08-13 07:27:53 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
|
|
|
|
footer: StyledButton {
|
|
|
|
id: applyButton
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Apply"
|
|
|
|
label: qsTrId("invalid-key-confirm")
|
2020-08-18 11:38:16 +00:00
|
|
|
disabled: !root.validate(inputGasLimit.text.trim()) || !root.validate(inputGasPrice.text.trim())
|
2020-08-13 07:27:53 +00:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: {
|
2020-08-18 11:38:16 +00:00
|
|
|
root.updateGasEthValue()
|
|
|
|
customNetworkFeeDialog.close()
|
2020-08-13 07:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|