fix(wallet): displaying L1 gas cost in UI

Fixes #13892
This commit is contained in:
Sale Djenic 2024-03-26 12:57:03 +01:00 committed by Jonathan Rainville
parent 3d21085fc4
commit e787dce368
8 changed files with 43 additions and 26 deletions

View File

@ -8,6 +8,7 @@ QtObject:
maxFeePerGasL: float
maxFeePerGasM: float
maxFeePerGasH: float
l1GasFee: float
eip1559Enabled: bool
proc setup*(self: GasFeesItem,
@ -17,6 +18,7 @@ QtObject:
maxFeePerGasL: float,
maxFeePerGasM: float,
maxFeePerGasH: float,
l1GasFee: float,
eip1559Enabled: bool
) =
self.QObject.setup
@ -26,6 +28,7 @@ QtObject:
self.maxFeePerGasL = maxFeePerGasL
self.maxFeePerGasM = maxFeePerGasM
self.maxFeePerGasH = maxFeePerGasH
self.l1GasFee = l1GasFee
self.eip1559Enabled = eip1559Enabled
proc delete*(self: GasFeesItem) =
@ -38,10 +41,11 @@ QtObject:
maxFeePerGasL: float = 0,
maxFeePerGasM: float = 0,
maxFeePerGasH: float = 0,
l1GasFee: float = 0,
eip1559Enabled: bool = false
): GasFeesItem =
new(result, delete)
result.setup(gasPrice, baseFee, maxPriorityFeePerGas, maxFeePerGasL, maxFeePerGasM, maxFeePerGasH, eip1559Enabled)
result.setup(gasPrice, baseFee, maxPriorityFeePerGas, maxFeePerGasL, maxFeePerGasM, maxFeePerGasH, l1GasFee, eip1559Enabled)
proc `$`*(self: GasFeesItem): string =
result = "GasFeesItem("
@ -51,54 +55,46 @@ QtObject:
result = result & "\nmaxFeePerGasL: " & $self.maxFeePerGasL
result = result & "\nmaxFeePerGasM: " & $self.maxFeePerGasM
result = result & "\nmaxFeePerGasH: " & $self.maxFeePerGasH
result = result & "\nl1GasFee: " & $self.l1GasFee
result = result & "\neip1559Enabled: " & $self.eip1559Enabled
result = result & ")"
proc gasPriceChanged*(self: GasFeesItem) {.signal.}
proc getGasPrice*(self: GasFeesItem): float {.slot.} =
return self.gasPrice
QtProperty[float] gasPrice:
read = getGasPrice
notify = gasPriceChanged
proc baseFeeChanged*(self: GasFeesItem) {.signal.}
proc getBaseFee*(self: GasFeesItem): float {.slot.} =
return self.baseFee
QtProperty[float] baseFee:
read = getBaseFee
notify = baseFeeChanged
proc maxPriorityFeePerGasChanged*(self: GasFeesItem) {.signal.}
proc getMaxPriorityFeePerGas*(self: GasFeesItem): float {.slot.} =
return self.maxPriorityFeePerGas
QtProperty[float] maxPriorityFeePerGas:
read = getMaxPriorityFeePerGas
notify = maxPriorityFeePerGasChanged
proc maxFeePerGasLChanged*(self: GasFeesItem) {.signal.}
proc getMaxFeePerGasL*(self: GasFeesItem): float {.slot.} =
return self.maxFeePerGasL
QtProperty[float] maxFeePerGasL:
read = getMaxFeePerGasL
notify = maxFeePerGasLChanged
proc maxFeePerGasMChanged*(self: GasFeesItem) {.signal.}
proc getMaxFeePerGasM*(self: GasFeesItem): float {.slot.} =
return self.maxFeePerGasM
QtProperty[float] maxFeePerGasM:
read = getMaxFeePerGasM
notify = maxFeePerGasMChanged
proc maxFeePerGasHChanged*(self: GasFeesItem) {.signal.}
proc getMaxFeePerGasH*(self: GasFeesItem): float {.slot.} =
return self.maxFeePerGasH
QtProperty[float] maxFeePerGasH:
read = getMaxFeePerGasH
notify = maxFeePerGasHChanged
proc eip1559EnabledChanged*(self: GasFeesItem) {.signal.}
proc getL1GasFee*(self: GasFeesItem): float {.slot.} =
return self.l1GasFee
QtProperty[float] l1GasFee:
read = getL1GasFee
proc getEip1559Enabled*(self: GasFeesItem): bool {.slot.} =
return self.eip1559Enabled
QtProperty[bool] eip1559Enabled:
read = getEip1559Enabled
notify = eip1559EnabledChanged
read = getEip1559Enabled

View File

@ -138,6 +138,7 @@ proc convertSuggestedFeesDtoToGasFeesItem(self: Module, gasFees: SuggestedFeesDt
maxFeePerGasL = gasFees.maxFeePerGasL,
maxFeePerGasM = gasFees.maxFeePerGasM,
maxFeePerGasH = gasFees.maxFeePerGasH,
l1GasFee = gasFees.l1GasFee,
eip1559Enabled = gasFees.eip1559Enabled
)

View File

@ -39,6 +39,7 @@ proc getFeesTotal*(paths: seq[TransactionPathDto]): FeesDto =
optimalPrice = path.gasFees.maxFeePerGasM
fees.totalFeesInEth += getGasEthValue(optimalPrice, path.gasAmount)
fees.totalFeesInEth += parseFloat(service_conversion.wei2Eth(service_conversion.gwei2Wei(path.gasFees.l1GasFee)))
fees.totalTokenFees += path.tokenFees
fees.totalTime += path.estimatedTime
return fees

View File

@ -185,6 +185,7 @@ type
maxFeePerGasL*: float64
maxFeePerGasM*: float64
maxFeePerGasH*: float64
l1GasFee*: float64
eip1559Enabled*: bool
proc decodeSuggestedFeesDto*(jsonObj: JsonNode): SuggestedFeesDto =
@ -195,6 +196,7 @@ proc decodeSuggestedFeesDto*(jsonObj: JsonNode): SuggestedFeesDto =
result.maxFeePerGasL = jsonObj{"maxFeePerGasL"}.getFloat
result.maxFeePerGasM = jsonObj{"maxFeePerGasM"}.getFloat
result.maxFeePerGasH = jsonObj{"maxFeePerGasH"}.getFloat
result.l1GasFee = jsonObj{"l1GasFee"}.getFloat
result.eip1559Enabled = jsonObj{"eip1559Enabled"}.getbool
proc toSuggestedFeesDto*(jsonObj: JsonNode): SuggestedFeesDto =
@ -205,6 +207,7 @@ proc toSuggestedFeesDto*(jsonObj: JsonNode): SuggestedFeesDto =
result.maxFeePerGasL = parseFloat(jsonObj{"maxFeePerGasLow"}.getStr)
result.maxFeePerGasM = parseFloat(jsonObj{"maxFeePerGasMedium"}.getStr)
result.maxFeePerGasH = parseFloat(jsonObj{"maxFeePerGasHigh"}.getStr)
result.l1GasFee = parseFloat(jsonObj{"l1GasFee"}.getStr)
result.eip1559Enabled = jsonObj{"eip1559Enabled"}.getbool
proc `$`*(self: SuggestedFeesDto): string =
@ -215,6 +218,7 @@ proc `$`*(self: SuggestedFeesDto): string =
maxFeePerGasL:{self.maxFeePerGasL},
maxFeePerGasM:{self.maxFeePerGasM},
maxFeePerGasH:{self.maxFeePerGasH},
l1GasFee:{self.l1GasFee},
eip1559Enabled:{self.eip1559Enabled}
)"""
@ -260,6 +264,7 @@ proc `$`*(self: TransactionPathDto): string =
approvalGasFees:{self.approvalGasFees},
approvalAmountRequired:{self.approvalAmountRequired},
approvalContractAddress:{self.approvalContractAddress},
gasFees:{$self.gasFees}
)"""
proc toTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =

View File

@ -14,7 +14,7 @@ import StatusQ.Core.Theme 0.1
Item {
id: root
property string selectedTokenSymbol
property var selectedAsset
property string currentCurrency
property var bestRoutes
@ -49,13 +49,27 @@ Item {
statusListItemIcon.active: true
statusListItemIcon.opacity: modelData.isFirstSimpleTx
title: qsTr("%1 transaction fee").arg(root.getNetworkName(modelData.fromNetwork))
subTitle: root.formatCurrencyAmount(totalGasAmountEth, Constants.ethToken)
subTitle: {
let fee = root.formatCurrencyAmount(totalGasAmountEth, Constants.ethToken)
if (modelData.gasFees.eip1559Enabled && modelData.gasFees.l1GasFee > 0) {
fee += "\n(L1 %1)".arg(root.formatCurrencyAmount(totalGasAmountL1Eth, Constants.ethToken))
}
return fee
}
property double totalGasAmountL1Eth: {
let maxFees = modelData.gasFees.maxFeePerGasM
let gasPrice = modelData.gasFees.eip1559Enabled? maxFees : modelData.gasFees.gasPrice
return root.getGasEthValue(gasPrice , modelData.gasFees.l1GasFee)
}
property double totalGasAmountEth: {
let maxFees = modelData.gasFees.maxFeePerGasM
let gasPrice = modelData.gasFees.eip1559Enabled ? maxFees : modelData.gasFees.gasPrice
return root.getGasEthValue(gasPrice , modelData.gasAmount)
}
property double totalGasAmountFiat: root.getFiatValue(totalGasAmountEth, Constants.ethToken)
property double totalGasAmountFiat: root.getFiatValue(totalGasAmountEth, Constants.ethToken) + root.getFiatValue(totalGasAmountL1Eth, Constants.ethToken)
statusListItemSubTitle.width: listItem.width/2 - Style.current.smallPadding
statusListItemSubTitle.elide: Text.ElideMiddle
statusListItemSubTitle.wrapMode: Text.NoWrap
@ -81,7 +95,7 @@ Item {
asset.color: Theme.palette.directColor1
statusListItemIcon.active: true
statusListItemIcon.opacity: modelData.isFirstSimpleTx
title: qsTr("Approve %1 %2 Bridge").arg(root.getNetworkName(modelData.fromNetwork)).arg(root.selectedTokenSymbol)
title: qsTr("Approve %1 %2 Bridge").arg(root.getNetworkName(modelData.fromNetwork)).arg(root.selectedAsset.symbol)
property double approvalGasFees: modelData.approvalGasFees
property string approvalGasFeesSymbol: Constants.ethToken
property double approvalGasFeesFiat: root.getFiatValue(approvalGasFees, approvalGasFeesSymbol)
@ -115,8 +129,8 @@ Item {
statusListItemIcon.opacity: modelData.isFirstBridgeTx
title: qsTr("%1 -> %2 bridge").arg(root.getNetworkName(modelData.fromNetwork)).arg(root.getNetworkName(modelData.toNetwork))
property double tokenFees: modelData.tokenFees
property double tokenFeesFiat: root.getFiatValue(tokenFees, root.selectedTokenSymbol)
subTitle: root.formatCurrencyAmount(tokenFees, root.selectedTokenSymbol)
property double tokenFeesFiat: root.getFiatValue(tokenFees, root.selectedAsset.symbol)
subTitle: root.formatCurrencyAmount(tokenFees, root.selectedAsset.symbol)
visible: modelData.bridgeName !== "Transfer"
statusListItemSubTitle.width: 100
statusListItemSubTitle.elide: Text.ElideMiddle

View File

@ -19,7 +19,7 @@ Rectangle {
property var bestRoutes
property var store
property var currencyStore: store.currencyStore
property string selectedTokenSymbol
property var selectedAsset
property int errorType: Constants.NoError
radius: 13
@ -76,7 +76,7 @@ Rectangle {
currentCurrency: root.currencyStore.currentCurrency
visible: root.errorType === Constants.NoError && !root.isLoading
bestRoutes: root.bestRoutes
selectedTokenSymbol: root.selectedTokenSymbol
selectedAsset: root.selectedAsset
getNetworkName: root.store.getNetworkName
}
GasValidator {

View File

@ -138,7 +138,7 @@ Item {
anchors.topMargin: Style.current.bigPadding
visible: root.advancedOrCustomMode
selectedTokenSymbol: root.selectedAsset.symbol
selectedAsset: root.selectedAsset
isLoading: root.isLoading
bestRoutes: root.bestRoutes
store: root.store

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 408ccc297d7d1d848004f31327f4171cbee62d47
Subproject commit 7410b5cf0b726431c8d4eecdee2c6efe78ef84be