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: return transaction.feesStrategy gasOption instead of the medium value #7652

Merged
merged 2 commits into from
Aug 27, 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
5 changes: 5 additions & 0 deletions .changeset/wicked-eyes-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/coin-evm": minor
---

fix evm getFeeData to return requested option value
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe("EVM Family", () => {
}
});

it("should return the medium value of the Ledger explorers gas tracker", async () => {
it("should return the fee data based on the transaction's feesStrategy", async () => {
jest.spyOn(LEDGER_GAS_TRACKER, "getGasOptions").mockImplementation(async () => ({
slow: {
maxFeePerGas: new BigNumber(1),
Expand All @@ -408,16 +408,64 @@ describe("EVM Family", () => {
},
}));

const legacyFeeData = await LEDGER_API.getFeeData(currency, { type: 0 } as any);
const eip1559FeeData = await LEDGER_API.getFeeData(currency, { type: 2 } as any);

expect(legacyFeeData).toEqual({
const slowFeeData = await LEDGER_API.getFeeData(currency, {
type: 2,
feesStrategy: "slow",
} as any);
const mediumFeeData = await LEDGER_API.getFeeData(currency, {
type: 2,
feesStrategy: "medium",
} as any);
const fastFeeData = await LEDGER_API.getFeeData(currency, {
type: 2,
feesStrategy: "fast",
} as any);

expect(slowFeeData).toEqual({
maxFeePerGas: new BigNumber(1),
maxPriorityFeePerGas: new BigNumber(2),
gasPrice: new BigNumber(3),
nextBaseFee: new BigNumber(4),
});
expect(mediumFeeData).toEqual({
maxFeePerGas: new BigNumber(5),
maxPriorityFeePerGas: new BigNumber(6),
gasPrice: new BigNumber(7),
nextBaseFee: new BigNumber(8),
});
expect(eip1559FeeData).toEqual({
expect(fastFeeData).toEqual({
maxFeePerGas: new BigNumber(9),
maxPriorityFeePerGas: new BigNumber(10),
gasPrice: new BigNumber(11),
nextBaseFee: new BigNumber(12),
});
});

it("should return medium fee data if feesStrategy is not provided", async () => {
jest.spyOn(LEDGER_GAS_TRACKER, "getGasOptions").mockImplementation(async () => ({
slow: {
maxFeePerGas: new BigNumber(1),
maxPriorityFeePerGas: new BigNumber(2),
gasPrice: new BigNumber(3),
nextBaseFee: new BigNumber(4),
},
medium: {
maxFeePerGas: new BigNumber(5),
maxPriorityFeePerGas: new BigNumber(6),
gasPrice: new BigNumber(7),
nextBaseFee: new BigNumber(8),
},
fast: {
maxFeePerGas: new BigNumber(9),
maxPriorityFeePerGas: new BigNumber(10),
gasPrice: new BigNumber(11),
nextBaseFee: new BigNumber(12),
},
}));

const feeData = await LEDGER_API.getFeeData(currency, { type: 2 } as any);

expect(feeData).toEqual({
maxFeePerGas: new BigNumber(5),
maxPriorityFeePerGas: new BigNumber(6),
gasPrice: new BigNumber(7),
Expand Down
4 changes: 2 additions & 2 deletions libs/coin-modules/coin-evm/src/api/node/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const getFeeData: NodeApi["getFeeData"] = async (currency, transaction) =
throw new LedgerNodeUsedIncorrectly();
}

const { medium } = await getGasOptions({
const options = await getGasOptions({
currency: {
...currency,
ethereumLikeInfo: {
Expand All @@ -249,7 +249,7 @@ export const getFeeData: NodeApi["getFeeData"] = async (currency, transaction) =
},
});

return medium;
return options?.[transaction.feesStrategy as keyof typeof options] ?? options.medium;
};

/**
Expand Down
Loading