Skip to content

Commit

Permalink
chore: using explorer gasOption to determine type
Browse files Browse the repository at this point in the history
  • Loading branch information
CremaFR committed Sep 5, 2024
1 parent 331a638 commit 1d2ae6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ 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?
jest.spyOn(nodeApi, "getFeeData").mockImplementationOnce(async () => ({
gasPrice: new BigNumber(1),
maxFeePerGas: null,
maxPriorityFeePerGas: null,
nextBaseFee: null,
}));

// @ts-expect-error - mixed type0/2
const tx = await prepareTransaction(account, {
...transaction,
feesStrategy: "custom",
Expand Down
21 changes: 9 additions & 12 deletions libs/coin-modules/coin-evm/src/prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,16 @@ 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,
};
}
const gasOption = await nodeApi.getFeeData(currency, transaction);

return {
gasPrice: transaction.gasPrice ?? null,
maxFeePerGas: transaction.maxFeePerGas ?? null,
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ?? null,
gasPrice: gasOption.gasPrice && transaction.gasPrice ? transaction.gasPrice : null,
maxFeePerGas:
gasOption.maxFeePerGas && transaction.maxFeePerGas ? transaction.maxFeePerGas : null,
maxPriorityFeePerGas:
gasOption.maxPriorityFeePerGas && transaction.maxPriorityFeePerGas
? transaction.maxPriorityFeePerGas
: null,
nextBaseFee: transaction.gasOptions?.medium?.nextBaseFee ?? null,
};
}
Expand Down

0 comments on commit 1d2ae6e

Please sign in to comment.