Skip to content

Commit edc8a25

Browse files
committed
chore: fixes
1 parent 3afa3c1 commit edc8a25

33 files changed

Lines changed: 252 additions & 293 deletions

features/create-vault/consts.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ export enum CREATE_VAULT_FORM_STEPS {
77

88
const steps = ['Main settings', 'Verify new vaults settings'];
99

10-
export const getSectionNameByStep = (step: number) => steps[step - 1];
10+
export const SECTION_NAMES_BY_STEP = steps.reduce(
11+
(acc, step, index) => ({
12+
...acc,
13+
[index + 1]: step,
14+
}),
15+
{} as Record<number, string>,
16+
);
1117

1218
export const CREATE_VAULT_STEPS = steps.length;
1319

features/create-vault/create-vault-form/create-vault-form.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CreateVaultSchema } from 'features/create-vault/types';
88
import {
99
CREATE_VAULT_FORM_STEPS,
1010
CREATE_VAULT_STEPS,
11-
getSectionNameByStep,
11+
SECTION_NAMES_BY_STEP,
1212
} from 'features/create-vault/consts';
1313

1414
import { createVaultSchema } from './validation';
@@ -22,22 +22,19 @@ import { FormTitle, FormBlock, FormSubtitle } from './styles';
2222

2323
import type { Address } from 'viem';
2424

25-
const defaultValues: CreateVaultSchema = {
26-
nodeOperator: '' as Address,
27-
vaultManager: [{ value: '' as Address }],
28-
nodeOperatorManager: '' as Address,
29-
nodeOperatorFeeBP: '' as unknown as number,
30-
confirmExpiry: 36,
31-
acceptTerms: false,
32-
roles: {},
33-
step: CREATE_VAULT_FORM_STEPS.main,
34-
};
35-
3625
export const CreateVaultForm: FC<PropsWithChildren> = () => {
3726
const formObject = useForm({
38-
defaultValues,
27+
defaultValues: {
28+
nodeOperator: '' as Address,
29+
vaultManager: [{ value: '' as Address }],
30+
nodeOperatorManager: '' as Address,
31+
nodeOperatorFeeBP: undefined,
32+
confirmExpiry: 36,
33+
acceptTerms: false,
34+
roles: {},
35+
step: CREATE_VAULT_FORM_STEPS.main,
36+
},
3937
mode: 'onTouched',
40-
4138
resolver: zodResolver(createVaultSchema, { async: true }),
4239
});
4340

@@ -64,7 +61,7 @@ export const CreateVaultForm: FC<PropsWithChildren> = () => {
6461
<FormSubtitle>
6562
Step {step} of {CREATE_VAULT_STEPS}
6663
</FormSubtitle>
67-
<FormTitle>{getSectionNameByStep(step)}</FormTitle>
64+
<FormTitle> {SECTION_NAMES_BY_STEP[step]}</FormTitle>
6865
<MainSettings isShown={step === CREATE_VAULT_FORM_STEPS.main} />
6966
<Confirmation
7067
isShown={step === CREATE_VAULT_FORM_STEPS.confirm}

features/create-vault/create-vault-form/form-controllers/address-array-input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const AddressArrayInput: FC<AddressArrayProps> = ({ name, label }) => {
2222
'addresses'
2323
>({ name: name as 'addresses' });
2424
const allowDelete = fields.length > 1;
25+
2526
return (
2627
<AddressList>
2728
{fields.map((field, index) => {

features/create-vault/create-vault-form/form-controllers/address-input-base.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ type AddressInputProps = Omit<UseFormRegisterReturn, 'ref'> &
1616
React.ComponentProps<typeof Input>;
1717

1818
export const AddressInputBase = forwardRef<HTMLInputElement, AddressInputProps>(
19-
(props, ref) => {
19+
({ onFocus, onBlur, ...rest }, ref) => {
20+
const name = rest.name as 'value';
21+
2022
const [inFocus, setInFocus] = useState(false);
21-
const name = props.name as 'value';
2223
const { getFieldState } = useFormContext();
2324

24-
const { invalid, isDirty, isValidating, error } = getFieldState(props.name);
25+
const { invalid, isDirty, isValidating, error } = getFieldState(name);
2526

2627
const value = useWatch<{ value: Address }>({ name });
2728

2829
const decorator = (() => {
2930
if (isAddress(value)) {
3031
if (invalid) return <ErrorTriangle />;
31-
if (isValidating) return <Loader size="small" />;
32+
if (invalid && isValidating) return <Loader size="small" />;
3233
if (!isDirty) return null;
3334

3435
return <Identicon address={value} />;
@@ -39,20 +40,20 @@ export const AddressInputBase = forwardRef<HTMLInputElement, AddressInputProps>(
3940
return (
4041
<AddressInputWrapper>
4142
<Input
42-
{...props}
43-
ref={ref}
4443
leftDecorator={decorator}
4544
type="text"
4645
fullwidth
46+
ref={ref}
4747
onFocus={(e) => {
4848
setInFocus(true);
49-
props.onFocus?.(e);
49+
onFocus?.(e);
5050
}}
5151
onBlur={(e) => {
52-
void props.onBlur?.(e);
5352
setInFocus(false);
53+
void onBlur?.(e);
5454
}}
5555
error={inFocus ? error?.message : Boolean(error?.message)}
56+
{...rest}
5657
/>
5758
{!invalid && value && (
5859
<EtherScanLink>

features/create-vault/create-vault-form/form-controllers/input-resolver.tsx renamed to features/create-vault/create-vault-form/form-controllers/create-vault-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const getInput = (dataType: GeneralInputProps['dataType']) => {
1919
}
2020
};
2121

22-
export const InputResolver: FC<GeneralInputProps> = (props) => {
22+
export const CreateVaultInput: FC<GeneralInputProps> = (props) => {
2323
const { dataType, title, notes, hint } = props;
2424

2525
const Input = getInput(dataType);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { InputResolver } from './input-resolver';
1+
export { CreateVaultInput } from './create-vault-input';

features/create-vault/create-vault-form/form-controllers/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components';
22
import { ButtonIcon, Question } from '@lidofinance/lido-ui';
33

4-
/// InputResolver
4+
/// CreateVaultInput
55

66
export const InputContainer = styled.div`
77
display: flex;

features/create-vault/create-vault-form/stages/confirmation/confirmation-data/confirmation-data-item/confirm-address.tsx renamed to features/create-vault/create-vault-form/stages/confirmation/confirmation-data/confirm-address.tsx

File renamed without changes.

features/create-vault/create-vault-form/stages/confirmation/confirmation-data/confirmation-data-item/confirm-number.tsx renamed to features/create-vault/create-vault-form/stages/confirmation/confirmation-data/confirm-number.tsx

File renamed without changes.

features/create-vault/create-vault-form/stages/confirmation/confirmation-data/confirmation-data-item/confirm-percent.tsx renamed to features/create-vault/create-vault-form/stages/confirmation/confirmation-data/confirm-percent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ConfirmDataItemProps } from './types';
66
import invariant from 'tiny-invariant';
77

88
export const ConfirmPercent: FC<ConfirmDataItemProps> = ({ payload }) => {
9+
if (!payload) return null;
910
invariant(
1011
typeof payload === 'number' || typeof payload === 'string',
1112
'Payload must be a string | number',

0 commit comments

Comments
 (0)