Developer Hub
🔮 For applications
SDK
Providers
Betslip

The BetslipProvider serves the purpose of storing a user's bet before its execution, while additionally furnishing information regarding odds and statuses.

Usage

Wrap your application in BetslipProvider.

import { ChainProvider, LiveProvider, ApolloProvider, SocketProvider, BetslipProvider } from '@azuro-org/sdk'
import { WagmiProvider, createConfig } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { polygonAmoy } from 'viem/chains'
 
 
const wagmiConfig = createConfig(config)
const queryClient = new QueryClient() 
 
function Providers(props: { children: React.ReactNode }) {
  const { children } = props
 
  return (
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}> 
        <ChainProvider initialChainId={polygonAmoy.id}>
          <LiveProvider initialLiveState={initialLiveState}>
            <ApolloProvider>
              <SocketProvider>
                <BetslipProvider>
                  {children}
                </BetslipProvider>
              </SocketProvider>
            </ApolloProvider>
          </LiveProvider>
        </ChainProvider>
      </QueryClientProvider>
    </WagmiProvider>
  )
}
ℹ️

The AzuroSDKProvider incorporates the BetslipProvider along with all associated providers.

⚠️

The BetslipProvider necessitates access to the ChainProvider, ApolloProvider, and SocketProvider.

Get stored context data.

import { useBaseBetslip, useDetailedBetslip } from '@azuro-org/sdk'
 
const { items, addItem, removeItem, clear } = useBaseBetslip()
const { 
  betAmount, odds, totalOdds, maxBet, minBet, statuses, disableReason, changeBetAmount, 
  isStatusesFetching, isOddsFetching, isBetAllowed 
} = useDetailedBetslip()
ℹ️

The useBaseBetslip hook is employed to gain access to items and facilitate their modification, while the useDetailedBetslip hook is utilized for obtaining additional information such as odds and statuses.

ℹ️

The odds is an object where the key combination is determined by the concatenation of conditionId and outcomeId:

odds[`${conditionId}-${outcomeId}`]
ℹ️

The statuses is an object where the key combination corresponds to conditionId:

statuses[conditionId]
ℹ️

Except of Single and Combo bets for Batch bet we use different amount structure batchBetAmounts.

The batchBetAmounts is an object where the key combination is determined by the concatenation of conditionId and outcomeId, the value is bet amount for outcome:

const selectionAmount = batchBetAmounts[`${conditionId}-${outcomeId}`]

Props

type BetslipProviderProps = {
  children: React.ReactNode
  affiliate?: Address // only for freeBets fetching
  isBatchBetWithSameGameEnabled?: boolean // if value is true betslip will allow to add outcomes from same game for batch bet
}

Return Value

type BaseBetslipContextValue = {
  items: BetslipItem[] // betslip items
  addItem: (itemProps: AddItemProps) => void // function for adding new items
  removeItem: (itemProps: RemoveItemProps) => void // function for removing item from betslip
  clear: () => void // function for clearing betslip
}
 
type DetailedBetslipContextValue = {
  betAmount: string // bet amount for single and combo bet
  batchBetAmounts: Record<string, string> // batch bet amounts
  odds: Record<string, number> // odds for each item
  totalOdds: number // total bet odds
  maxBet: number | undefined // maximum bet amount
  minBet: number | undefined // minimum bet amount
  selectedFreeBet: FreeBet | undefined // selected freeBet
  freeBets: FreeBet[] | undefined | null // list of freeBets
  statuses: Record<string, ConditionStatus> // status for each item
  disableReason: BetslipDisableReason | undefined // reason for prohibiting the bet
  changeBetAmount: (value: string) => void // function for changing bet amount
  changeBatchBetAmount: (item: changeBatchBetAmountItem, value: string) => void // function for changing bet amount for batch bet
  changeBatch: (value: boolean) => void // function for switching between combo and batch
  selectFreeBet: (value?: FreeBet) => void // set freeBet as selected
  isBatch: boolean // true if batch is enabled
  isLiveBet: boolean // true if live outcome in the betslip
  isCombo: boolean // true if combo bet
  isStatusesFetching: boolean // indicates statuses fetching
  isOddsFetching: boolean // indicates odds fetching
  isFreeBetsFetching: boolean // indicates freeBets fetching
  isBetAllowed: boolean // true if bet can be placed
}
 
enum BetslipDisableReason {
  ConditionStatus = 'ConditionStatus', // one or more outcomes have been removed or suspended
  BetAmountGreaterThanMaxBet = 'BetAmountGreaterThanMaxBet', // bet amount exceeds max bet
  BetAmountLowerThanMinBet = 'BetAmountLowerThanMinBet', // bet amount lower than min bet
  ComboWithLive = 'ComboWithLive', // live outcome can't be used in combo
  ComboWithForbiddenItem = 'ComboWithForbiddenItem', // one or more conditions can't be used in combo
  ComboWithSameGame = 'ComboWithSameGame', // outcomes from same game can't be used in combo
  PrematchConditionInStartedGame = 'PrematchConditionInStartedGame', // pre-match item in started game
  BatchWithLive = 'BatchWithLive', // live outcome can't be used in batch
  FreeBetWithLive = 'FreeBetWithLive', // freeBet can't be used in live
  FreeBetWithCombo = 'FreeBetWithCombo', // freeBet can't be used in combo
  FreeBetWithBatch = 'FreeBetWithBatch', // freeBet can't be used in batch
  FreeBetExpired = 'FreeBetExpired', // freeBet is expired
  FreeBetMinOdds = 'FreeBetMinOdds', // selection's odds is low for freeBet
}
 
type Game = {
  gameId: string
  countryName: string
  countrySlug: string
  leagueName: string
  leagueSlug: string
  participants: Array<{
    name: string
    image?: string
  }>
  startsAt: number
  sportId: number
  sportSlug: string
  sportName: string
}
 
type Selection = {
  outcomeId: string
  conditionId: string
  coreAddress: string
}
 
type BetslipItem = {
  lpAddress: string
  game: Game
  isExpressForbidden: boolean
} & Selection
 
type AddItemProps = {
  gameId: string
  lpAddress: string
  isExpressForbidden: boolean
} & Selection
 
type RemoveItemProps = {
  outcomeId: string
  conditionId: string
}
 
type ChangeBatchBetAmountItem = {
  outcomeId: string
  conditionId: string
}