Skip to content

Commit 3d12dfd

Browse files
refactor: improve provide data input effects
1 parent 78cd295 commit 3d12dfd

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/components/Forms/FormikInput.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from "react"
1+
import { ChangeEvent, FC, FocusEvent } from "react"
22
import {
33
FormControl,
44
FormControlProps,
@@ -20,6 +20,8 @@ export const FormikInput: FC<
2020
helperText?: string | JSX.Element
2121
placeholder?: string
2222
tooltip?: string
23+
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
24+
onBlur?: (e: FocusEvent<HTMLInputElement>) => void
2325
}
2426
> = ({
2527
name,
@@ -28,6 +30,8 @@ export const FormikInput: FC<
2830
helperText,
2931
placeholder,
3032
tooltip,
33+
onChange,
34+
onBlur,
3135
...restProps
3236
}) => {
3337
const [field, meta] = useField(name)
@@ -75,8 +79,16 @@ export const FormikInput: FC<
7579
errorBorderColor="red.300"
7680
placeholder={placeholder}
7781
_placeholder={{ color: useColorModeValue("gray.400", "gray.500") }}
78-
{...field}
79-
value={meta.value}
82+
name={field.name}
83+
value={field.value}
84+
onChange={(e) => {
85+
field.onChange(e)
86+
onChange?.(e)
87+
}}
88+
onBlur={(e) => {
89+
field.onBlur(e)
90+
onBlur?.(e)
91+
}}
8092
/>
8193
<HelperErrorText
8294
helperText={helperText}

src/pages/tBTC/Bridge/Minting/ProvideData.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useState,
1313
useEffect,
1414
FocusEvent,
15+
ChangeEvent,
1516
} from "react"
1617
import { Form, FormikInput } from "../../../../components/Forms"
1718
import withOnlyConnectedWallet from "../../../../components/withOnlyConnectedWallet"
@@ -68,7 +69,6 @@ type ComponentProps = {
6869
const MintingProcessFormBase: FC<ComponentProps & FormikProps<FormValues>> = ({
6970
formId,
7071
values,
71-
setFieldTouched,
7272
}) => {
7373
const dispatch = useAppDispatch()
7474
const threshold = useThreshold()
@@ -80,9 +80,8 @@ const MintingProcessFormBase: FC<ComponentProps & FormikProps<FormValues>> = ({
8080
: BitcoinNetwork.Mainnet
8181
)
8282

83-
const handleBtcAddressChange = (event: FocusEvent<HTMLInputElement>) => {
83+
const handleBtcAddressChange = (event: ChangeEvent<HTMLInputElement>) => {
8484
const btcAddress = event.target.value
85-
setFieldTouched("btcRecoveryAddress", true)
8685

8786
const isValidFormat =
8887
validateBTCAddress(btcAddress, threshold.tbtc.bitcoinNetwork) ===
@@ -95,10 +94,6 @@ const MintingProcessFormBase: FC<ComponentProps & FormikProps<FormValues>> = ({
9594
ethChainId: SupportedChainIds.Ethereum,
9695
})
9796
)
98-
} else if (btcAddress) {
99-
console.log(
100-
"BTC Address format validation failed (onBlur) or address is empty."
101-
)
10297
}
10398
}
10499

@@ -156,6 +151,7 @@ const MintingProcessForm = withFormik<MintingProcessFormProps, FormValues>({
156151
},
157152
displayName: "MintingProcessForm",
158153
enableReinitialize: true,
154+
validateOnChange: false,
159155
})(MintingProcessFormBase)
160156

161157
export const ProvideDataComponent: FC<{

0 commit comments

Comments
 (0)