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
|
|
|
|
text: qsTr("Network fee")
|
|
|
|
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
|
|
|
|
text: qsTr("Slow")
|
|
|
|
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
|
|
|
|
text: qsTr("Optimal")
|
|
|
|
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
|
|
|
|
text: qsTr("Fast")
|
|
|
|
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
|
|
|
|
label: qsTr("Reset")
|
|
|
|
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
|
|
|
|
label: qsTr("Advanced")
|
|
|
|
btnColor: "transparent"
|
|
|
|
textSize: 13
|
|
|
|
onClicked: {
|
|
|
|
customNetworkFeeDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModalPopup {
|
|
|
|
id: customNetworkFeeDialog
|
|
|
|
title: qsTr("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
|
|
|
|
label: qsTr("Gas limit")
|
|
|
|
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
|
|
|
|
label: qsTr("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
|
|
|
|
text: qsTr("Gwei")
|
|
|
|
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
|
|
|
|
label: qsTr("Apply")
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|