Skip to content

Commit c016ec1

Browse files
committed
feat: withdraw form validation
1 parent 2fa77ed commit c016ec1

File tree

41 files changed

+442
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+442
-411
lines changed

features/adjustment/const.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

features/adjustment/mint/form/amount-field/amount-field.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@ import { InputGroup } from '@lidofinance/lido-ui';
22
import { useController, useFormContext } from 'react-hook-form';
33
import { InputAmount } from 'shared/components';
44

5-
import {
6-
TokenSelectHookForm,
7-
TokenOption,
8-
} from 'shared/hook-form/controls/token-select-hook-form/token-select-hook-form';
9-
import { TOKENS_TO_MINT } from 'features/adjustment/const';
5+
import { TokenSelectHookForm } from 'shared/hook-form/controls/token-select-hook-form';
106
import { useMintFormData } from 'features/adjustment/mint/mint-form-context';
11-
12-
const OPTIONS: TokenOption[] = [
13-
{ token: TOKENS_TO_MINT.stETH },
14-
{ token: TOKENS_TO_MINT.wstETH },
15-
];
7+
import { VAULT_MINT_TOKENS } from 'modules/vaults';
168

179
export const AmountField = () => {
1810
const { mintableStETH, mintableWstETH } = useMintFormData();
@@ -25,7 +17,7 @@ export const AmountField = () => {
2517
return (
2618
<>
2719
<InputGroup>
28-
<TokenSelectHookForm options={OPTIONS} />
20+
<TokenSelectHookForm options={VAULT_MINT_TOKENS} />
2921
<InputAmount {...field} label={`${token} amount`} maxValue={maxValue} />
3022
</InputGroup>
3123
</>

features/adjustment/mint/form/form-input/form-input.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import { InputGroup } from '@lidofinance/lido-ui';
2+
import { VAULT_MINT_TOKENS } from 'modules/vaults';
23
import { InputAmount } from 'shared/components';
3-
import {
4-
TokenSelectHookForm,
5-
TokenOption,
6-
} from 'shared/hook-form/controls/token-select-hook-form/token-select-hook-form';
7-
import { TOKENS_TO_MINT } from 'features/adjustment/const';
8-
9-
const OPTIONS: TokenOption[] = [
10-
{ token: TOKENS_TO_MINT.stETH },
11-
{ token: TOKENS_TO_MINT.wstETH },
12-
];
4+
import { TokenSelectHookForm } from 'shared/hook-form/controls';
135

146
export const FormInput = () => {
157
return (
168
<InputGroup>
17-
<TokenSelectHookForm options={OPTIONS} />
9+
<TokenSelectHookForm options={VAULT_MINT_TOKENS} />
1810
<InputAmount label="ETH amount" />
1911
</InputGroup>
2012
);

features/adjustment/repay/form/form-input/form-input.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import { InputGroup } from '@lidofinance/lido-ui';
22
import { InputAmount } from 'shared/components';
3-
import {
4-
TokenSelectHookForm,
5-
TokenOption,
6-
} from 'shared/hook-form/controls/token-select-hook-form/token-select-hook-form';
7-
import { TOKENS_TO_MINT } from 'features/adjustment/const';
3+
import { TokenSelectHookForm } from 'shared/hook-form/controls';
4+
85
import { useController, useFormContext } from 'react-hook-form';
96
import { useRepayFormData } from '../../repay-form-context';
10-
11-
const OPTIONS: TokenOption[] = [
12-
{ token: TOKENS_TO_MINT.stETH },
13-
{ token: TOKENS_TO_MINT.wstETH },
14-
];
7+
import { VAULT_MINT_TOKENS } from 'modules/vaults';
158

169
export const FormInput = () => {
1710
const { field: amountField } = useController({ name: 'amount' });
@@ -24,7 +17,7 @@ export const FormInput = () => {
2417
// TODO: add error message
2518
return (
2619
<InputGroup>
27-
<TokenSelectHookForm options={OPTIONS} />
20+
<TokenSelectHookForm options={VAULT_MINT_TOKENS} />
2821
<InputAmount
2922
maxValue={maxValue}
3023
label={`${token} amount`}

features/supply/fund/form/fund-form-provider/validation.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { zodResolver } from '@hookform/resolvers/zod';
44
import type { Resolver } from 'react-hook-form';
55

66
import { awaitWithTimeout } from 'utils/await-with-timeout';
7-
import { addressSchema } from 'utils/validate-form-value';
7+
import {
8+
addressSchema,
9+
amountSchema,
10+
supplyTokenSchema,
11+
} from 'utils/validate-form-value';
812
import { vaultTexts } from 'modules/vaults';
913

1014
import type {
@@ -26,10 +30,8 @@ const mintSchema = z.discriminatedUnion('mintSteth', [
2630

2731
export const FundFormSchema = z.intersection(
2832
z.object({
29-
amount: z
30-
.bigint({ message: vaultTexts.common.errors.amount.required })
31-
.min(1n, vaultTexts.common.errors.amount.min(0n)),
32-
token: z.enum(['ETH', 'wETH']),
33+
amount: amountSchema,
34+
token: supplyTokenSchema,
3335
}),
3436
mintSchema,
3537
);

features/supply/fund/form/hooks/use-fund.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const useFund = () => {
5959
functionName: 'withdraw',
6060
args: [amount],
6161
}),
62-
loadingActionText: vaultTexts.actions.supply.loadingWeth,
62+
loadingActionText: vaultTexts.actions.weth.loadingUnwrap,
6363
});
6464
}
6565

features/supply/fund/form/inputs/inputs.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,17 @@ import { useState } from 'react';
22
import { useFormContext } from 'react-hook-form';
33

44
import {
5-
type TokenOption,
65
TokenAmountInputHookForm,
76
AddressInputHookForm,
87
TokenSelectHookForm,
98
InputGroupHookForm,
109
} from 'shared/hook-form/controls';
10+
import { VAULT_SUPPLY_TOKENS, vaultTexts } from 'modules/vaults';
1111

1212
import { useFundForm } from '../fund-form-provider/fund-form-provider';
1313
import type { FundFormValidatedValues } from '../types';
1414

1515
import { CheckMint } from './styles';
16-
import { vaultTexts } from 'modules/vaults';
17-
18-
const options: TokenOption[] = [
19-
{
20-
token: 'ETH',
21-
label: 'ETH',
22-
},
23-
{
24-
token: 'wETH',
25-
label: 'wETH',
26-
},
27-
];
2816

2917
export const Inputs = () => {
3018
const [inputInFocus, setInputInFocus] = useState(false);
@@ -41,7 +29,7 @@ export const Inputs = () => {
4129
<TokenSelectHookForm
4230
errorField="amount"
4331
fieldName="token"
44-
options={options}
32+
options={VAULT_SUPPLY_TOKENS}
4533
/>
4634
<TokenAmountInputHookForm
4735
token={token}

features/supply/withdraw/form/address-field/address-field.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

features/supply/withdraw/form/address-field/current-address-button.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

features/supply/withdraw/form/address-field/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)