Skip to content

Betting events

The SPA provides an API that allows users to subscribe to various user-related events, such as login, logout, among others. Once subscribed to an event, they can implement custom logic to handle it as needed.

redirect

Description: Trigger at the moment of performing the actions specified in the Destination; it must be possible to set the transition via external routes.

1
2
3
4
5
6
7
8
9
interface RedirectPayload {
  destination: Destination;
  link: string;
}

enum Destination {
  Login = 'login',
  Logout = 'logout',
}

Example: This event is typically used to trigger the opening of a login modal when an unauthorized user attempts to place a bet

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
bettingAPI.subscribe('redirect', ({ destination, link }) => {
  switch (destination) {
    // at the moment only two values are available for the 'destination'
    case 'login': {
      window.location.href = '#!/auth/signin?popup';
    }
    case 'logout': {
      window.location.href = '#!/auth/signout';
    }
    // after handling login and logout events you should execute window.location.reload()
    default: {
      break;
    }
  }
});

handle-not-enough-balance

Description: Trigger when a player does not have enough funds to make a bet. The integrator can handle the case where the user needs to deposit more funds.

1
2
3
interface HandleNotEnoughBalancePayload {
  deposit: string;
}

Example: This event is typically used to trigger the opening of a deposit modal

1
2
3
bettingAPI.subscribe('handle-not-enough-balance', ({ deposit }) => {
  console.error(`Not enough balance, deposit: ${deposit}`);
});

toggle-widget-betslip

Description: Trigger when a player opens or close the betslip widget

1
2
3
interface ToggleWidgetBetslipPayload {
  isOpen: boolean;
}

Example: The integrator can use this event to handle UI changes, such as enabling/disabling scrolling on mobile devices.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
bettingAPI.subscribe('toggle-widget-betslip', (payload) => {
  const el = document.getElementById('betting-betslip-mobile');

  if (el && payload.isOpen) {
    el.style.setProperty('top', ' 0');
    el.style.setProperty('bottom', 'initial');
    el.style.setProperty('height', '100%');
    document.body.classList.add('betting-fixed-body');
  }

  if (el && !payload.isOpen) {
    el.style.setProperty('top', null);
    el.style.setProperty('bottom', '0');
    el.style.setProperty('height', null);
    document.body.classList.remove('betting-fixed-body');
  }
});