useConditionsState
The useConditionsState hook is used for maintain updated states for a conditions.
Conditions have a state field that indicates their current state. For instance, ConditionState.Created signifies the condition is available for betting, while ConditionState.Stopped indicates it has temporarily stopped accepting bets. This hook monitors this state and returns an isLocked flag, indicating whether placing a bet on this condition is currently possible or not.
Usage
Before utilizing useConditionsState, it is essential to initialize the FeedSocketProvider and ConditionUpdatesProvider:
import {
ChainProvider,
FeedSocketProvider,
ConditionUpdatesProvider,
useWatchers,
} from '@azuro-org/sdk'
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
<ChainProvider>
<FeedSocketProvider>
<ConditionUpdatesProvider>
{children}
</ConditionUpdatesProvider>
</FeedSocketProvider>
</ChainProvider>
)
}Example of usage: Game markets list (Option A).
Pass the full conditions array to get hidden state without an extra fetch.
import { useConditionsState } from '@azuro-org/sdk'
// conditions: ConditionDetailedData[] from useConditions
const { data: states, conditionsMap } = useConditionsState({ conditions })
// hide conditions that are still hidden (temporarily stopped by provider)
const visibleConditions = conditions.filter(({ conditionId }) => !conditionsMap[conditionId]?.hidden)Example of usage: Betslip (Option B).
import { useConditionsState } from '@azuro-org/sdk'
import { ConditionState } from '@azuro-org/toolkit'
import { useMemo } from 'react'
const items = [{...}]
const { data: states, isFetching: isStatesFetching } = useConditionsState({
conditionIds: items.map(({ conditionId }) => conditionId),
})
const isConditionsInActiveState = useMemo(() => {
return Object.values(states).every(state => state === ConditionState.Active)
}, [ states ])Props
Two signatures are supported:
Option A — pass full condition objects (preferred for game markets):
{
conditions: Pick<ConditionDetailedData, 'conditionId' | 'state' | 'hidden'>[]
}Option B — pass IDs only (betslip / ID-only scenarios):
{
conditionIds: string[]
initialStates?: Record<string, ConditionState> // key is conditionId
}Option A is preferred when rendering game markets — it provides initial hidden state without an extra fetch.
When using Option B, initialStates is optional. If it’s not provided, the hook will automatically fetch the initial states.
enum ConditionState {
Active = 'Active',
Canceled = 'Canceled',
Removed = 'Removed',
Resolved = 'Resolved',
Stopped = 'Stopped'
}Return Value
{
data: Record<string, ConditionState> // key is conditionId
conditionsMap: Record<string, { // key is conditionId
state: ConditionState
hidden: boolean // true while hidden; resets to false on any socket update
}>
isFetching: boolean // flag indicates initial states fetching
}The hidden field mirrors the logic in useConditionState: starts from the initial data, and clears to false when any socket update arrives for that condition.