diff --git a/src/helpers/parser.ts b/src/helpers/parser.ts index 20fa9d3..45b1614 100644 --- a/src/helpers/parser.ts +++ b/src/helpers/parser.ts @@ -1,10 +1,11 @@ import { ethers } from "ethers"; +import {BigNumber} from "bignumber.js"; -export default function parseAmount(numberString: string): string { +export function parseAmount(numberString: string): string { try { - const number = BigInt(numberString); + const number = BigNumber(numberString).toFixed(); return ethers.formatEther(number).toString(); } catch (e) { return ""; } -} +} \ No newline at end of file diff --git a/src/tests/parse.test.ts b/src/tests/parse.test.ts index 013ff6c..e4278e8 100644 --- a/src/tests/parse.test.ts +++ b/src/tests/parse.test.ts @@ -1,7 +1,7 @@ import assert from "assert/strict"; import { describe, it } from "node:test"; import { BigNumber } from "bignumber.js"; -import parseAmount from "../helpers/parser.js"; +import {parseAmount} from "../helpers/parser.js"; describe("Test tx amount parse", () => { it("Should parse rawFungibleTokenAmount on 18 digit BigNumber value", () => { @@ -19,4 +19,18 @@ describe("Test tx amount parse", () => { const expectedParsedAmount = "114119.157542431558142674"; assert.deepStrictEqual(amountPrettified, expectedParsedAmount); }); + + it("Should parse scientific notation", () => { + const scientificNotation = "9.268745046813357e+22"; + const amountPrettified = parseAmount(scientificNotation); + const expectedParsedAmount = "92687.45046813357"; + assert.deepStrictEqual(amountPrettified, expectedParsedAmount); + }); + + it("Should parse regular number", () => { + const scientificNotation = "1000000000000000000"; + const amountPrettified = parseAmount(scientificNotation); + const expectedParsedAmount = "1.0"; + assert.deepStrictEqual(amountPrettified, expectedParsedAmount); + }); });