SDK
Watch Hooks
useOutcome

Hook is used for maintain updated odds for a selection and also monitors the suspension of bets for that selection.

Whenever a bet is placed on the Azuro protocol, the system updates the odds related to the outcomes influenced by this bet. Utilize this hook to subscribe to the updated odds for the outcomes displayed in your UI. This ensures that bettors can observe the current changes and make informed betting decisions.

Conditions have a status that indicates their current state. For instance, ConditionStatus.Created signifies the condition is available for betting, while ConditionStatus.Paused indicates it has temporarily stopped accepting bets. This hook monitors this state and returns an isLocked flag, indicating whether placing a bet on this outcome is currently possible or not.

Usage

Initialize watchers in the root of your app.

import { useWatchers } from '@azuro-org/sdk'
 
export function Watchers() {
  useWatchers()
 
  return null
}

Subscribe to changes in your outcome.

import { type MarketOutcome, useOutcome } from '@azuro-org/sdk'
 
const outcome: MarketOutcome = {...}
 
const { odds, isLocked } = useOutcome({
  selection: outcome,
  initialOdds: outcome.odds,
  initialStatus: outcome.status,
})
ℹ️

Example of usage: Outcome button.

We've retrieved markets with outcomes and rendered a button for each outcome. The useOutcome hook offers a method to maintain updated odds for the outcome button and react to changes in the condition status. Full Example (opens in a new tab)

import { type MarketOutcome, useOutcome } from '@azuro-org/sdk'
 
type OutcomeProps = {
  outcome: MarketOutcome
}
 
export function OutcomeButton(props: OutcomeProps) {
  const { outcome } = props
 
  const { odds, isLocked } = useOutcome({
    selection: outcome,
    initialOdds: outcome.odds,
    initialStatus: outcome.status,
  })
 
  return (
    <button
      disabled={isLocked} // disable outcome button if isLocked is true
    >
      <span>{outcome.selectionName}</span>
      <span>{odds}</span>
    </button>
  )
}

Props

{
  selection: Selection
  initialOdds?: string
  initialStatus?: ConditionStatus
}
type Selection = {
  conditionId: string | bigint
  outcomeId: string | bigint
}
 
enum ConditionStatus {
  Canceled = 'Canceled',
  Created = 'Created',
  Paused = 'Paused',
  Resolved = 'Resolved'
}

useSelectionOdds Return Value

{
  odds: string, // outcome's odds
  isLocked: boolean // flag indicates whether placing a bet on this outcome is currently possible or not
}