Games.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Store from "../store/store.js";
  2. import { polymarketLeaguesAndGames } from "../libs/polymarketClient.js";
  3. import { pinnacleWebLeagues, pinnacleWebGames } from "../libs/pinnacleClient.js";
  4. export const getLeagues = async () => {
  5. return Store.get('leagues');
  6. };
  7. export const getGames = async () => {
  8. return Store.get('games');
  9. };
  10. const updateData = async () => {
  11. polymarketLeaguesAndGames()
  12. .then(({ leagues, games }) => {
  13. Store.set('polymarket', leagues, 'leagues');
  14. Store.set('polymarket', games, 'games');
  15. })
  16. .then(() => {
  17. const getWebLeaguesToday = pinnacleWebLeagues(1);
  18. const getWebLeaguesTomorrow = pinnacleWebLeagues(0);
  19. return Promise.all([getWebLeaguesToday, getWebLeaguesTomorrow])
  20. })
  21. .then(data => {
  22. const leaguesMap = new Map(webLeaguesToday.concat(webLeaguesTomorrow));
  23. const leagues = Array.from(leaguesMap.values()).sort((a, b) => a.id - b.id);
  24. Store.set('pinnacle', leagues, 'leagues');
  25. })
  26. .then(() => {
  27. setTimeout(updateData, 1000 * 60);
  28. })
  29. .catch(err => {
  30. console.error(err);
  31. setTimeout(updateData, 1000 * 5);
  32. });
  33. }
  34. updateData();
  35. export default { getLeagues, getGames }