-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature-tx-info.tsx
More file actions
39 lines (37 loc) · 1.3 KB
/
feature-tx-info.tsx
File metadata and controls
39 lines (37 loc) · 1.3 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
39
import { AmountInfo, InfoRow, Wrapper } from './styles';
import { Loader, Text } from '@lidofinance/lido-ui';
import { useSimulateContract } from 'wagmi';
import { dashboardAbi } from 'abi/dashboard-abi';
import { useVaultInfo } from 'features/overview/contexts';
import { useFormContext } from 'react-hook-form';
export const FeatureTxInfo = () => {
const { activeVault } = useVaultInfo();
const { watch } = useFormContext();
const [token, amount] = watch(['token', 'amount']);
const owner = activeVault?.owner;
const isEnabled = !!owner && !!amount;
const amountAsArg = amount ? BigInt(amount) : BigInt(0);
const functionName = token === 'stETH' ? 'burnStETH' : 'burnWstETH';
const { isLoading, data, isError } = useSimulateContract({
abi: dashboardAbi,
address: owner,
functionName,
args: [amountAsArg],
query: {
enabled: isEnabled,
},
});
return (
<Wrapper>
<InfoRow>
<Text size="xxs" color="secondary">
Transaction cost
</Text>
{isLoading && <Loader size="small" />}
{!!data?.result && <AmountInfo>{data?.result}</AmountInfo>}
{isError && !isLoading && <AmountInfo>Is not available</AmountInfo>}
{!isLoading && !data?.result && !isError && <AmountInfo>-</AmountInfo>}
</InfoRow>
</Wrapper>
);
};