From c8b37a1fdbf1d6df076be38fa1f698a0f77b8628 Mon Sep 17 00:00:00 2001 From: guibescos <59208140+guibescos@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:25:30 -0600 Subject: [PATCH] Fix PythBalance parser to work with commas (#280) * Fix * Fix commas * Do it --- staking/app/pythBalance.ts | 2 ++ staking/tests/pyth_balance.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/staking/app/pythBalance.ts b/staking/app/pythBalance.ts index 8a9ed7f9..eccd04c2 100644 --- a/staking/app/pythBalance.ts +++ b/staking/app/pythBalance.ts @@ -27,6 +27,8 @@ export class PythBalance { } static fromString(amount: string) { + amount = amount.split(",").join(""); + if (amount.match(INTEGER_REGEXP)) { return new PythBalance(new BN(amount).mul(new BN(10 ** PYTH_DECIMALS))); } else if (amount.match(DECIMAL_REGEXP)) { diff --git a/staking/tests/pyth_balance.ts b/staking/tests/pyth_balance.ts index 86914220..65820326 100644 --- a/staking/tests/pyth_balance.ts +++ b/staking/tests/pyth_balance.ts @@ -100,6 +100,11 @@ describe("pyth balance tests", async () => { assert(amount.eq(new PythBalance(new BN(60_969_430_243)))); assert(!amount.isZero()); + amount = PythBalance.fromString("60,969.430243"); + assert.equal(amount.toString(), "60,969.430243"); + assert(amount.eq(new PythBalance(new BN(60_969_430_243)))); + assert(!amount.isZero()); + amount = PythBalance.fromString("060969.430243"); assert.equal(amount.toString(), "60,969.430243"); assert(amount.eq(new PythBalance(new BN(60_969_430_243))));