@azuro-org/sdk
Version:
One-stop solution for building betting dApps on the Azuro Protocol.
56 lines (55 loc) • 2.67 kB
TypeScript
import { OutcomeState, type MarketOutcome, type Selection } from '@azuro-org/toolkit';
import { type OutcomeUpdateData } from '../../contexts/conditionUpdates';
export type UseOutcomesStateProps = {
selections: Selection[];
initialStates?: Record<string, OutcomeState>;
outcomes?: never;
} | {
outcomes: Pick<MarketOutcome, 'conditionId' | 'outcomeId' | 'odds' | 'state' | 'hidden'>[];
initialStates?: never;
selections?: never;
};
export type OutcomesStateData = {
states: Record<string, OutcomeState>;
/** map of `${conditionId}-${outcomeId}` to its current odds, turnover, state and hidden flag */
statesMap: Record<string, OutcomeUpdateData>;
};
/**
* Watch real-time state updates for a list of outcomes.
* Subscribes to condition updates via websocket and tracks per-outcome state changes
* (Active, Stopped, Canceled, Won, Lost) and visibility.
* Requires `FeedSocketProvider` and `ConditionUpdatesProvider` (both are included in `AzuroSDKProvider`).
*
* This is the outcome-level analog of `useConditionsState`: a single condition can hold several outcomes
* that independently become hidden or change state, so each outcome carries its own `state`/`hidden`.
*
* Returns `data` - a map of `${conditionId}-${outcomeId}` keys to their current `OutcomeState`.
* Returns `outcomesMap` - a map `{ [`${conditionId}-${outcomeId}`]: { odds, turnover, state, hidden } }`
* holding the full `OutcomeUpdateData` for each outcome (live odds/turnover plus state/hidden).
*
* The `hidden` field indicates whether an outcome should be hidden from the market's outcome list,
* independently of the condition's own `hidden` flag.
*
* - Docs: https://gem.azuro.org/hub/apps/sdk/watch-hooks/useOutcomesState
*
* @example
* import { useOutcomesState } from '@azuro-org/sdk'
* import { OutcomeState, type MarketOutcome } from '@azuro-org/toolkit'
*
* // best approach for a condition's outcomes (MarketOutcome[] from groupConditionsByMarket)
* const { data, outcomesMap, isFetching } = useOutcomesState({
* outcomes: condition.outcomes,
* })
*
* // OR if you have selections only, like in the betslip
* const { data, outcomesMap, isFetching } = useOutcomesState({
* selections: [ { conditionId: '123...', outcomeId: '1' } ],
* // optional, keyed by `${conditionId}-${outcomeId}`; fetched from the API when omitted
* initialStates: { '123...-1': OutcomeState.Active },
* })
* */
export declare const useOutcomesState: ({ selections, initialStates, outcomes }: UseOutcomesStateProps) => {
data: Record<string, OutcomeState>;
outcomesMap: Record<string, OutcomeUpdateData>;
isFetching: boolean;
};