From b9ddcb419c49a6b217895143ef331537a1d79376 Mon Sep 17 00:00:00 2001 From: Crypto Minion <154598612+jrwbabylonlab@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:41:06 +1100 Subject: [PATCH] fix: should not show staking form if not enabled (#627) * fix: should not show staking form if not enabled --------- Co-authored-by: David Totraev --- src/app/components/Staking/StakingForm.tsx | 17 ++++++-- src/app/state/StakingState.tsx | 17 +++++--- src/components/staking/StakingForm/index.tsx | 41 +++++++++++++------- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/app/components/Staking/StakingForm.tsx b/src/app/components/Staking/StakingForm.tsx index 951383a5..92d449db 100644 --- a/src/app/components/Staking/StakingForm.tsx +++ b/src/app/components/Staking/StakingForm.tsx @@ -12,8 +12,15 @@ import { FinalityProviders } from "./FinalityProviders/FinalityProviders"; const { networkName } = getNetworkConfigBTC(); export function StakingForm() { - const { loading, validationSchema, stakingInfo, hasError, errorMessage } = - useStakingState(); + const { + loading, + validationSchema, + stakingInfo, + hasError, + blocked, + available, + errorMessage, + } = useStakingState(); const { displayPreview } = useStakingService(); return ( @@ -32,9 +39,11 @@ export function StakingForm() {
diff --git a/src/app/state/StakingState.tsx b/src/app/state/StakingState.tsx index 0123d373..71e4a00a 100644 --- a/src/app/state/StakingState.tsx +++ b/src/app/state/StakingState.tsx @@ -44,6 +44,8 @@ export type StakingStep = export interface StakingState { hasError: boolean; + blocked: boolean; + available: boolean; loading: boolean; processing: boolean; errorMessage?: string; @@ -73,6 +75,8 @@ export interface StakingState { const { StateProvider, useState: useStakingState } = createStateUtils({ hasError: false, + blocked: false, + available: false, loading: false, processing: false, errorMessage: "", @@ -137,13 +141,10 @@ export function StakingState({ children }: PropsWithChildren) { const { publicKeyNoCoord } = useBTCWallet(); - const hasError = - isStateError || - isNetworkFeeError || - !isApiNormal || - isGeoBlocked || - !networkInfo?.stakingStatus; const loading = isStateLoading || isCheckLoading || isFeeLoading; + const hasError = isStateError || isNetworkFeeError || !isApiNormal; + const blocked = isGeoBlocked; + const available = Boolean(networkInfo?.stakingStatus.isStakingOpen); const errorMessage = apiMessage; const latestParam = networkInfo?.params.bbnStakingParams?.latestParam; @@ -299,6 +300,8 @@ export function StakingState({ children }: PropsWithChildren) { const context = useMemo( () => ({ hasError, + blocked, + available, loading, processing, errorMessage, @@ -315,6 +318,8 @@ export function StakingState({ children }: PropsWithChildren) { }), [ hasError, + blocked, + available, loading, processing, errorMessage, diff --git a/src/components/staking/StakingForm/index.tsx b/src/components/staking/StakingForm/index.tsx index fef4b3be..06bf4292 100644 --- a/src/components/staking/StakingForm/index.tsx +++ b/src/components/staking/StakingForm/index.tsx @@ -4,9 +4,9 @@ import { useState } from "react"; import { StatusView } from "@/app/components/Staking/FinalityProviders/FinalityProviderTableStatusView"; import apiNotAvailable from "@/app/components/Staking/Form/States/api-not-available.svg"; import { Message } from "@/app/components/Staking/Form/States/Message"; +import stakingNotStartedIcon from "@/app/components/Staking/Form/States/staking-not-started.svg"; import walletIcon from "@/app/components/Staking/Form/States/wallet-icon.svg"; import { WalletNotConnected } from "@/app/components/Staking/Form/States/WalletNotConnected"; -import { useHealthCheck } from "@/app/hooks/useHealthCheck"; import { AuthGuard } from "@/components/common/AuthGuard"; import { AmountField } from "./components/AmountField"; @@ -21,7 +21,9 @@ import { TermField } from "./components/TermField"; interface DelegationFormProps { loading?: boolean; - disabled?: boolean; + blocked?: boolean; + available?: boolean; + hasError?: boolean; error?: string; stakingInfo?: { minFeeRate: number; @@ -37,12 +39,13 @@ interface DelegationFormProps { export function DelegationForm({ loading, - disabled, + blocked, + available, + hasError, error, stakingInfo, }: DelegationFormProps) { const [isCustomFee, setIsCustomFee] = useState(false); - const { isGeoBlocked } = useHealthCheck(); if (loading) { return ( @@ -54,17 +57,27 @@ export function DelegationForm({ ); } - if (disabled) { - if (isGeoBlocked) { - return ( - - ); - } + if (blocked) { + return ( + + ); + } + + if (!available) { + return ( + + ); + } + if (hasError) { return (