stargate: Accept a string gasPrice in calculateFee
This commit is contained in:
parent
c06dd0c0ce
commit
1bc770327d
@ -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",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user