stargate: Accept a string gasPrice in calculateFee

This commit is contained in:
willclarktech 2021-06-16 10:18:34 +02:00
parent c06dd0c0ce
commit 1bc770327d
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 13 additions and 1 deletions

View File

@ -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",
});
});
});

View File

@ -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),