From 11c9044a3644ebea9f53365f2fd11c07059b18e9 Mon Sep 17 00:00:00 2001 From: joon9823 Date: Tue, 14 Jan 2025 14:19:52 +0900 Subject: [PATCH] Fix bug on parsing coin amount and converting to int coins --- package-lock.json | 4 ++-- package.json | 2 +- src/core/Coin.ts | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 08c0ee2..a070822 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@initia/initia.js", - "version": "0.2.26", + "version": "0.2.27", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@initia/initia.js", - "version": "0.2.26", + "version": "0.2.27", "license": "Apache-2.0", "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", diff --git a/package.json b/package.json index d173315..4db9b89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@initia/initia.js", - "version": "0.2.26", + "version": "0.2.27", "description": "The JavaScript SDK for Initia", "license": "Apache-2.0", "author": "Initia Foundation", diff --git a/src/core/Coin.ts b/src/core/Coin.ts index 94faebd..04014ee 100644 --- a/src/core/Coin.ts +++ b/src/core/Coin.ts @@ -1,6 +1,6 @@ import { JSONSerializable } from '../util/json' import { Denom } from './Denom' -import { num, checkDecimal } from './num' +import { num, checkDecimal, BigNumber } from './num' import { Coin as Coin_pb } from '@initia/initia.proto/cosmos/base/v1beta1/coin' /** @@ -23,7 +23,7 @@ export class Coin extends JSONSerializable { amount: number | string ) { super() - this.amount = num(amount).toString() + this.amount = num(amount).toFixed() this.isDecimal = checkDecimal(amount) } @@ -31,14 +31,14 @@ export class Coin extends JSONSerializable { * Turns the Coin into an Integer coin. */ public toIntCoin(): Coin { - return new Coin(this.denom, num(this.amount).toFixed()) + return new Coin(this.denom, num(this.amount).toFixed(0)) } /** * Turns the Coin into an Integer coin with ceiling the amount. */ public toIntCeilCoin(): Coin { - return new Coin(this.denom, num(this.amount).toFixed(0, 2)) + return new Coin(this.denom, num(this.amount).toFixed(0, BigNumber.ROUND_CEIL)) } /**