Skip to content

Commit

Permalink
fix issue with error trying to convert number with decimals to bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
temptemp3 committed Nov 12, 2024
1 parent 8fa19c1 commit d765ad9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ const Swap = () => {
const fromAmountBN = new BigNumber(fromAmount.replace(/,/g, ''));
if (fromAmountBN.isNaN()) return;
const fromAmountBI = BigInt(
fromAmountBN.multipliedBy(10 ** token.decimals).toFixed()
fromAmountBN.multipliedBy(10 ** token.decimals).toFixed(0)
);
ci.Trader_swapAForB(1, fromAmountBI, 0).then((r: any) => {
if (r.success) {
Expand All @@ -795,7 +795,7 @@ const Swap = () => {
const fromAmountBN = new BigNumber(fromAmount.replace(/,/g, ''));
if (fromAmountBN.isNaN()) return;
const fromAmountBI = BigInt(
fromAmountBN.multipliedBy(10 ** token.decimals).toFixed()
fromAmountBN.multipliedBy(10 ** token.decimals).toFixed(0)
);
ci.Trader_swapBForA(1, fromAmountBI, 0).then((r: any) => {
if (r.success) {
Expand Down Expand Up @@ -844,9 +844,9 @@ const Swap = () => {
const toAmountBI = BigInt(
toAmountBN
.multipliedBy(new BigNumber(10).pow(token2.decimals))
.decimalPlaces(0, BigNumber.ROUND_DOWN)
.toFixed(0)
);
// TODO consider using larger number
ci.Trader_exactSwapBForA(1, Number.MAX_SAFE_INTEGER, toAmountBI).then(
(r: any) => {
console.log({ r });
Expand All @@ -868,13 +868,12 @@ const Swap = () => {
} else if (pool.tokA === tokenId(token)) {
const toAmountBN = new BigNumber(toAmount.replace(/,/g, ''));
if (toAmountBN.isNaN()) return;
// convert to atomic unit
const toAmountBI = BigInt(
toAmountBN
.multipliedBy(new BigNumber(10).pow(token2.decimals))
.decimalPlaces(0, BigNumber.ROUND_DOWN)
.toFixed(0)
);
// TODO consider using larger number
ci.Trader_exactSwapAForB(1, Number.MAX_SAFE_INTEGER, toAmountBI).then(
(r: any) => {
console.log({ r });
Expand Down

0 comments on commit d765ad9

Please sign in to comment.