Skip to content

v7.1.0

Choose a tag to compare

@on47sky on47sky released this 01 Oct 18:36
· 7 commits to main since this release
c819ef5

@azuro-org/toolkit v7.1.0

Promo codes — activate a code, get the freebet it grants

What's new

  • New activatePromoCode — activates an operator's promo code for a bettor and resolves with the freebet it
    issued, in the same Freebet shape getBonuses returns:
    import { activatePromoCode, isPromoCodeError } from '@azuro-org/toolkit'
    
    try {
      const freebet = await activatePromoCode({
        chainId: 137,
        code: 'SUMMER26',
        account: '0x...',
        affiliate: '0x...',
      })
    
      console.log(freebet.amount, freebet.chainId)
    }
    catch (error) {
      if (isPromoCodeError(error) && error.code === 'bonus.promo_code_already_activated') {
        // show "already used"
      }
    }
    • The code is trimmed and upper-cased before it is sent, so it can be typed in any case.
    • chainId only selects the API environment. The returned freebet's chainId is the chain of the pool the code
      pays from, which can differ from the one you passed in.
    • affiliate must be the address of the code's pool, or the activation is refused.
  • New PromoCodeError — thrown for every failure once the API has responded, with code: PromoCodeErrorCode,
    status (the HTTP status) and cause. A successful response whose body can't be read is unknown as well.
  • New isPromoCodeError — a type guard that checks name and code rather than instanceof, so it keeps
    working when two copies of the toolkit end up in one bundle.
  • New types — ActivatePromoCodeParams, ActivatePromoCodeResult, PromoCodeErrorCode.

Failure reasons (PromoCodeError.code)

Code Meaning
bonus.promo_code_not_found No such code
bonus.promo_code_deactivated The operator deactivated the code
bonus.promo_code_expired The code's expiry time has been reached
bonus.promo_code_unavailable The code's product or operator is not active
bonus.promo_code_affiliate_mismatch affiliate is not the address of the code's pool
bonus.promo_code_already_activated This address already activated this code
bonus.promo_code_limit_reached The code has used up its activation limit
bonus.promo_code_busy Another activation of the same code is in progress — safe to retry
bonus.activate_promo_code_error The activation failed on the server
unknown Anything else: validation errors, server errors, a reason this version doesn't know, an unreadable response

A Record<PromoCodeErrorCode, string> of bettor-facing messages makes TypeScript flag a missing entry whenever a
reason is added.

Note

A network failure (a rejected fetch) is not a PromoCodeError and propagates unchanged, as in every other
toolkit function — keep a generic fallback message.

Additive — getBonuses and getAvailableFreebets return exactly what they did before, and a freebet issued by a
promo code shows up in them like any other.

Docs:
activatePromoCode
promo codes guide
release notes

Full Changelog: v7.0.0...v7.1.0