diff --git a/packages/app/contexts/StackboxFormContext.tsx b/packages/app/contexts/StackboxFormContext.tsx index 623c3e33..106b3982 100644 --- a/packages/app/contexts/StackboxFormContext.tsx +++ b/packages/app/contexts/StackboxFormContext.tsx @@ -5,6 +5,7 @@ import { ReactNode, createContext, useContext, useMemo } from "react"; import { ChainId } from "@stackly/sdk"; import { createParser, + Options, parseAsString, parseAsStringEnum, parseAsTimestamp, @@ -50,14 +51,29 @@ const throwStackboxFormContextError = () => { throw new Error("No StackboxFormContext available"); }; +type StackboxFormStateInput = [ + T, + ( + value: T | ((old: T) => T | null) | null, + options?: Options | undefined + ) => Promise +]; + interface StackboxFormContextProps { resetFormValues: (newChainId: ChainId) => void; - stackboxFormState: any; + stackboxFormState: { + fromTokenState: StackboxFormStateInput; + toTokenState: StackboxFormStateInput; + tokenAmountState: StackboxFormStateInput; + frequencyState: StackboxFormStateInput; + startDateState: StackboxFormStateInput; + endDateState: StackboxFormStateInput; + }; } const StackboxFormContext = createContext({ resetFormValues: throwStackboxFormContextError, - stackboxFormState: null, + stackboxFormState: null as any, }); interface StackboxFormContextProviderProps { @@ -108,7 +124,6 @@ export const StackboxFormContextProvider = ({ "endDate", parseAsTimestamp.withDefault(new Date(endDateByFrequency[frequency])) ); - const stackboxFormContext = useMemo(() => { const resetFormValues = (newChainId: ChainId) => { const validChainId = checkIsValidChainId(newChainId) @@ -125,12 +140,30 @@ export const StackboxFormContextProvider = ({ }; const stackboxFormState = { - fromTokenState: [fromToken, setFromToken], - toTokenState: [toToken, setToToken], - tokenAmountState: [tokenAmount, setTokenAmount], - frequencyState: [frequency, setFrequency], - startDateState: [startDateTime, setStartDateTime], - endDateState: [endDateTime, setEndDateTime], + fromTokenState: [ + fromToken, + setFromToken, + ] as StackboxFormStateInput, + toTokenState: [ + toToken, + setToToken, + ] as StackboxFormStateInput, + tokenAmountState: [ + tokenAmount, + setTokenAmount, + ] as StackboxFormStateInput, + frequencyState: [ + frequency, + setFrequency, + ] as StackboxFormStateInput, + startDateState: [ + startDateTime, + setStartDateTime, + ] as StackboxFormStateInput, + endDateState: [ + endDateTime, + setEndDateTime, + ] as StackboxFormStateInput, }; return {