Skip to content

Commit

Permalink
fix(amount-input): balance parsing fix (wormhole-foundation#2567)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarm22 authored Sep 11, 2024
1 parent 6b8d602 commit 79dd5a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions wormhole-connect/src/hooks/useGetTokenBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { chainToPlatform } from '@wormhole-foundation/sdk-base';
import { getTokenBridgeWrappedTokenAddress } from 'utils/sdkv2';
import { Chain, TokenAddress } from '@wormhole-foundation/sdk';

// TODO: This hook shouldn't format amounts
// Instead the view should format and render accordingly
const useGetTokenBalances = (
walletAddress: string,
chain: Chain | undefined,
Expand Down
6 changes: 3 additions & 3 deletions wormhole-connect/src/views/v2/Bridge/AmountInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Typography from '@mui/material/Typography';
import AlertBannerV2 from 'components/v2/AlertBanner';
import useGetTokenBalances from 'hooks/useGetTokenBalances';
import { setAmount } from 'store/transferInput';
import { toFixedDecimals } from 'utils/balance';
import { getMaxAmt, validateAmount } from 'utils/transferValidation';
import type { TokenConfig } from 'config/types';
import type { RootState } from 'store';
Expand Down Expand Up @@ -122,7 +121,7 @@ const AmountInput = (props: Props) => {
<CircularProgress size={14} />
) : (
<Typography fontSize={14} textAlign="right">
{Number.parseFloat(toFixedDecimals(`${tokenBalance}`, 6))}
{tokenBalance}
</Typography>
)}
</Stack>
Expand All @@ -136,7 +135,8 @@ const AmountInput = (props: Props) => {
disabled={isInputDisabled || !tokenBalance}
onClick={() => {
if (tokenBalance) {
const trimmedTokenBalance = toFixedDecimals(`${tokenBalance}`, 6);
// TODO: Remove this when useGetTokenBalances returns non formatted amounts
const trimmedTokenBalance = tokenBalance.replaceAll(',', '');
dispatch(setAmount(trimmedTokenBalance));
}
}}
Expand Down

0 comments on commit 79dd5a7

Please sign in to comment.