-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbalance.tsx
More file actions
38 lines (36 loc) · 1.13 KB
/
balance.tsx
File metadata and controls
38 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { AmountInfo, InfoRow, Wrapper } from './styles';
import { Loader } from '@lidofinance/lido-ui';
import { formatBalance } from 'utils';
import { useFormContext } from 'react-hook-form';
import { useRepayFormData } from 'features/adjustment/repay/repay-form-context';
export const Balance = () => {
const { watch } = useFormContext();
const {
stEthBalance,
wstEthBalance,
isStEthLoading,
isWstEthLoading,
isStEthError,
isWstEthError,
} = useRepayFormData();
const token = watch('token');
const isLoading = isStEthLoading || isWstEthLoading;
const isError = isStEthError || isWstEthError;
const balance = token === 'stETH' ? stEthBalance : wstEthBalance;
return (
<Wrapper>
<InfoRow>
<span>Available to repay</span>
{isLoading && <Loader size="small" />}
{!isLoading && !isError && balance !== undefined && (
<AmountInfo>
{formatBalance(balance).trimmed} {token}
</AmountInfo>
)}
{isError && !isLoading && (
<AmountInfo>stEth amount is not available</AmountInfo>
)}
</InfoRow>
</Wrapper>
);
};