diff --git a/.changeset/wicked-eyes-explain.md b/.changeset/wicked-eyes-explain.md new file mode 100644 index 000000000000..61c37645cdf5 --- /dev/null +++ b/.changeset/wicked-eyes-explain.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/coin-evm": minor +--- + +fix evm getFeeData to return requested option value diff --git a/libs/coin-modules/coin-evm/src/__tests__/unit/api/node/ledger.unit.test.ts b/libs/coin-modules/coin-evm/src/__tests__/unit/api/node/ledger.unit.test.ts index a54f473a4cd7..98064c26fee3 100644 --- a/libs/coin-modules/coin-evm/src/__tests__/unit/api/node/ledger.unit.test.ts +++ b/libs/coin-modules/coin-evm/src/__tests__/unit/api/node/ledger.unit.test.ts @@ -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), @@ -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), diff --git a/libs/coin-modules/coin-evm/src/api/node/ledger.ts b/libs/coin-modules/coin-evm/src/api/node/ledger.ts index 9d3065f33063..835b6fda0f32 100644 --- a/libs/coin-modules/coin-evm/src/api/node/ledger.ts +++ b/libs/coin-modules/coin-evm/src/api/node/ledger.ts @@ -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: { @@ -249,7 +249,7 @@ export const getFeeData: NodeApi["getFeeData"] = async (currency, transaction) = }, }); - return medium; + return options?.[transaction.feesStrategy as keyof typeof options] ?? options.medium; }; /**