SDK
Write Hooks
usePrepareBet

Hook is used for place a bet and approve tokens spending if necessary.

Usage

import { usePrepareBet } from '@azuro-org/sdk'
 
const {
  totalOdds,
  approveTx,
  betTx,
  submit,
  isApproveRequired,
  isOddsLoading,
  isAllowanceLoading,
} = usePrepareBet({
  amount: '10',
  slippage: 5,
  affiliate: '0x0000000000000000000000000000000000000000',
  selections: [
    {
      conditionId: '486903008559711340',
      outcomeId: '29',
    },  
  ],
})
 
submit()

Props

{
  amount: string // bet amount
  slippage: number // 5%
  affiliate: Address // your affiliate address
  selections: Selection[] // user's choise for bet
  deadline?: number // duration after which the bet will be canceled if it does not get included in a block
  onSuccess?(receipt: TransactionReceipt): void // callback function triggered after a successful bet
  onError?(err?: Error): void // callback function triggered upon encountering an error
}
type Selection = {
  conditionId: string | bigint
  outcomeId: string | bigint
}

Return Value

{
  isAllowanceLoading: boolean // flag indicates the fetching of allowance
  isApproveRequired: boolean // flag indicates the necessity for token spending approval
  isOddsLoading: boolean // flag indicates the fetching of selection's odds
  selectionsOdds: string[] // array containing odds for the provided selections
  totalOdds: string // tatal odds for the provided selections
  submit: () => Promise<TransactionReceipt> // function used to trigger the bet action or token spending approval
  approveTx: { // approve transaction data
    isPending: boolean
    isProcessing: boolean
    data: WriteContractResult | null
    error: Error | null
  }
  betTx: { // bet transaction data
    isPending: boolean
    isProcessing: boolean
    data: WriteContractResult | null
    error: Error | null
  }
}