diff --git a/src/app/api/getParams.ts b/src/app/api/getNetworkInfo.ts similarity index 76% rename from src/app/api/getParams.ts rename to src/app/api/getNetworkInfo.ts index 4b232817..e8b4a509 100644 --- a/src/app/api/getParams.ts +++ b/src/app/api/getNetworkInfo.ts @@ -1,12 +1,12 @@ import { getPublicKeyNoCoord } from "@babylonlabs-io/btc-staking-ts"; import { AxiosResponse } from "axios"; -import { Params } from "../types/params"; +import { NetworkInfo } from "../types/networkInfo"; import { apiWrapper } from "./apiWrapper"; -export interface ParamsDataResponse { - data: ParamsAPI; +interface NetworkInfoDataResponse { + data: NetworkInfoAPI; } export interface BtcCheckpointParams { @@ -14,9 +14,16 @@ export interface BtcCheckpointParams { btc_confirmation_depth: number; } -export interface ParamsAPI { - bbn: BbnParams[]; - btc: BtcCheckpointParams[]; +interface StakingStatus { + is_staking_open: boolean; +} + +interface NetworkInfoAPI { + staking_status: StakingStatus; + params: { + bbn: BbnParams[]; + btc: BtcCheckpointParams[]; + }; } export interface BbnParams { @@ -37,14 +44,14 @@ export interface BbnParams { delegation_creation_base_gas_fee: number; } -export const getParams = async (): Promise => { +export const getNetworkInfo = async (): Promise => { const { data } = (await apiWrapper( "GET", - "/v2/params", - "Error getting params", - )) as AxiosResponse; + "/v2/network-info", + "Error getting network info", + )) as AxiosResponse; - const params = data.data; + const { params, staking_status } = data.data; const stakingVersions = params.bbn .sort((a, b) => a.version - b.version) // Sort by version ascending @@ -104,15 +111,20 @@ export const getParams = async (): Promise => { } return { - bbnStakingParams: { - latestParam: latestStakingParam, - versions: stakingVersions, - genesisParam: genesisStakingParam, + stakingStatus: { + isStakingOpen: staking_status.is_staking_open, }, - btcEpochCheckParams: { - latestParam: latestEpochCheckParam, - versions: epochCheckVersions, - genesisParam: genesisEpochCheckParam, + params: { + bbnStakingParams: { + latestParam: latestStakingParam, + versions: stakingVersions, + genesisParam: genesisStakingParam, + }, + btcEpochCheckParams: { + latestParam: latestEpochCheckParam, + versions: epochCheckVersions, + genesisParam: genesisEpochCheckParam, + }, }, }; }; diff --git a/src/app/components/FAQ/FAQ.tsx b/src/app/components/FAQ/FAQ.tsx index e08c6d9c..7c4a820d 100644 --- a/src/app/components/FAQ/FAQ.tsx +++ b/src/app/components/FAQ/FAQ.tsx @@ -1,6 +1,6 @@ import { Heading } from "@babylonlabs-io/bbn-core-ui"; -import { useParams } from "@/app/hooks/api/useParams"; +import { useNetworkInfo } from "@/app/hooks/api/useNetworkInfo"; import { getNetworkConfig } from "@/config/network.config"; import { questions } from "./data/questions"; @@ -9,9 +9,10 @@ interface FAQProps {} export const FAQ: React.FC = () => { const { coinName, networkName } = getNetworkConfig(); - const { data: params } = useParams(); + const { data: networkInfo } = useNetworkInfo(); const confirmationDepth = - params?.btcEpochCheckParams?.latestParam?.btcConfirmationDepth || 10; + networkInfo?.params.btcEpochCheckParams?.latestParam + ?.btcConfirmationDepth || 10; return (
diff --git a/src/app/components/Modals/PreviewModal.tsx b/src/app/components/Modals/PreviewModal.tsx index 0e965564..060d31d4 100644 --- a/src/app/components/Modals/PreviewModal.tsx +++ b/src/app/components/Modals/PreviewModal.tsx @@ -11,7 +11,7 @@ import { Text, } from "@babylonlabs-io/bbn-core-ui"; -import { useParams } from "@/app/hooks/api/useParams"; +import { useNetworkInfo } from "@/app/hooks/api/useNetworkInfo"; import { useIsMobileView } from "@/app/hooks/useBreakpoint"; import { getNetworkConfig } from "@/config/network.config"; import { blocksToDisplayTime } from "@/utils/blocksToDisplayTime"; @@ -48,9 +48,10 @@ export const PreviewModal = ({ const isMobileView = useIsMobileView(); const { coinName } = getNetworkConfig(); - const { data: params } = useParams(); + const { data: networkInfo } = useNetworkInfo(); const confirmationDepth = - params?.btcEpochCheckParams?.latestParam?.btcConfirmationDepth || 10; + networkInfo?.params.btcEpochCheckParams?.latestParam + ?.btcConfirmationDepth || 10; const DialogComponent = isMobileView ? MobileDialog : Dialog; diff --git a/src/app/components/Staking/Staking.tsx b/src/app/components/Staking/Staking.tsx index 84ec4be7..8f969e16 100644 --- a/src/app/components/Staking/Staking.tsx +++ b/src/app/components/Staking/Staking.tsx @@ -74,8 +74,8 @@ export const Staking = () => { useLocalStorage("bbn-staking-cancelFeedbackModalOpened ", false); const { createDelegationEoi, estimateStakingFee } = useTransactionService(); - const { params } = useAppState(); - const latestParam = params?.bbnStakingParams?.latestParam; + const { networkInfo } = useAppState(); + const latestParam = networkInfo?.params.bbnStakingParams?.latestParam; const [pendingVerificationOpen, setPendingVerificationOpen] = useState(false); const [stakingTxHashHex, setStakingTxHashHex] = useState< diff --git a/src/app/components/Summary/Summary.tsx b/src/app/components/Summary/Summary.tsx index 815a5f38..4ad19407 100644 --- a/src/app/components/Summary/Summary.tsx +++ b/src/app/components/Summary/Summary.tsx @@ -3,7 +3,7 @@ import { FaBitcoin } from "react-icons/fa"; import { Tooltip } from "react-tooltip"; import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider"; -import { useParams } from "@/app/hooks/api/useParams"; +import { useNetworkInfo } from "@/app/hooks/api/useNetworkInfo"; import { useHealthCheck } from "@/app/hooks/useHealthCheck"; import { useAppState } from "@/app/state"; import { useDelegationState } from "@/app/state/DelegationState"; @@ -24,9 +24,10 @@ export const Summary = () => { const { coinName } = getNetworkConfig(); const onMainnet = getNetworkConfig().network === Network.MAINNET; - const { data: params } = useParams(); + const { data: networkInfo } = useNetworkInfo(); const confirmationDepth = - params?.btcEpochCheckParams?.latestParam?.btcConfirmationDepth || 10; + networkInfo?.params.btcEpochCheckParams?.latestParam + ?.btcConfirmationDepth || 10; if (!address) return; diff --git a/src/app/hooks/api/useNetworkInfo.ts b/src/app/hooks/api/useNetworkInfo.ts new file mode 100644 index 00000000..44e319cd --- /dev/null +++ b/src/app/hooks/api/useNetworkInfo.ts @@ -0,0 +1,13 @@ +import { getNetworkInfo } from "@/app/api/getNetworkInfo"; +import { useAPIQuery } from "@/app/hooks/api/useApi"; +import { NetworkInfo } from "@/app/types/networkInfo"; + +export const NETWORK_INFO_KEY = "NETWORK_INFO"; + +export function useNetworkInfo({ enabled = true }: { enabled?: boolean } = {}) { + return useAPIQuery({ + queryKey: [NETWORK_INFO_KEY], + queryFn: getNetworkInfo, + enabled, + }); +} diff --git a/src/app/hooks/api/useParams.ts b/src/app/hooks/api/useParams.ts deleted file mode 100644 index 45f6d03f..00000000 --- a/src/app/hooks/api/useParams.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getParams } from "@/app/api/getParams"; -import { useAPIQuery } from "@/app/hooks/api/useApi"; -import { Params } from "@/app/types/params"; - -export const PARAMS_KEY = "PARAMS"; - -export function useParams({ enabled = true }: { enabled?: boolean } = {}) { - return useAPIQuery({ - queryKey: [PARAMS_KEY], - queryFn: getParams, - enabled, - }); -} diff --git a/src/app/hooks/services/useTransactionService.tsx b/src/app/hooks/services/useTransactionService.tsx index 9280d8f4..033f3377 100644 --- a/src/app/hooks/services/useTransactionService.tsx +++ b/src/app/hooks/services/useTransactionService.tsx @@ -17,7 +17,7 @@ import { EOIStepStatus } from "@/app/components/Modals/EOIModal"; import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider"; import { useCosmosWallet } from "@/app/context/wallet/CosmosWalletProvider"; import { useAppState } from "@/app/state"; -import { BbnStakingParamsVersion, Params } from "@/app/types/params"; +import { BbnStakingParamsVersion, Params } from "@/app/types/networkInfo"; import { clearTxSignatures, extractSchnorrSignaturesFromTransaction, @@ -51,7 +51,7 @@ export enum SigningStep { } export const useTransactionService = () => { - const { availableUTXOs: inputUTXOs, params } = useAppState(); + const { availableUTXOs: inputUTXOs, networkInfo } = useAppState(); const { data: networkFees } = useNetworkFees(); const { defaultFeeRate } = getFeeRateFromMempool(networkFees); @@ -70,8 +70,8 @@ export const useTransactionService = () => { pushTx, } = useBTCWallet(); - const latestParam = params?.bbnStakingParams?.latestParam; - const genesisParam = params?.bbnStakingParams?.genesisParam; + const latestParam = networkInfo?.params.bbnStakingParams?.latestParam; + const genesisParam = networkInfo?.params.bbnStakingParams?.genesisParam; /** * Create the delegation EOI @@ -287,7 +287,7 @@ export const useTransactionService = () => { stakingTxHex: string, ) => { // Perform checks - if (!params?.bbnStakingParams.versions.length) { + if (!networkInfo?.params.bbnStakingParams.versions.length) { throw new Error("Staking parameters not loaded"); } if (!btcConnected || !btcNetwork) @@ -295,7 +295,7 @@ export const useTransactionService = () => { validateStakingInput(stakingInput); - const p = getParamByVersion(params, paramVersion); + const p = getParamByVersion(networkInfo.params, paramVersion); if (!p) throw new Error("Staking params not loaded"); const staking = new Staking( @@ -327,7 +327,7 @@ export const useTransactionService = () => { [ btcConnected, btcNetwork, - params, + networkInfo, address, publicKeyNoCoord, inputUTXOs, @@ -348,7 +348,10 @@ export const useTransactionService = () => { }[], ) => { // Perform checks - if (!params || params.bbnStakingParams.versions.length === 0) { + if ( + !networkInfo || + networkInfo.params.bbnStakingParams.versions.length === 0 + ) { throw new Error("Params not loaded"); } if (!btcConnected || !btcNetwork) @@ -358,7 +361,7 @@ export const useTransactionService = () => { const stakingTx = await Transaction.fromHex(stakingTxHex); - const p = getParamByVersion(params, paramVersion); + const p = getParamByVersion(networkInfo.params, paramVersion); if (!p) throw new Error("Staking params not loaded"); const staking = new Staking( @@ -405,7 +408,7 @@ export const useTransactionService = () => { console.log("unbonding tx id", signedUnbondingTx.getId()); }, [ - params, + networkInfo, btcConnected, btcNetwork, address, @@ -429,7 +432,10 @@ export const useTransactionService = () => { unbondingTxHex: string, ) => { // Perform checks - if (!params || params.bbnStakingParams.versions.length === 0) { + if ( + !networkInfo || + networkInfo.params.bbnStakingParams.versions.length === 0 + ) { throw new Error("Params not loaded"); } if (!btcConnected || !btcNetwork) @@ -437,7 +443,7 @@ export const useTransactionService = () => { validateStakingInput(stakingInput); - const p = getParamByVersion(params, paramVersion); + const p = getParamByVersion(networkInfo.params, paramVersion); if (!p) throw new Error("Staking params not loaded"); const staking = new Staking( @@ -468,7 +474,7 @@ export const useTransactionService = () => { ); }, [ - params, + networkInfo, btcConnected, btcNetwork, address, @@ -493,7 +499,10 @@ export const useTransactionService = () => { stakingTxHex: string, ) => { // Perform checks - if (!params || params.bbnStakingParams.versions.length === 0) { + if ( + !networkInfo || + networkInfo.params.bbnStakingParams.versions.length === 0 + ) { throw new Error("Params not loaded"); } if (!btcConnected || !btcNetwork) @@ -501,7 +510,7 @@ export const useTransactionService = () => { validateStakingInput(stakingInput); - const p = getParamByVersion(params, paramVersion); + const p = getParamByVersion(networkInfo.params, paramVersion); if (!p) throw new Error("Staking params not loaded"); const staking = new Staking( @@ -531,7 +540,7 @@ export const useTransactionService = () => { ); }, [ - params, + networkInfo, btcConnected, btcNetwork, address, diff --git a/src/app/state/index.tsx b/src/app/state/index.tsx index 17b4bf4e..fcb59f9c 100644 --- a/src/app/state/index.tsx +++ b/src/app/state/index.tsx @@ -2,9 +2,7 @@ import { useCallback, useMemo, useState, type PropsWithChildren } from "react"; import { useBTCTipHeight } from "@/app/hooks/api/useBTCTipHeight"; import { useOrdinals } from "@/app/hooks/api/useOrdinals"; -import { useParams } from "@/app/hooks/api/useParams"; import { useUTXOs } from "@/app/hooks/api/useUTXOs"; -import { useVersions } from "@/app/hooks/api/useVersions"; import { createStateUtils } from "@/utils/createStateUtils"; import { filterDust } from "@/utils/wallet"; import type { @@ -12,7 +10,8 @@ import type { UTXO, } from "@/utils/wallet/btc_wallet_provider"; -import { Params } from "../types/params"; +import { useNetworkInfo } from "../hooks/api/useNetworkInfo"; +import { NetworkInfo } from "../types/networkInfo"; import { DelegationState } from "./DelegationState"; import { DelegationV2State } from "./DelegationV2State"; @@ -22,7 +21,7 @@ const STATE_LIST = [DelegationState, DelegationV2State]; export interface AppState { availableUTXOs?: UTXO[]; totalBalance: number; - params?: Params; + networkInfo?: NetworkInfo; currentHeight?: number; isError: boolean; isLoading: boolean; @@ -58,16 +57,10 @@ export function AppState({ children }: PropsWithChildren) { enabled: !isUTXOLoading, }); const { - data: versions, - isLoading: isVersionLoading, - isError: isVersionError, - } = useVersions(); - - const { - data: params, - isLoading: isParamsLoading, - isError: isParamsError, - } = useParams(); + data: networkInfo, + isLoading: isNetworkInfoLoading, + isError: isNetworkInfoError, + } = useNetworkInfo(); const { data: height, @@ -77,17 +70,12 @@ export function AppState({ children }: PropsWithChildren) { // Computed const isLoading = - isVersionLoading || isHeightLoading || isUTXOLoading || isOrdinalLoading || - isParamsLoading; + isNetworkInfoLoading; const isError = - isHeightError || - isVersionError || - isUTXOError || - isOrdinalError || - isParamsError; + isHeightError || isUTXOError || isOrdinalError || isNetworkInfoError; const ordinalMap: Record = useMemo( () => @@ -122,7 +110,7 @@ export function AppState({ children }: PropsWithChildren) { availableUTXOs, currentHeight: height, totalBalance, - params, + networkInfo, isError, isLoading, ordinalsExcluded, @@ -133,7 +121,7 @@ export function AppState({ children }: PropsWithChildren) { availableUTXOs, height, totalBalance, - params, + networkInfo, isError, isLoading, ordinalsExcluded, diff --git a/src/app/types/params.ts b/src/app/types/networkInfo.ts similarity index 87% rename from src/app/types/params.ts rename to src/app/types/networkInfo.ts index ee25f86a..56d73f6b 100644 --- a/src/app/types/params.ts +++ b/src/app/types/networkInfo.ts @@ -27,7 +27,16 @@ export interface BtcEpochCheckParams { versions: BtcEpochCheckParamsVersion[]; } +export interface StakingStatus { + isStakingOpen: boolean; +} + export interface Params { bbnStakingParams: BbnStakingParams; btcEpochCheckParams: BtcEpochCheckParams; } + +export interface NetworkInfo { + stakingStatus: StakingStatus; + params: Params; +} diff --git a/src/components/delegations/DelegationList/components/Status.tsx b/src/components/delegations/DelegationList/components/Status.tsx index ee432949..125b1d4d 100644 --- a/src/components/delegations/DelegationList/components/Status.tsx +++ b/src/components/delegations/DelegationList/components/Status.tsx @@ -1,6 +1,6 @@ import { useAppState } from "@/app/state"; import { DelegationV2StakingState as state } from "@/app/types/delegationsV2"; -import { BbnStakingParamsVersion } from "@/app/types/params"; +import { BbnStakingParamsVersion } from "@/app/types/networkInfo"; import { Hint } from "@/components/common/Hint"; import { blocksToDisplayTime } from "@/utils/blocksToDisplayTime"; @@ -92,9 +92,9 @@ const STATUSES: Record< }; export function Status({ value }: StatusProps) { - const { params } = useAppState(); + const { networkInfo } = useAppState(); const { label = "unknown", tooltip = "unknown" } = - STATUSES[value](params?.bbnStakingParams?.latestParam) ?? {}; + STATUSES[value](networkInfo?.params.bbnStakingParams?.latestParam) ?? {}; return {label}; }