Skip to content

v8.1.0

Choose a tag to compare

@on47sky on47sky released this 01 Oct 18:37
· 10 commits to main since this release
3555a73

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.
    • error is always a PromoCodeError or an AuthError. Unlike the toolkit function, the hook also reports a
      network failure as PromoCodeError('unknown'), with the original error as cause.
  • Freebet data refreshes itself — after a successful activation the hook invalidates the wallet's useBonuses
    and useAvailableFreebets queries 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 own onSuccess, 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