Skip to content

Commit

Permalink
Fix PythBalance parser to work with commas (#280)
Browse files Browse the repository at this point in the history
* Fix

* Fix commas

* Do it
  • Loading branch information
guibescos authored Nov 20, 2023
1 parent 7b16e33 commit c8b37a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions staking/app/pythBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
5 changes: 5 additions & 0 deletions staking/tests/pyth_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand Down

2 comments on commit c8b37a1

@vercel
Copy link

@vercel vercel bot commented on c8b37a1 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

staking-devnet – ./

staking-devnet-git-main-pyth-web.vercel.app
governance-nu.vercel.app
staking-devnet-pyth-web.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c8b37a1 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.