mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-15 00:55:22 +00:00
d8b0145eb3
Add gas estimate for sticker pack purchase. Update transaction for sticker pack purchase. Add GasValidator component which validates gas is selected correctly and displays an error message if not. This component is not visible until it is not valid (at which point the valdiation error message is displayed). In a future PR, need to: 1. estimate gas for token txfer (sendTransaction) via a normalised method for estimating gas for EthSend 2. move sticker pack purchase to use an EthSend object so gas can be estimated and tx sent
79 lines
2.4 KiB
QML
79 lines
2.4 KiB
QML
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: colValidation.height
|
|
property string notEnoughEthForGasMessage: qsTr("Not enough ETH for gas")
|
|
property var selectedAccount
|
|
property double selectedAmount
|
|
property var selectedAsset
|
|
property double selectedGasEthValue
|
|
property bool isValid: false
|
|
property var reset: function() {}
|
|
|
|
onSelectedAccountChanged: validate()
|
|
onSelectedAmountChanged: validate()
|
|
onSelectedAssetChanged: validate()
|
|
onSelectedGasEthValueChanged: validate()
|
|
|
|
function resetInternal() {
|
|
selectedAccount = undefined
|
|
selectedAmount = 0
|
|
selectedAsset = undefined
|
|
selectedGasEthValue = 0
|
|
isValid = true
|
|
}
|
|
|
|
function validate() {
|
|
let isValid = true
|
|
if (!(selectedAccount && selectedAccount.assets && selectedAmount > 0 && selectedAsset && selectedGasEthValue > 0)) {
|
|
return root.isValid
|
|
}
|
|
txtValidationError.text = ""
|
|
let gasTotal = selectedGasEthValue
|
|
if (selectedAsset && selectedAsset.symbol.toUpperCase() === "ETH") {
|
|
gasTotal += selectedAmount
|
|
}
|
|
const currAcctGasAsset = Utils.findAssetBySymbol(selectedAccount.assets, "ETH")
|
|
if (currAcctGasAsset.value < gasTotal) {
|
|
isValid = false
|
|
txtValidationError.text = notEnoughEthForGasMessage
|
|
}
|
|
root.isValid = isValid
|
|
return isValid
|
|
}
|
|
|
|
Column {
|
|
id: colValidation
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
visible: txtValidationError.text !== ""
|
|
spacing: 5
|
|
|
|
SVGImage {
|
|
id: imgExclamation
|
|
width: 13.33
|
|
height: 13.33
|
|
sourceSize.height: height * 2
|
|
sourceSize.width: width * 2
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
fillMode: Image.PreserveAspectFit
|
|
source: "../app/img/exclamation_outline.svg"
|
|
}
|
|
StyledText {
|
|
id: txtValidationError
|
|
text: ""
|
|
verticalAlignment: Text.AlignVCenter
|
|
horizontalAlignment: Text.AlignHCenter
|
|
font.pixelSize: 13
|
|
height: 18
|
|
color: Style.current.danger
|
|
}
|
|
}
|
|
}
|