diff --git a/src/app/components/Staking/StakingForm.tsx b/src/app/components/Staking/StakingForm.tsx index 18ace567..951383a5 100644 --- a/src/app/components/Staking/StakingForm.tsx +++ b/src/app/components/Staking/StakingForm.tsx @@ -29,7 +29,7 @@ export function StakingForm() { -
+
{ diff --git a/src/app/state/StakingState.tsx b/src/app/state/StakingState.tsx index 076f12ba..0123d373 100644 --- a/src/app/state/StakingState.tsx +++ b/src/app/state/StakingState.tsx @@ -8,6 +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 { IS_FIXED_TERM_FIELD } from "@/config"; import { getNetworkConfigBTC } from "@/config/network/btc"; import { btcToSatoshi, satoshiToBtc } from "@/utils/btc"; import { createStateUtils } from "@/utils/createStateUtils"; @@ -53,6 +54,7 @@ export interface StakingState { defaultFeeRate: number; minStakingTimeBlocks: number; maxStakingTimeBlocks: number; + defaultStakingTimeBlocks?: number; minStakingAmountSat: number; maxStakingAmountSat: number; unbondingFeeSat: number; @@ -161,6 +163,10 @@ export function StakingState({ children }: PropsWithChildren) { const { minFeeRate, defaultFeeRate, maxFeeRate } = getFeeRateFromMempool(mempoolFeeRates); + const defaultStakingTimeBlocks = + IS_FIXED_TERM_FIELD || minStakingTimeBlocks === maxStakingTimeBlocks + ? maxStakingTimeBlocks + : undefined; return { defaultFeeRate, @@ -170,6 +176,7 @@ export function StakingState({ children }: PropsWithChildren) { maxStakingAmountSat, minStakingTimeBlocks, maxStakingTimeBlocks, + defaultStakingTimeBlocks, unbondingFeeSat, unbondingTime, }; diff --git a/src/components/staking/StakingForm/components/TermField.tsx b/src/components/staking/StakingForm/components/TermField.tsx index b3450a2e..8dfcf27a 100644 --- a/src/components/staking/StakingForm/components/TermField.tsx +++ b/src/components/staking/StakingForm/components/TermField.tsx @@ -3,11 +3,12 @@ import { HiddenField, NumberField } from "@babylonlabs-io/bbn-core-ui"; interface TermFieldProps { min?: number; max?: number; + defaultValue?: number; } -export function TermField({ min = 0, max = 0 }: TermFieldProps) { - if (min === max) { - return ; +export function TermField({ min = 0, defaultValue }: TermFieldProps) { + if (defaultValue) { + return ; } const label = ( diff --git a/src/components/staking/StakingForm/index.tsx b/src/components/staking/StakingForm/index.tsx index 8435f918..fef4b3be 100644 --- a/src/components/staking/StakingForm/index.tsx +++ b/src/components/staking/StakingForm/index.tsx @@ -31,6 +31,7 @@ interface DelegationFormProps { maxStakingTimeBlocks: number; minStakingAmountSat: number; maxStakingAmountSat: number; + defaultStakingTimeBlocks?: number; }; } @@ -45,7 +46,11 @@ export function DelegationForm({ if (loading) { return ( - } title="Please wait..." /> + } + title="Please wait..." + /> ); } @@ -85,6 +90,7 @@ export function DelegationForm({
diff --git a/src/components/staking/StakingModal/index.tsx b/src/components/staking/StakingModal/index.tsx index cb8952d6..d727111b 100644 --- a/src/components/staking/StakingModal/index.tsx +++ b/src/components/staking/StakingModal/index.tsx @@ -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 ?? ""), @@ -65,9 +69,15 @@ export function StakingModal() { finalityProvider: "", term: "", amount: "", - feeRate: stakingInfo?.defaultFeeRate ?? 0, - feeAmount: 0, + feeRate: stakingInfo?.defaultFeeRate?.toString() ?? "0", + feeAmount: "0", }); + if (stakingInfo?.defaultStakingTimeBlocks) { + setFieldValue("term", stakingInfo?.defaultStakingTimeBlocks, { + shouldDirty: true, + shouldTouch: true, + }); + } revalidateForm(); }} /> diff --git a/src/config/index.ts b/src/config/index.ts index d67d60a5..668a435f 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -21,3 +21,6 @@ export const getNetworkAppUrl = (): string => { export const getBtcNetwork = (): Network => { return network; }; + +export const IS_FIXED_TERM_FIELD = + process.env.NEXT_PUBLIC_FIXED_STAKING_TERM === "true";