Skip to content

Commit

Permalink
fix: set term field as dirty and touched
Browse files Browse the repository at this point in the history
  • Loading branch information
totraev committed Jan 10, 2025
1 parent 567221a commit a30010d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Home = () => {

<Container
as="main"
className="-mt-[10rem] md:-mt-[6.25rem] flex flex-col gap-12 md:gap-16 pb-16"
className="-mt-[10rem] md:-mt-[6.5rem] flex flex-col gap-12 md:gap-16 pb-16"
>
<Stats />
<PersonalBalance />
Expand Down
7 changes: 3 additions & 4 deletions src/app/state/StakingState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useNetworkFees } from "@/app/hooks/client/api/useNetworkFees";
import { useHealthCheck } from "@/app/hooks/useHealthCheck";
import { useAppState } from "@/app/state";
import type { DelegationV2 } from "@/app/types/delegationsV2";
import { getDefaultTermValue } from "@/config";
import { IS_FIXED_TERM_FIELD } from "@/config";
import { getNetworkConfigBTC } from "@/config/network/btc";
import { btcToSatoshi, satoshiToBtc } from "@/utils/btc";
import { createStateUtils } from "@/utils/createStateUtils";
Expand Down Expand Up @@ -164,10 +164,9 @@ export function StakingState({ children }: PropsWithChildren) {
const { minFeeRate, defaultFeeRate, maxFeeRate } =
getFeeRateFromMempool(mempoolFeeRates);
const defaultStakingTimeBlocks =
getDefaultTermValue() ??
(minStakingTimeBlocks === maxStakingTimeBlocks
IS_FIXED_TERM_FIELD || minStakingTimeBlocks === maxStakingTimeBlocks
? maxStakingTimeBlocks
: undefined);
: undefined;

return {
defaultFeeRate,
Expand Down
14 changes: 12 additions & 2 deletions src/components/staking/StakingModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function StakingModal() {
} = useStakingState();
const { getFinalityProvider } = useFinalityProviderState();
const { createEOI, stakeDelegation } = useStakingService();
const { reset: resetForm, trigger: revalidateForm } = useFormContext();
const {
reset: resetForm,
trigger: revalidateForm,
setValue: setFieldValue,
} = useFormContext();

const fp = useMemo(
() => getFinalityProvider(formData?.finalityProvider ?? ""),
Expand Down Expand Up @@ -63,11 +67,17 @@ export function StakingModal() {
await createEOI(formData);
resetForm({
finalityProvider: "",
term: stakingInfo?.defaultStakingTimeBlocks?.toString() ?? "",
term: "",
amount: "",
feeRate: stakingInfo?.defaultFeeRate?.toString() ?? "0",
feeAmount: "0",
});
if (stakingInfo?.defaultStakingTimeBlocks) {
setFieldValue("term", stakingInfo?.defaultStakingTimeBlocks, {
shouldDirty: true,
shouldTouch: true,
});
}
revalidateForm();
}}
/>
Expand Down
10 changes: 2 additions & 8 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,5 @@ export const getBtcNetwork = (): Network => {
return network;
};

export const getDefaultTermValue = (): number | undefined => {
const termDefaultValue = parseInt(
process.env.NEXT_PUBLIC_DEFAULT_TERM_VALUE ?? "",
10,
);

return !Number.isNaN(termDefaultValue) ? termDefaultValue : undefined;
};
export const IS_FIXED_TERM_FIELD =
process.env.NEXT_PUBLIC_FIXED_STAKING_TERM === "true";

0 comments on commit a30010d

Please sign in to comment.