@@ -5,12 +5,10 @@ import {
55 useCallback ,
66 createContext ,
77 useContext ,
8- useState ,
98} from 'react' ;
109import { FormProvider , useForm } from 'react-hook-form' ;
1110import invariant from 'tiny-invariant' ;
1211
13- import { useFormControllerRetry } from 'shared/hook-form/form-controller/use-form-controller-retry-delegate' ;
1412import { useVaultInfo } from 'modules/vaults' ;
1513import { useMint } from 'features/adjustment/mint/hooks' ;
1614
@@ -20,12 +18,6 @@ import {
2018 FormControllerContextValueType ,
2119} from 'shared/hook-form/form-controller' ;
2220import { MintFormSchema } from 'features/adjustment/mint/types' ;
23- import { SubmitModal } from 'shared/components' ;
24- import {
25- SubmitPayload ,
26- SubmitStep ,
27- SubmitStepEnum ,
28- } from 'shared/components/submit-modal/types' ;
2921import { Address } from 'viem' ;
3022
3123type MintDataContextValue = {
@@ -48,20 +40,17 @@ export const useMintFormData = () => {
4840} ;
4941
5042export const MintFormProvider : FC < { children : ReactNode } > = ( { children } ) => {
51- const [ submitStep , setSubmitStep ] = useState < {
52- step : SubmitStep ;
53- tx ?: Address ;
54- } > ( ( ) => ( { step : SubmitStepEnum . edit } ) ) ;
5543 const formObject = useForm < MintFormSchema > ( {
5644 defaultValues : {
5745 amount : undefined ,
5846 token : 'stETH' ,
5947 recipient : '' as Address ,
6048 } ,
6149 mode : 'all' ,
50+ // TODO: validation
6251 reValidateMode : 'onChange' ,
6352 } ) ;
64- const { callMint } = useMint ( ) ;
53+ const { mint , retryEvent } = useMint ( ) ;
6554 const { activeVault } = useVaultInfo ( ) ;
6655
6756 const mintData = useMemo ( ( ) => {
@@ -76,54 +65,35 @@ export const MintFormProvider: FC<{ children: ReactNode }> = ({ children }) => {
7665 } ;
7766 } , [ activeVault ] ) ;
7867
79- const { retryEvent, retryFire } = useFormControllerRetry ( ) ;
80- const setModalState = useCallback ( ( submitStep : SubmitPayload ) => {
81- setSubmitStep ( submitStep ) ;
82- } , [ ] ) ;
83-
8468 const onSubmit = useCallback (
8569 async ( { recipient, amount, token } : MintFormSchema ) => {
86- if ( amount && recipient ) {
87- try {
88- setModalState ( { step : SubmitStepEnum . initiate } ) ;
89- const tx = await callMint ( recipient , amount , token , setModalState ) ;
90- setModalState ( { step : SubmitStepEnum . overview , tx } ) ;
91- return true ;
92- } catch ( err ) {
93- if (
94- err instanceof Error &&
95- err . message . includes ( 'User rejected the request' )
96- ) {
97- setModalState ( { step : SubmitStepEnum . reject } ) ;
98- } else {
99- setModalState ( { step : SubmitStepEnum . error } ) ;
100- }
101- }
102- }
70+ // TODO: add validation, remove stub
71+ if ( ! recipient || ! amount ) return false ;
72+ invariant ( recipient , '[MintFormProvider] recipient is undefined' ) ;
73+ invariant ( amount , '[MintFormProvider] amount is undefined' ) ;
74+ invariant ( token , '[MintFormProvider] token is undefined' ) ;
10375
104- return false ;
76+ return await mint ( recipient , amount , token ) ;
10577 } ,
10678 // eslint-disable-next-line react-hooks/exhaustive-deps
107- [ callMint ] ,
79+ [ mint ] ,
10880 ) ;
10981
11082 const formControllerValue : FormControllerContextValueType < MintFormSchema > =
11183 useMemo (
11284 ( ) => ( {
11385 onSubmit,
11486 retryEvent,
115- retryFire,
11687 onReset : formObject . reset ,
11788 } ) ,
118- [ retryFire , retryEvent , onSubmit , formObject . reset ] ,
89+ [ retryEvent , onSubmit , formObject . reset ] ,
11990 ) ;
12091
12192 return (
12293 < MintDataContext . Provider value = { mintData } >
12394 < FormProvider { ...formObject } >
12495 < FormControllerContext . Provider value = { formControllerValue } >
12596 < FormController > { children } </ FormController >
126- < SubmitModal submitStep = { submitStep } setModalState = { setModalState } />
12797 </ FormControllerContext . Provider >
12898 </ FormProvider >
12999 </ MintDataContext . Provider >
0 commit comments