Skip to content

Commit 88c399c

Browse files
committed
refactor: update claim no fees form regarding new contracts
1 parent e0695fc commit 88c399c

16 files changed

Lines changed: 117 additions & 251 deletions

File tree

features/claim/claim-form/form/claim-form-context/claim-form-provider.tsx

Lines changed: 0 additions & 91 deletions
This file was deleted.

features/claim/claim-form/form/claim-form-context/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

features/claim/claim-form/form/claim-form-context/use-claim.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

features/claim/claim-form/form/claim-form-context/validation.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

features/claim/claim-form/form/claimable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useClaimForm } from 'features/claim/claim-form/form/claim-form-context';
21
import { InfoRowAmount } from 'shared/components/form';
32
import { vaultTexts } from 'modules/vaults';
43

4+
import { useClaimData } from './hooks';
5+
56
export const Claimable = () => {
6-
const { claimableFeeQuery } = useClaimForm();
7+
const { claimableFeeQuery } = useClaimData();
78

89
return (
910
<InfoRowAmount
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { ClaimFormProvider } from './claim-form-context';
2-
31
import { Claimable } from './claimable';
42
import { ClaimInputs } from './claim-inputs';
53
import { SubmitButton } from './submit-button';
4+
import { FormContainer } from './styles';
65

76
export const ClaimForm = () => {
87
return (
9-
<ClaimFormProvider>
8+
<FormContainer>
109
<Claimable />
1110
<ClaimInputs />
1211
<SubmitButton />
13-
</ClaimFormProvider>
12+
</FormContainer>
1413
);
1514
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './use-claim';
2+
export * from './use-claim-data';

features/claim/claim-form/form/claim-form-context/use-claim-data.tsx renamed to features/claim/claim-form/form/hooks/use-claim-data.tsx

File renamed without changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { useCallback, useState } from 'react';
2+
import { useEstimateGas, useAccount } from 'wagmi';
3+
import { encodeFunctionData } from 'viem';
4+
5+
import { dashboardAbi } from 'abi/dashboard-abi';
6+
import { useVaultInfo, vaultTexts, GoToVault } from 'modules/vaults';
7+
import invariant from 'tiny-invariant';
8+
import { useSendTransaction, withSuccess } from 'modules/web3';
9+
import {} from 'modules/vaults/components/go-to-vault';
10+
11+
export const useClaim = () => {
12+
const [isSubmitting, setSubmitting] = useState(false);
13+
const { activeVault } = useVaultInfo();
14+
const owner = activeVault?.owner;
15+
const { sendTX, ...rest } = useSendTransaction();
16+
17+
return {
18+
claim: useCallback(async () => {
19+
invariant(owner, '[useClaim] owner is undefined');
20+
setSubmitting(true);
21+
22+
const loadingActionText = vaultTexts.actions.claim.loading;
23+
const mainActionCompleteText = vaultTexts.actions.claim.completed;
24+
25+
const claimCall = {
26+
to: owner,
27+
data: encodeFunctionData({
28+
abi: dashboardAbi,
29+
functionName: 'disburseNodeOperatorFee',
30+
}),
31+
loadingActionText,
32+
};
33+
34+
const { success } = await withSuccess(
35+
sendTX({
36+
transactions: [claimCall],
37+
mainActionLoadingText: loadingActionText,
38+
mainActionCompleteText,
39+
renderSuccessContent: GoToVault,
40+
}),
41+
);
42+
43+
setSubmitting(false);
44+
return success;
45+
}, [owner, sendTX]),
46+
isSubmitting,
47+
...rest,
48+
};
49+
};
50+
51+
export const useEstimateClaim = () => {
52+
const { address } = useAccount();
53+
const { activeVault } = useVaultInfo();
54+
const owner = activeVault?.owner;
55+
const enabled = !!(
56+
owner &&
57+
address &&
58+
activeVault.nodeOperatorUnclaimedFee > 0n
59+
);
60+
61+
return useEstimateGas({
62+
to: owner,
63+
account: address,
64+
data: encodeFunctionData({
65+
abi: dashboardAbi,
66+
functionName: 'disburseNodeOperatorFee',
67+
}),
68+
query: {
69+
enabled,
70+
},
71+
});
72+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import styled from 'styled-components';
2+
3+
export const FormContainer = styled.section`
4+
display: flex;
5+
flex-direction: column;
6+
gap: ${({ theme }) => theme.spaceMap.md}px;
7+
8+
width: 600px;
9+
font-weight: 400;
10+
font-size: 12px;
11+
line-height: 1.6em;
12+
border-radius: 20px;
13+
margin: 0;
14+
padding: 32px;
15+
box-shadow: none;
16+
background: var(--lido-color-foreground);
17+
color: var(--lido-color-textSecondary);
18+
`;

0 commit comments

Comments
 (0)