Skip to content

Commit 0ba1ea5

Browse files
committed
chore(packages): simplify
1 parent 0e841e0 commit 0ba1ea5

2 files changed

Lines changed: 29 additions & 27 deletions

File tree

services/simple-staking/src/ui/baby/widgets/StakingForm/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Form } from "@babylonlabs-io/core-ui";
22
import { useMemo } from "react";
3+
import { DeepPartial } from 'react-hook-form';
34

45
import { AmountField } from "@/ui/baby/components/AmountField";
56
import { FeeField } from "@/ui/baby/components/FeeField";
@@ -60,20 +61,22 @@ export default function StakingForm({
6061
});
6162
};
6263

64+
const handleChange = (data: DeepPartial<StakingFormFields>) => {
65+
setBabyStakeDraft({
66+
...data,
67+
validatorAddresses: data.validatorAddresses?.filter(
68+
(i) => i !== undefined,
69+
),
70+
})
71+
};
72+
6373
return (
6474
<Form
6575
schema={formSchema}
6676
className="flex h-[500px] flex-col gap-2"
6777
onSubmit={handlePreview}
6878
defaultValues={defaultValues}
69-
onChange={(data) =>
70-
setBabyStakeDraft({
71-
...data,
72-
validatorAddresses: data.validatorAddresses?.filter(
73-
(i) => i !== undefined,
74-
),
75-
})
76-
}
79+
onChange={handleChange}
7780
>
7881
<AmountField balance={availableBalance} price={babyPrice} />
7982
<ValidatorField />

services/simple-staking/src/ui/common/components/Multistaking/MultistakingForm/MultistakingForm.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Form } from "@babylonlabs-io/core-ui";
22
import { useCallback, useMemo } from "react";
3+
import { DeepPartial } from "react-hook-form";
34

45
import { useFormPersistenceState } from "@/ui/common/state/FormPersistenceState";
56
import {
@@ -20,11 +21,7 @@ export function MultistakingForm() {
2021
finalityProviders: btcStakeDraft?.finalityProviders,
2122
amount: btcStakeDraft?.amount,
2223
term: btcStakeDraft?.term ?? stakingInfo?.defaultStakingTimeBlocks,
23-
feeRate:
24-
btcStakeDraft?.feeRate ??
25-
(stakingInfo?.defaultFeeRate !== undefined
26-
? stakingInfo.defaultFeeRate
27-
: 0),
24+
feeRate: btcStakeDraft?.feeRate ?? stakingInfo?.defaultFeeRate ?? 0,
2825
feeAmount: btcStakeDraft?.feeAmount,
2926
}),
3027
[
@@ -49,6 +46,21 @@ export function MultistakingForm() {
4946
[setFormData, goToStep],
5047
);
5148

49+
const handleChange = (data: DeepPartial<MultistakingFormFields>) => {
50+
const sanitizedFinalityProviders: Record<string, string> = {};
51+
52+
Object.entries(data.finalityProviders ?? {}).forEach(([key, value]) => {
53+
if (typeof value === "string") {
54+
sanitizedFinalityProviders[key] = value;
55+
}
56+
});
57+
58+
setBtcStakeDraft({
59+
...data,
60+
finalityProviders: sanitizedFinalityProviders,
61+
});
62+
}
63+
5264
if (!stakingInfo) {
5365
return null;
5466
}
@@ -59,20 +71,7 @@ export function MultistakingForm() {
5971
mode="onChange"
6072
reValidateMode="onChange"
6173
defaultValues={defaultValues}
62-
onChange={(data) => {
63-
const sanitizedFinalityProviders: Record<string, string> = {};
64-
65-
Object.entries(data.finalityProviders ?? {}).forEach(([key, value]) => {
66-
if (typeof value === "string") {
67-
sanitizedFinalityProviders[key] = value;
68-
}
69-
});
70-
71-
setBtcStakeDraft({
72-
...data,
73-
finalityProviders: sanitizedFinalityProviders,
74-
});
75-
}}
74+
onChange={handleChange}
7675
onSubmit={handlePreview}
7776
>
7877
<MultistakingFormContent />

0 commit comments

Comments
 (0)