Skip to content

Commit

Permalink
Do it (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos authored Nov 19, 2023
1 parent afcd195 commit c13b9fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion staking/app/pythBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export class PythBalance {
const padded = this.toBN()
.toString()
.padStart(PYTH_DECIMALS + 1, "0");

return (
padded.slice(0, padded.length - PYTH_DECIMALS) +
addCommas(padded.slice(0, padded.length - PYTH_DECIMALS)) +
("." + padded.slice(padded.length - PYTH_DECIMALS)).replace(
TRAILING_ZEROS,
""
Expand Down Expand Up @@ -90,3 +91,7 @@ export class PythBalance {
return this.eq(PythBalance.zero());
}
}

const addCommas = (x: string) => {
return x.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
6 changes: 3 additions & 3 deletions staking/tests/pyth_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ describe("pyth balance tests", async () => {

it("Tests on 60969.430243", async () => {
let amount = PythBalance.fromString("60969.430243");
assert.equal(amount.toString(), "60969.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(), "60969.430243");
assert.equal(amount.toString(), "60,969.430243");
assert(amount.eq(new PythBalance(new BN(60_969_430_243))));
assert(!amount.isZero());

amount = new PythBalance(new BN(60_969_430_243));
assert.equal(amount.toString(), "60969.430243");
assert.equal(amount.toString(), "60,969.430243");
assert(amount.eq(new PythBalance(new BN(60_969_430_243))));
assert(amount.toBN().eq(new BN(60_969_430_243)));
assert(!amount.isZero());
Expand Down

2 comments on commit c13b9fc

@vercel
Copy link

@vercel vercel bot commented on c13b9fc Nov 19, 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 c13b9fc Nov 19, 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.