2021-05-21 20:19:03 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-25 12:30:23 +00:00
|
|
|
|
2021-10-14 10:39:59 +00:00
|
|
|
import "../"
|
2021-10-14 13:09:35 +00:00
|
|
|
import "../panels"
|
2021-05-21 20:19:03 +00:00
|
|
|
|
2021-10-25 12:30:23 +00:00
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
2021-10-14 10:39:59 +00:00
|
|
|
// TODO: use StatusQ components
|
2021-05-21 20:19:03 +00:00
|
|
|
Rectangle {
|
|
|
|
property var buttonGroup
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Low"
|
|
|
|
property string text: qsTrId("low")
|
2021-05-21 20:19:03 +00:00
|
|
|
property string gasLimit
|
|
|
|
property double price: 1
|
|
|
|
property string defaultCurrency: "USD"
|
|
|
|
property bool hovered: false
|
|
|
|
property bool checkedByDefault: false
|
|
|
|
property var getGasEthValue: function () {}
|
|
|
|
property var getFiatValue: function () {}
|
2021-07-05 12:34:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
function formatDec(num, dec){
|
|
|
|
return Math.round((num + Number.EPSILON) * Math.pow(10, dec)) / Math.pow(10, dec)
|
|
|
|
}
|
|
|
|
|
2021-05-21 20:19:03 +00:00
|
|
|
property double ethValue: {
|
|
|
|
if (!gasLimit) {
|
|
|
|
return 0
|
|
|
|
}
|
2021-07-05 12:34:56 +00:00
|
|
|
return formatDec(parseFloat(getGasEthValue(price, gasLimit)), 6)
|
2021-05-21 20:19:03 +00:00
|
|
|
}
|
|
|
|
property double fiatValue: getFiatValue(ethValue, "ETH", defaultCurrency)
|
|
|
|
signal checked()
|
|
|
|
|
|
|
|
id: gasRectangle
|
|
|
|
border.color: hovered || gasRadioBtn.checked ? Style.current.primary : Style.current.border
|
|
|
|
border.width: 1
|
|
|
|
color: Style.current.transparent
|
|
|
|
width: 130
|
|
|
|
height: 120
|
|
|
|
clip: true
|
|
|
|
radius: Style.current.radius
|
|
|
|
|
|
|
|
StatusRadioButton {
|
|
|
|
id: gasRadioBtn
|
|
|
|
ButtonGroup.group: buttonGroup
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 14
|
|
|
|
checked: gasRectangle.checkedByDefault
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (checked) {
|
|
|
|
gasRectangle.checked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: gasText
|
|
|
|
text: gasRectangle.text
|
|
|
|
font.pixelSize: 15
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.top: gasRadioBtn.bottom
|
|
|
|
anchors.topMargin: 6
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: ethText
|
|
|
|
text: gasRectangle.ethValue + " ETH"
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.top: gasText.bottom
|
|
|
|
anchors.topMargin: 4
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: fiatText
|
|
|
|
text: `${gasRectangle.fiatValue} ${gasRectangle.defaultCurrency}`
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.top: ethText.bottom
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: gasRectangle.hovered = true
|
|
|
|
onExited: gasRectangle.hovered = false
|
|
|
|
onClicked: gasRadioBtn.toggle()
|
|
|
|
}
|
|
|
|
}
|