Skip to content

Commit

Permalink
fix: decimals when selling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulclindo committed Oct 10, 2023
1 parent 11b7f0c commit 234d4b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
19 changes: 11 additions & 8 deletions packages/milkomeda-wsc-ui/src/components/Pages/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ const Overview: React.FC<{ selectedWrapToken: WrapToken | null }> = ({ selectedW
} = useTransactionConfigWSC();

const amount = React.useMemo(() => {
if (!defaultWrapToken) return;
if (!defaultWrapToken || !selectedWrapToken) return;
return defaultWrapToken.unit === LOVELACE_UNIT
? convertWeiToTokens({
valueWei: defaultWrapToken.amount,
token: { decimals: 18 },
}).dp(2, BigNumber.ROUND_UP)
: new BigNumber(+defaultWrapToken.amount).dp(4, BigNumber.ROUND_UP);
}, [defaultWrapToken]);
: convertWeiToTokens({
valueWei: defaultWrapToken.amount,
token: selectedWrapToken,
});
}, [defaultWrapToken, selectedWrapToken]);

const tranferTotalAmount =
amount &&
Expand All @@ -53,11 +56,11 @@ const Overview: React.FC<{ selectedWrapToken: WrapToken | null }> = ({ selectedW
: selectedWrapToken?.assetName
: null
}
{...(defaultWrapToken?.unit !== LOVELACE_UNIT && {
tooltipMessage: `Please keep in mind that number of decimals calculation for the token is different, eg: ${amount?.toFixed()} tReserveCoin is equivalent to ${amount?.dividedBy(
10 ** (selectedWrapToken?.decimals ?? 0)
)} RC `,
})}
// {...(defaultWrapToken?.unit !== LOVELACE_UNIT && {
// tooltipMessage: `Please keep in mind that number of decimals calculation for the token is different, eg: ${amount?.toFixed()} tReserveCoin is equivalent to ${amount?.dividedBy(
// 10 ** (selectedWrapToken?.decimals ?? 0)
// )} RC `,
// })}
/>
<LabelWithBalance
label="Bridge fees:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ export const useSelectedWrapToken = () => {

const defaultToken = {
...token,
quantity:
token.unit === LOVELACE_UNIT
? convertWeiToTokens({ valueWei: token.quantity, token })
: new BigNumber(token.quantity),
quantity: convertWeiToTokens({ valueWei: token.quantity, token }),
};
setSelectedWrapToken(defaultToken);
};
Expand Down Expand Up @@ -167,13 +164,18 @@ const WrapStep = ({ nextStep }) => {
}
};

const formattedAmount =
defaultWrapToken.unit === LOVELACE_UNIT
const formattedAmount = React.useMemo(() => {
if (!defaultWrapToken || !selectedWrapToken) return;
return defaultWrapToken.unit === LOVELACE_UNIT
? convertWeiToTokens({
valueWei: defaultWrapToken.amount,
token: { decimals: 18 },
}).dp(2, BigNumber.ROUND_UP)
: new BigNumber(defaultWrapToken.amount).dp(4, BigNumber.ROUND_UP);
: convertWeiToTokens({
valueWei: defaultWrapToken.amount,
token: selectedWrapToken,
});
}, [defaultWrapToken, selectedWrapToken]);

const isAmountValid = React.useMemo(() => {
if (!formattedAmount || !wrappingFee || !bridgeFees || !selectedWrapToken || isLoading) return;
Expand Down

0 comments on commit 234d4b8

Please sign in to comment.