Determines the current status of a bet based on order state, on-chain status, and game states. Returns a unified bet status that combines API order state and blockchain data.

This helper extends the BetStatus from the subgraph. However, it’s noticeable that there might not be sufficient statuses to create a detailed UI representation of the bet state. For instance, there might be ambiguity in understanding what occurred with the bet between the ‘Accepted’ and ‘Resolved’ statuses.

enum GraphBetStatus {
  Accepted = 'Accepted', // bet was accepted on-chain
  Resolved = 'Resolved', // bet was resolved
  Canceled = 'Canceled' // bet was canceled
}

We’ve introduced additional statuses to provide more granular state information:

enum BetStatus {
  Accepted,         // same as GraphBetStatus.Accepted
  Live,             // if at least one game is live
  PendingResolution,// if at least one game is pending resolution
  Resolved,         // same as GraphBetStatus.Resolved
  Canceled,         // same as GraphBetStatus.Canceled or BetOrderState.Canceled
  Preparing,        // bet is being created/placed (pending API processing - BetOrderState.Created | BetOrderState.Placed | BetOrderState.Sent)
  Rejected,         // bet order was rejected (BetOrderState.Rejected)
}

Usage

import { getBetStatus, BetStatus } from '@azuro-org/toolkit'
 
const games = [
  { state: GameState.Live, startsAt: '1234567890' },
]
const orderState = BetOrderState.Sent
const graphStatus = GraphBetStatus.Accepted
 
const status = getBetStatus({ games, orderState, graphStatus })
 
if (status === BetStatus.Live) {
  console.log('Bet is live!')
}

Props

{
  games: Array<{
    state: GameState
    startsAt: string
  }>
  orderState: BetOrderState | null
  graphStatus: GraphBetStatus | null
}

Return Value

enum BetStatus {
  Accepted,
  Live,
  PendingResolution,
  Resolved,
  Canceled,
  Preparing,
  Rejected,
}