Skip to content

Commit

Permalink
fix issue with commas in swap input
Browse files Browse the repository at this point in the history
  • Loading branch information
temptemp3 committed Nov 12, 2024
1 parent 36ad3fa commit 8fa19c1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,8 @@ const Swap = () => {

const fee = useMemo(() => {
if (!info) return "0";
return ((fromAmount * info?.protoInfo.totFee) / 10000).toFixed(6);
const amount = Number(fromAmount.replace(/,/g, ''));
return ((amount * info?.protoInfo.totFee) / 10000).toFixed(6);
}, [info, fromAmount]);

console.log("fee", fee);
Expand Down Expand Up @@ -774,7 +775,7 @@ const Swap = () => {
);
ci.setFee(4000);
if (pool.tokA === tokenId(token)) {
const fromAmountBN = new BigNumber(fromAmount);
const fromAmountBN = new BigNumber(fromAmount.replace(/,/g, ''));
if (fromAmountBN.isNaN()) return;
const fromAmountBI = BigInt(
fromAmountBN.multipliedBy(10 ** token.decimals).toFixed()
Expand All @@ -791,7 +792,7 @@ const Swap = () => {
}
});
} else if (pool.tokB === tokenId(token)) {
const fromAmountBN = new BigNumber(fromAmount);
const fromAmountBN = new BigNumber(fromAmount.replace(/,/g, ''));
if (fromAmountBN.isNaN()) return;
const fromAmountBI = BigInt(
fromAmountBN.multipliedBy(10 ** token.decimals).toFixed()
Expand Down Expand Up @@ -838,7 +839,7 @@ const Swap = () => {
);
ci.setFee(4000);
if (pool.tokA === tokenId(token2)) {
const toAmountBN = new BigNumber(toAmount);
const toAmountBN = new BigNumber(toAmount.replace(/,/g, ''));
if (toAmountBN.isNaN()) return;
const toAmountBI = BigInt(
toAmountBN
Expand All @@ -865,7 +866,7 @@ const Swap = () => {
}
);
} else if (pool.tokA === tokenId(token)) {
const toAmountBN = new BigNumber(toAmount);
const toAmountBN = new BigNumber(toAmount.replace(/,/g, ''));
if (toAmountBN.isNaN()) return;
// convert to atomic unit
const toAmountBI = BigInt(
Expand Down

0 comments on commit 8fa19c1

Please sign in to comment.