Repository navigation
v8.1.0
Promo codes — useActivatePromoCode
Requires @azuro-org/toolkit@^7.1.0.
What's new
- New
useActivatePromoCode— a mutation hook that activates a promo code for the connected wallet (wagmi or
the AA connector):import { useActivatePromoCode } from '@azuro-org/sdk' import { isPromoCodeError } from '@azuro-org/toolkit' const { activate, isPending, error, reset } = useActivatePromoCode({ affiliate: '0x...', onSuccess: (freebet) => console.log(freebet.amount, freebet.chainId), }) activate({ code: 'SUMMER26' }) if (isPromoCodeError(error) && error.code === 'bonus.promo_code_expired') { // show "expired" }
- Props:
affiliate,chainId?(defaults to the app's chain),onSuccess?,onError?. Returns
{ activate, activateAsync, isPending, error, reset }. - Without a connected wallet it fails with
AuthError('NoWallet')and sends nothing. No sign-in is involved:
the activation endpoint is public, so no SIWE token is used. erroris always aPromoCodeErroror anAuthError. Unlike the toolkit function, the hook also reports a
network failure asPromoCodeError('unknown'), with the original error ascause.
- Props:
- Freebet data refreshes itself — after a successful activation the hook invalidates the wallet's
useBonuses
anduseAvailableFreebetsqueries for the freebet's own chain and your affiliate, so the betslip offers the new
freebet without a reload. It runs in the mutation's ownonSuccess, so it still happens when the component that
started the activation has unmounted (a dropdown that closed).
Note
isPromoCodeError and PromoCodeErrorCode come from @azuro-org/toolkit; the SDK doesn't re-export them. The
list of failure reasons is in the toolkit's
v7.1.0 release.
Docs:
useActivatePromoCode
promo codes guide
release notes
Full Changelog: v8.0.0...v8.1.0