Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): displaying L1 gas cost in UI #14149

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/app/modules/main/wallet_section/send/gas_fees_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ QtObject:
maxFeePerGasL: float
maxFeePerGasM: float
maxFeePerGasH: float
l1GasFee: float
eip1559Enabled: bool

proc setup*(self: GasFeesItem,
Expand All @@ -17,6 +18,7 @@ QtObject:
maxFeePerGasL: float,
maxFeePerGasM: float,
maxFeePerGasH: float,
l1GasFee: float,
eip1559Enabled: bool
) =
self.QObject.setup
Expand All @@ -26,6 +28,7 @@ QtObject:
self.maxFeePerGasL = maxFeePerGasL
self.maxFeePerGasM = maxFeePerGasM
self.maxFeePerGasH = maxFeePerGasH
self.l1GasFee = l1GasFee
self.eip1559Enabled = eip1559Enabled

proc delete*(self: GasFeesItem) =
Expand All @@ -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("
Expand All @@ -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
1 change: 1 addition & 0 deletions src/app/modules/main/wallet_section/send/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
1 change: 1 addition & 0 deletions src/app_service/service/transaction/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/app_service/service/transaction/dto.nim
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ type
maxFeePerGasL*: float64
maxFeePerGasM*: float64
maxFeePerGasH*: float64
l1GasFee*: float64
eip1559Enabled*: bool

proc decodeSuggestedFeesDto*(jsonObj: JsonNode): SuggestedFeesDto =
Expand All @@ -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 =
Expand All @@ -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 =
Expand All @@ -215,6 +218,7 @@ proc `$`*(self: SuggestedFeesDto): string =
maxFeePerGasL:{self.maxFeePerGasL},
maxFeePerGasM:{self.maxFeePerGasM},
maxFeePerGasH:{self.maxFeePerGasH},
l1GasFee:{self.l1GasFee},
eip1559Enabled:{self.eip1559Enabled}
)"""

Expand Down Expand Up @@ -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 =
Expand Down
26 changes: 20 additions & 6 deletions ui/imports/shared/popups/send/controls/GasSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ui/imports/shared/popups/send/views/FeesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/popups/send/views/NetworkSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down