Skip to content

Commit 11c9044

Browse files
committed
Fix bug on parsing coin amount and converting to int coins
1 parent 5cf6593 commit 11c9044

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@initia/initia.js",
3-
"version": "0.2.26",
3+
"version": "0.2.27",
44
"description": "The JavaScript SDK for Initia",
55
"license": "Apache-2.0",
66
"author": "Initia Foundation",

src/core/Coin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSONSerializable } from '../util/json'
22
import { Denom } from './Denom'
3-
import { num, checkDecimal } from './num'
3+
import { num, checkDecimal, BigNumber } from './num'
44
import { Coin as Coin_pb } from '@initia/initia.proto/cosmos/base/v1beta1/coin'
55

66
/**
@@ -23,22 +23,22 @@ export class Coin extends JSONSerializable<Coin.Amino, Coin.Data, Coin.Proto> {
2323
amount: number | string
2424
) {
2525
super()
26-
this.amount = num(amount).toString()
26+
this.amount = num(amount).toFixed()
2727
this.isDecimal = checkDecimal(amount)
2828
}
2929

3030
/**
3131
* Turns the Coin into an Integer coin.
3232
*/
3333
public toIntCoin(): Coin {
34-
return new Coin(this.denom, num(this.amount).toFixed())
34+
return new Coin(this.denom, num(this.amount).toFixed(0))
3535
}
3636

3737
/**
3838
* Turns the Coin into an Integer coin with ceiling the amount.
3939
*/
4040
public toIntCeilCoin(): Coin {
41-
return new Coin(this.denom, num(this.amount).toFixed(0, 2))
41+
return new Coin(this.denom, num(this.amount).toFixed(0, BigNumber.ROUND_CEIL))
4242
}
4343

4444
/**

0 commit comments

Comments
 (0)