useLegacyBets
The useLegacyBets hook is used to fetch pre-match betting history of a specific bettor.
⚠️
The useLegacyBets hook is only for fetching old v2 Azuro Protocol bets if you need to show full betting history.
ℹ️
Hook represents a logic wrapper over TanStack Query’s useInfiniteQuery hook. Explore TanStack Query docs to understand what data the hook returns.
Usage
import { useLegacyBets } from '@azuro-org/sdk'
const { data, hasNextPage, isFetching, fetchNextPage } = useLegacyBets(props)
const { pages } = data || {}
// render pages
<>
{
pages?.map(({ bets, nextPage }) => {
return (
<React.Fragment key={`${nextPage}`}>
{
bets.map(bet => (
<BetComponent key={`${bet.createdAt}-${bet.tokenId}`} bet={bet} />
))
}
</React.Fragment>
)
})
}
<>
## Props
```ts
{
filter: {
bettor: string // bettor address
affiliate?: string // affiliate address
type?: BetType // bet type
}
itemsPerPage?: number
orderBy?: Bet_OrderBy // default: Bet_OrderBy.CreatedBlockTimestamp` - orders rows by passed rule
orderDir?: OrderDirection // order direction: asc, desc
chainId?: ChainId
query?: InfiniteQueryParameters<QueryResult>
}type ChainId =
| 100 // Gnosis
| 137 // Polygon
| 80002 // Polygon Amoy
| 88888 // Chiliz
| 88882 // Chiliz Spicy
| 8453 // Base
| 84532 // Base Sepolia
enum BetType {
Unredeemed = 'unredeemed', // ready to redeem bets
Accepted = 'accepted', // not resolved bets
Settled = 'settled', // resolved bets
CashedOut = 'cashedOut', // cashed out bets
}
type QueryResult = {
bets: Bet[],
nextPage: number | undefined,
}Return Value
UseInfiniteQueryResult<QueryResult>import { type UseInfiniteQueryResult } from '@tanstack/react-query'
type Selection = {
conditionId: string
outcomeId: string
}
type BetOutcome = {
selectionName: string
odds: number
marketName: string
game: GameQuery['games'][0] // game on which the bet is placed
isWin: boolean | null
isLose: boolean | null
isCanceled: boolean
} & Selection
type Bet = {
affiliate: string // affiliate address
tokenId: string // id of the bet's NFT
freebetId?: string | null // id of the freebet's NFT
freebetContractAddress?: Address // freebet contract address
totalOdds: number // total odds of the bet
coreAddress: Address // core contract address
lpAddress: Address // lp contract address
outcomes: BetOutcome[] // bet's outcomes list
txHash: string // bet's transaction hash
status: BetStatus // subgraph bet status
amount: string // bet's amount in USDT
possibleWin: number // possible win amount in USDT
payout: number | null // claimable amount - `null` once the bet is redeemed or cashed out; gates a redeem action
settledPayout: number | null // what the bet actually returned - stays populated after redemption; use for historical/aggregate views
cashout: string | null // cashout amount in USDT
createdAt: number // created date
isWin: boolean // flag indicates the bet's win
isLose: boolean // flag indicates the bet's lose
isRedeemable: boolean // flag indicates the possibility of redeeming the bet
isRedeemed: boolean // flag indicates whether the bet has been redeemed
isCanceled: boolean // flag indicates whether the bet has been canceled
isLive: boolean // flag indicates whether the bet is live
isCashedOut: boolean // flag indicates whether the bet is cashed out
}ℹ️
payout vs settledPayout
payout is gated on redeemability — it answers “is there money to claim?” and becomes null once
the bet is redeemed. settledPayout answers “what did this bet return?” and stays populated after
redemption. Use settledPayout for historical and aggregate views; use payout only to gate a redeem
action.