Skip to content

Commit

Permalink
Merge pull request #36 from lidofinance/fix/wrap-unwrap-refactor-qa-f…
Browse files Browse the repository at this point in the history
…eedback

Fix/wrap unwrap refactor qa feedback
  • Loading branch information
itaven authored Sep 5, 2023
2 parents d4e7a8a + 939a4e3 commit c7d0aaa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export const RequestFormProvider: React.FC = ({ children }) => {
});

// TODO refactor this part as part of TX flow
const { handleSubmit, reset, watch } = formObject;
const {
handleSubmit,
reset,
watch,
formState: { defaultValues },
} = formObject;
const [token, amount] = watch(['token', 'amount']);
const {
allowance,
Expand All @@ -91,11 +96,17 @@ export const RequestFormProvider: React.FC = ({ children }) => {

const onSubmit = useMemo(
() =>
handleSubmit(async ({ requests, amount, token }) => {
handleSubmit(async ({ requests, mode, amount, token }) => {
const { success } = await request(requests, amount, token);
if (success) reset();
if (success) {
reset({
...defaultValues,
mode,
token,
});
}
}),
[reset, handleSubmit, request],
[handleSubmit, request, reset, defaultValues],
);

useEffect(() => {
Expand Down
15 changes: 11 additions & 4 deletions features/wsteth/wrap/wrap-form-controls/form-controller-wrap.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { useCallback } from 'react';
import { FormController } from 'features/wsteth/shared/form-controller/form-controller';
import { useFormContext } from 'react-hook-form';
import { WrapFormInputType } from '../wrap-form-context';

export const FormControllerWrap: React.FC = ({ children }) => {
const { setValue, clearErrors } = useFormContext();
const {
reset,
getValues,
formState: { defaultValues },
} = useFormContext<WrapFormInputType>();

const handleReset = useCallback(() => {
setValue('amount', undefined);
clearErrors('amount');
}, [clearErrors, setValue]);
reset({
...defaultValues,
token: getValues('token'),
});
}, [defaultValues, getValues, reset]);

return <FormController reset={handleReset}>{children}</FormController>;
};
5 changes: 5 additions & 0 deletions shared/forms/components/input-amount/input-amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const InputAmount = forwardRef<HTMLInputElement, InputAmountProps>(

const handleChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
// Support for devices where inputMode="decimal" showing keyboard with comma as decimal delimiter
if (e.currentTarget.value.includes(',')) {
e.currentTarget.value = e.currentTarget.value.replaceAll(',', '.');
}

// Prepend zero when user types just a dot symbol for "0."
if (e.currentTarget.value === '.') {
e.currentTarget.value = '0.';
Expand Down

0 comments on commit c7d0aaa

Please sign in to comment.