status-desktop/ui/imports/shared/controls/GasSelector.qml

203 lines
8.0 KiB
QML
Raw Normal View History

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import utils 1.0
import shared.panels 1.0
import shared.controls 1.0
import shared.controls.chat 1.0
import StatusQ.Controls 0.1
import StatusQ.Components 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
Item {
id: root
property string selectedTokenSymbol
property string currentCurrency
property string currentCurrencySymbol
property bool advancedOrCustomMode: false
2021-07-05 12:34:56 +00:00
property var bestRoutes: []
property var estimatedGasFeesTime: []
2021-07-05 12:34:56 +00:00
property int selectedPriority: 1
property double selectedGasEthValue
property string selectedGasFiatValue
property string selectedTimeEstimate
2021-07-05 12:34:56 +00:00
property var getGasEthValue: function () {}
property var getFiatValue: function () {}
2021-07-05 12:34:56 +00:00
enum Priority {
SLOW, // 0
OPTIMAL, // 1
FAST // 2
2021-07-05 12:34:56 +00:00
}
enum EstimatedTime {
Unknown = 0,
LessThanOneMin,
LessThanThreeMins,
LessThanFiveMins,
MoreThanFiveMins
2021-07-05 12:34:56 +00:00
}
QtObject {
id: d
function getLabelForEstimatedTxTime(estimatedFlag) {
switch(estimatedFlag) {
case GasSelector.EstimatedTime.Unknown:
return qsTr("~ Unknown")
case GasSelector.EstimatedTime.LessThanOneMin :
return qsTr("< 1 minute")
case GasSelector.EstimatedTime.LessThanThreeMins :
return qsTr("< 3 minutes")
case GasSelector.EstimatedTime.LessThanFiveMins:
return qsTr("< 5 minutes")
default:
return qsTr("> 5 minutes")
}
2021-07-05 12:34:56 +00:00
}
}
width: parent.width
height: visible ? (!advancedOrCustomMode ? selectorButtons.height : advancedGasSelector.height) + Style.current.halfPadding : 0
Row {
id: selectorButtons
visible: !root.advancedOrCustomMode
anchors.top: parent.top
anchors.topMargin: Style.current.halfPadding
spacing: 11
ButtonGroup {
buttons: gasPrioRepeater.children
}
Repeater {
id: gasPrioRepeater
model: root.estimatedGasFeesTime
GasSelectorButton {
objectName: "GasSelector_slowGasButton"
property double totalFeesInFiat: parseFloat(root.getFiatValue(modelData.totalFeesInEth, "ETH", currentCurrency)) +
parseFloat(root.getFiatValue(modelData.totalTokenFees, root.selectedTokenSymbol, currentCurrency))
primaryText: index === 0 ? qsTr("Slow") : index === 1 ? qsTr("Optimal"): qsTr("Fast")
timeText: index === selectedPriority ? d.getLabelForEstimatedTxTime(modelData.totalTime): qsTr("~ Unknown")
totalGasEthValue: modelData.totalFeesInEth
totalGasFiatValue: index === selectedPriority ? "%1 %2".arg(LocaleUtils.numberToLocaleString(totalFeesInFiat)).arg(root.currentCurrency.toUpperCase()): qsTr("...")
checked: index === selectedPriority
onCheckedChanged: {
if(checked) {
root.selectedPriority = index
root.selectedGasEthValue = totalGasEthValue
root.selectedGasFiatValue = totalGasFiatValue
root.selectedTimeEstimate = timeText
}
2021-07-05 12:34:56 +00:00
}
}
}
}
Column {
id: advancedGasSelector
width: parent.width
anchors.top: parent.top
anchors.topMargin: Style.current.halfPadding
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 10
visible: root.advancedOrCustomMode
spacing: Style.current.halfPadding
feat(tx-comps): Send transaction modal Fixes #669. Composes all tx components to create a send transaction modal for the wallet. 1. Add a reusable TransactionStackView component that wraps a StackView component to show the screens of the Send Tx modal and handles back/forward/reset functionality. 2. Add a reusable TransactionStackGroup which holds tx components and allows modal header and button text to be defined and handles validation for all child components. 3. Add an isValid property to all tx comps for pristine validation state. 4. Reset all components in modal once modal is closed. This consists of a `resetInternal` function that each component should implement to reinstate its original starting state, and a `reset` function that parent components can use to reinstate the overridden properties. 5. Tx error handling to display either a StatusGo error message in the dialog, or wrong password in the TransactionSigner. 6. Fix ReceiveModal to allow for pre-selected account based on current wallet account. 7. Add focused border colour to Input component. 8. Fix issue with last TransactionStackGroup input not being able to obtain focus. 9. Fix fiatBalance not appearing on initial load on AccountSelector. 10. Fix selected asset updated properly when assets changed in the AssetSelector component. 11. AccountSelector is pre-populated with selected wallet account. Supporting work on the components has been done to suppor this. 12. Changing accounts in the "from account" updates the asset balances in the AssetAndAmountInput component. 13. Move validation from ContactSelector to the Select component. 1. Test sending of tokens. This requires that tokens contracts are setup on testnet. Right now, they are set up for contract addresses on mainnet. 2. Loading state once transaction is sent. Button in modal needs to move to a loading state and the "toast" messages in the wallet need to appear informaing user of tx progress. 3. Need to clarify (and implement?) support of ENS names in the AddressInput. It appears that ENS names could be resolved. This would be a long operation and require some kind of UI loading indication. 4. Wallet balances need to be updated on every block, so for example, sending funds between accounts I should be able to see the balance updated in real time. 1. Sending to a contact currently doesn't work because the ContactSelector component selects the Contact's whipser key, instead of his/her wallet address. May need to figure out how this is done in status-react. As it stands, attempting to send to a contact will crash the app. 2. Sending *from* an imported account does not work, with an error from StatusGo `cannot locate account for address: 0x123...`
2020-08-20 04:45:29 +00:00
StatusSwitchTabBar {
id: tabBar
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
visible: root.advancedOrCustomMode
StatusSwitchTabButton {
text: qsTr("Slow")
}
StatusSwitchTabButton {
text: qsTr("Optimal")
2021-07-05 12:34:56 +00:00
}
StatusSwitchTabButton {
text: qsTr("Fast")
feat(tx-comps): Send transaction modal Fixes #669. Composes all tx components to create a send transaction modal for the wallet. 1. Add a reusable TransactionStackView component that wraps a StackView component to show the screens of the Send Tx modal and handles back/forward/reset functionality. 2. Add a reusable TransactionStackGroup which holds tx components and allows modal header and button text to be defined and handles validation for all child components. 3. Add an isValid property to all tx comps for pristine validation state. 4. Reset all components in modal once modal is closed. This consists of a `resetInternal` function that each component should implement to reinstate its original starting state, and a `reset` function that parent components can use to reinstate the overridden properties. 5. Tx error handling to display either a StatusGo error message in the dialog, or wrong password in the TransactionSigner. 6. Fix ReceiveModal to allow for pre-selected account based on current wallet account. 7. Add focused border colour to Input component. 8. Fix issue with last TransactionStackGroup input not being able to obtain focus. 9. Fix fiatBalance not appearing on initial load on AccountSelector. 10. Fix selected asset updated properly when assets changed in the AssetSelector component. 11. AccountSelector is pre-populated with selected wallet account. Supporting work on the components has been done to suppor this. 12. Changing accounts in the "from account" updates the asset balances in the AssetAndAmountInput component. 13. Move validation from ContactSelector to the Select component. 1. Test sending of tokens. This requires that tokens contracts are setup on testnet. Right now, they are set up for contract addresses on mainnet. 2. Loading state once transaction is sent. Button in modal needs to move to a loading state and the "toast" messages in the wallet need to appear informaing user of tx progress. 3. Need to clarify (and implement?) support of ENS names in the AddressInput. It appears that ENS names could be resolved. This would be a long operation and require some kind of UI loading indication. 4. Wallet balances need to be updated on every block, so for example, sending funds between accounts I should be able to see the balance updated in real time. 1. Sending to a contact currently doesn't work because the ContactSelector component selects the Contact's whipser key, instead of his/her wallet address. May need to figure out how this is done in status-react. As it stands, attempting to send to a contact will crash the app. 2. Sending *from* an imported account does not work, with an error from StatusGo `cannot locate account for address: 0x123...`
2020-08-20 04:45:29 +00:00
}
currentIndex: GasSelector.Priority.OPTIMAL
2021-07-05 12:34:56 +00:00
onCurrentIndexChanged: {
root.selectedPriority = currentIndex
if(gasPrioRepeater.count === 3) {
root.selectedGasFiatValue = gasPrioRepeater.itemAt(currentIndex).totalGasFiatValue
root.selectedGasEthValue = gasPrioRepeater.itemAt(currentIndex).totalGasEthValue
root.selectedTimeEstimate = gasPrioRepeater.itemAt(currentIndex).timeText
}
}
}
// Normal transaction
Repeater {
model: root.bestRoutes
StatusListItem {
id: listItem
color: Theme.palette.statusListItem.backgroundColor
width: parent.width
asset.name: index == 0 ? "tiny/gas" : ""
title: qsTr("%1 transaction fee").arg(modelData.fromNetwork.chainName)
subTitle: "%1 eth".arg(LocaleUtils.numberToLocaleString(parseFloat(totalGasAmount)))
property string totalGasAmount : {
let maxFees = (tabBar.currentIndex === GasSelector.Priority.SLOW) ? modelData.gasFees.maxFeePerGasL :
(tabBar.currentIndex === GasSelector.Priority.OPTIMAL) ?
modelData.gasFees.maxFeePerGasM : modelData.gasFees.maxFeePerGasH
let gasPrice = modelData.gasFees.eip1559Enabled ? maxFees : modelData.gasFees.gasPrice
return root.getGasEthValue(gasPrice , modelData.gasAmount)
}
statusListItemSubTitle.width: listItem.width/2 - Style.current.smallPadding
statusListItemSubTitle.elide: Text.ElideMiddle
statusListItemSubTitle.wrapMode: Text.NoWrap
components: [
StatusBaseText {
Layout.alignment: Qt.AlignRight
text: "%1%2".arg(currentCurrencySymbol).arg(LocaleUtils.numberToLocaleString(parseFloat(root.getFiatValue(totalGasAmount, "ETH", root.currentCurrency))))
font.pixelSize: 15
color: Theme.palette.baseColor1
width: listItem.width/2 - Style.current.padding
elide: Text.ElideRight
}
]
2021-07-05 12:34:56 +00:00
}
}
// Bridge
Repeater {
model: root.bestRoutes
StatusListItem {
id: listItem2
color: Theme.palette.statusListItem.backgroundColor
width: parent.width
asset.name: index == 0 ? "tiny/bridge" : ""
title: qsTr("%1 -> %2 bridge").arg(modelData.fromNetwork.chainName).arg(modelData.toNetwork.chainName)
subTitle: "%1 %2".arg(LocaleUtils.numberToLocaleString(modelData.tokenFees)).arg(root.selectedTokenSymbol)
visible: modelData.bridgeName !== "Simple"
statusListItemSubTitle.width: 100//parent.width - Style.current.smallPadding
statusListItemSubTitle.elide: Text.ElideMiddle
components: [
StatusBaseText {
Layout.alignment: Qt.AlignRight
text: "%1%2".arg(currentCurrencySymbol).arg(LocaleUtils.numberToLocaleString(parseFloat(root.getFiatValue(modelData.tokenFees, root.selectedTokenSymbol, root.currentCurrency))))
font.pixelSize: 15
color: Theme.palette.baseColor1
width: listItem2.width/2 - Style.current.padding
elide: Text.ElideRight
}
]
}
}
}
}