Skip to content

Commit

Permalink
Use refs to handle multiple form submits for Operator Mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Dec 6, 2023
1 parent 227ef21 commit 036cf18
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV PYTHON=/usr/bin/python3
ENV NODE_OPTIONS=--max_old_space_size=3072

# Copy package files and install node modules
COPY package*.json yarn.lock ./
COPY package*.json ./
RUN npm install -g node-gyp
RUN yarn install --ignore-scripts --frozen-lockfile
RUN yarn upgrade @keep-network/coverage-pools@sepolia \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const validateInputtedOperatorAddress = async (
operator: string
) => Promise<boolean>,
mappedOperatorTbtc: string,
mappedOperatorRandomBeacon: string,
mappedOperatorRandomBeacon: string
): Promise<string | undefined> => {
let validationMsg: string | undefined = ""

Expand Down Expand Up @@ -102,13 +102,21 @@ const MapOperatorToStakingProviderForm = withFormik<
} = props
const errors: FormikErrors<MapOperatorToStakingProviderFormValues> = {}

console.log("tbtc", mappedOperatorTbtc)
console.log("random beacon", mappedOperatorRandomBeacon)
console.log("taco", mappedOperatorTaco)

errors.operator = validateETHAddress(values.operator)
if (!errors.operator && mappedOperatorTbtc !== undefined && mappedOperatorRandomBeacon !== undefined) {
if (
!errors.operator &&
mappedOperatorTbtc !== undefined &&
mappedOperatorRandomBeacon !== undefined
) {
errors.operator = await validateInputtedOperatorAddress(
values.operator,
checkIfOperatorIsMappedToAnotherStakingProvider,
mappedOperatorTbtc,
mappedOperatorRandomBeacon,
mappedOperatorRandomBeacon
)
}
if (!errors.operator && mappedOperatorTaco !== undefined) {
Expand All @@ -118,10 +126,14 @@ const MapOperatorToStakingProviderForm = withFormik<
await checkIfOperatorIsMappedToAnotherStakingProvider(values.operator)
validationMsg = undefined
if (isOperatorMappedToAnotherStakingProvider) {
validationMsg = "Operator is already mapped to another staking provider."
validationMsg =
"Operator is already mapped to another staking provider."
}
} catch (error) {
console.error("`MapOperatorToStakingProviderForm` validation error.", error)
console.error(
"`MapOperatorToStakingProviderForm` validation error.",
error
)
validationMsg = (error as Error)?.message
}
errors.operator = validationMsg
Expand Down
20 changes: 16 additions & 4 deletions src/components/Modal/MapOperatorToStakingProviderModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const MapOperatorToStakingProviderModal: FC<
BaseModalProps & MapOperatorToStakingProviderModalProps
> = () => {
const { account } = useWeb3React()
const formRef =
const formRefTbtc =
useRef<FormikProps<MapOperatorToStakingProviderFormValues>>(null)
const formRefTaco =
useRef<FormikProps<MapOperatorToStakingProviderFormValues>>(null)
const { closeModal, openModal } = useModal()
const threshold = useThreshold()
Expand Down Expand Up @@ -88,6 +90,16 @@ const MapOperatorToStakingProviderModal: FC<
)
}

const handleSubmit = async () => {
if (formRefTbtc.current) {
await formRefTbtc.current.handleSubmit()
}

if (formRefTaco.current) {
await formRefTaco.current.handleSubmit()
}
}

return (
<>
<ModalHeader>Operator Address Mapping</ModalHeader>
Expand Down Expand Up @@ -132,7 +144,7 @@ const MapOperatorToStakingProviderModal: FC<
)}
<StakeAddressInfo stakingProvider={account ? account : AddressZero} />
<MapOperatorToStakingProviderForm
innerRef={formRef}
innerRef={formRefTbtc}
formId="map-operator-to-staking-provider-form-tbtc"
initialAddress={
isOperatorMappedOnlyInRandomBeacon
Expand Down Expand Up @@ -172,7 +184,7 @@ const MapOperatorToStakingProviderModal: FC<
<LabelSm>Taco (requires 1tx)</LabelSm>
<StakeAddressInfo stakingProvider={account ? account : AddressZero} />
<MapOperatorToStakingProviderForm
innerRef={formRef}
innerRef={formRefTaco}
formId="map-operator-to-staking-provider-form-taco"
initialAddress={""}
onSubmitForm={onSubmit}
Expand All @@ -187,7 +199,7 @@ const MapOperatorToStakingProviderModal: FC<
<Button onClick={closeModal} variant="outline" mr={2}>
Dismiss
</Button>
<Button type="submit" form="map-operator-to-staking-provider-form">
<Button type="submit" onClick={handleSubmit}>
Map Address
</Button>
</ModalFooter>
Expand Down
2 changes: 1 addition & 1 deletion src/enums/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const envVariables = [
"DAPP_DEVELOPMENT_TESTNET_CONTRACTS",
] as const

export type EnvVariableKey = typeof envVariables[number]
export type EnvVariableKey = (typeof envVariables)[number]

// In order not to break the previous enum API, so using eg.
// `EnvVariable.ETH_HOSTNAME_HTTP` is still valid.
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useFetchExternalPoolData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const pools = {
} as const

type ExternalPool = keyof typeof pools
type ExternalPoolId<T extends ExternalPool> = typeof pools[T][number]
type ExternalPoolId<T extends ExternalPool> = (typeof pools)[T][number]

const fetchCurvePool: (
poolId: ExternalPoolId<"curve">
Expand Down
2 changes: 1 addition & 1 deletion src/static/icons/tokenIconMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const tokenIcons = [
"T_CIRCLE_BRAND",
] as const

export type TokenIcon = typeof tokenIcons[number]
export type TokenIcon = (typeof tokenIcons)[number]

const tokenIconMap: Record<TokenIcon, ComponentType> = {
KEEP_CIRCLE_BRAND: KeepCircleBrand,
Expand Down

0 comments on commit 036cf18

Please sign in to comment.