diff --git a/packages/stargate/src/fee.spec.ts b/packages/stargate/src/fee.spec.ts index 393fb01c..43897041 100644 --- a/packages/stargate/src/fee.spec.ts +++ b/packages/stargate/src/fee.spec.ts @@ -70,4 +70,14 @@ describe("calculateFee", () => { gas: "80000", }); }); + + it("accepts a string gas price", () => { + const gasLimit = 80000; + const gasPrice = "0.025ucosm"; + const fee = calculateFee(gasLimit, gasPrice); + expect(fee).toEqual({ + amount: [{ amount: "2000", denom: "ucosm" }], + gas: "80000", + }); + }); }); diff --git a/packages/stargate/src/fee.ts b/packages/stargate/src/fee.ts index 78902cb2..f8b40590 100644 --- a/packages/stargate/src/fee.ts +++ b/packages/stargate/src/fee.ts @@ -51,7 +51,9 @@ export class GasPrice { } } -export function calculateFee(gasLimit: number, { denom, amount: gasPriceAmount }: GasPrice): StdFee { +export function calculateFee(gasLimit: number, gasPrice: GasPrice | string): StdFee { + const processedGasPrice = typeof gasPrice === "string" ? GasPrice.fromString(gasPrice) : gasPrice; + const { denom, amount: gasPriceAmount } = processedGasPrice; const amount = Math.ceil(gasPriceAmount.multiply(new Uint53(gasLimit)).toFloatApproximation()); return { amount: coins(amount, denom),