From 1bc770327dca898ca8792f7cc2ff0aefda68d6ba Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 16 Jun 2021 10:18:34 +0200 Subject: [PATCH] stargate: Accept a string gasPrice in calculateFee --- packages/stargate/src/fee.spec.ts | 10 ++++++++++ packages/stargate/src/fee.ts | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) 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),