⚠️
Important! We’ve moved to V3! This documentation is for V2 only and will be updated in May.
Developer Hub
🔮 For applications
SDK
Providers
Betslip

BetslipProvider

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

⚠️

Batch bet and Freebets currently unavailable!

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}>
          <FeedSocketProvider>
            <GameUpdatesProvider>
              <ConditionUpdatesProvider>
                <BetslipProvider>
                  {children}
                </BetslipProvider>
              </ConditionUpdatesProvider>
            </GameUpdatesProvider>
          </FeedSocketProvider>
        </ChainProvider>
      </QueryClientProvider>
    </WagmiProvider>
  )
}
ℹ️

The AzuroSDKProvider incorporates the BetslipProvider along with all associated providers.

⚠️

The BetslipProvider necessitates access to the ChainProvider, ApolloProvider, and Socket Providers.

Accessing Betslip Context

import { useBaseBetslip, useDetailedBetslip } from '@azuro-org/sdk'
 
const { items, addItem, removeItem, clear } = useBaseBetslip()
const { betAmount, odds} = 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 states.

ℹ️

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

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

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

states[conditionId]

Storing additional data

You can extend the betslip item in your global.d.ts to suit your needs by adding additional fields to the BetslipItem interface. This allows you to customize the data structure and store extra information as required for your application:

  1. Expand a namespace in global in your global.d.ts file:
global.d.ts
declare global {
  namespace AzuroSDK {
    interface BetslipItem {
      marketName: string
      selectionName: string
    }
  }
}
  1. That’s it! Now you can provide additional data:
const { addItem } = useBaseBetslip()
 
addItem({
  conditionId: '...',
  outcomeId: '...',
  gameId: '...',
  isExpressForbidden: true,
  marketName: 'FTB',
  selectionName: '1',
})

Example can be found here (opens in a new tab).

Props

type BetslipProviderProps = {
  children: React.ReactNode
}

Return Value

type BaseBetslipContextValue = {
  items: AzuroSDK.BetslipItem[] // betslip items
  addItem: (itemProps: AzuroSDK.BetslipItem) => 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
  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
  states: Record<string, ConditionState> // status for each item
  disableReason: BetslipDisableReason | undefined // reason for prohibiting the bet
  changeBetAmount: (value: string) => void // function for changing bet amount
  isCombo: boolean // true if combo bet
  isStatesFetching: boolean // indicates states fetching
  isOddsFetching: boolean // indicates odds fetching
  isMaxBetFetching: boolean // indicates max bet fetching
  isBetAllowed: boolean // true if bet can be placed
}
 
enum BetslipDisableReason {
  ConditionState = 'ConditionState', // one or more outcomes have been removed or suspended
  BetAmountGreaterThanMaxBet = 'BetAmountGreaterThanMaxBet', // bet amount exceeds max bet
  BetAmountLowerThanMinBet = 'BetAmountLowerThanMinBet', // bet amount lower than min bet
  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
}
 
declare global {
  namespace AzuroSDK {
    interface BetslipItem extends Selection {
      gameId: string
      isExpressForbidden: boolean
    }
  }
}
 
type Selection = {
  outcomeId: string
  conditionId: string
  coreAddress: string
}
 
type AddItemProps = {
  gameId: string
  lpAddress: string
  isExpressForbidden: boolean
} & Selection
 
type RemoveItemProps = Selection