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: bnb custom fee staying as type2 after prepare #7741

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .changeset/rotten-cooks-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/coin-evm": minor
"@ledgerhq/live-common": minor
---

fixed bnb custom fee crashes and erased gasLimit
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ describe("EVM Family", () => {
});
});

it("should return a legacy coin transaction when passing a gasPrice and custom feesStrategy", async () => {
// @ts-expect-error - TODO: change type to allow gasPrice?
CremaFR marked this conversation as resolved.
Show resolved Hide resolved
const tx = await prepareTransaction(account, {
...transaction,
feesStrategy: "custom",
gasPrice: new BigNumber(1),
maxFeePerGas: new BigNumber(0),
maxPriorityFeePerGas: new BigNumber(0),
});

expect(tx).toEqual({
...transaction,
gasPrice: new BigNumber(1),
feesStrategy: "custom",
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
type: 0,
});
});

it("should create a coin transaction using all amount in the account", async () => {
const accountWithBalance = {
...account,
Expand Down
9 changes: 9 additions & 0 deletions libs/coin-modules/coin-evm/src/prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ export const prepareTransaction = async (
// Get the current network status fees
const feeData: FeeData = await (async (): Promise<FeeData> => {
if (transaction.feesStrategy === "custom") {
// better type0 check. gasPrice is never defined if type2
if (transaction.gasPrice) {
return {
gasPrice: transaction.gasPrice,
maxFeePerGas: null,
maxPriorityFeePerGas: null,
nextBaseFee: transaction.gasOptions?.medium?.nextBaseFee ?? null,
};
}
return {
gasPrice: transaction.gasPrice ?? null,
maxFeePerGas: transaction.maxFeePerGas ?? null,
Expand Down
3 changes: 2 additions & 1 deletion libs/ledger-live-common/src/exchange/swap/webApp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { BigNumber } from "bignumber.js";
import { AccountLike } from "@ledgerhq/types-live";

export const getCustomFeesPerFamily = transaction => {
const { family, maxFeePerGas, maxPriorityFeePerGas, feePerByte, fees, utxoStrategy } =
const { family, maxFeePerGas, maxPriorityFeePerGas, feePerByte, fees, utxoStrategy, gasPrice } =
transaction;

switch (family) {
case "evm": {
return {
maxFeePerGas,
maxPriorityFeePerGas,
gasPrice,
};
}
case "bitcoin": {
Expand Down
Loading