import log from "../../log.js"; import { CustomWinAnimation, displayCommunityJackpotWin, displayJackpotWinInterface, notificationTypeEnum, winResponse } from "../../types.js"; import events from "../events/index.js"; import jackpot from "../jackpot/index.js"; import displayAnimation from "./1.js"; import { widgetDOM } from "../widget/model.js"; import media from "../widget/media.js"; import texts from "../widget/texts.js"; export function displayMainWinner(props: CustomWinAnimation) { const propsDefault = { lottieUrl: 'https://joobacdn.pages.dev/cdn/lottie/coinsFalling.json', cssUrl: 'https://joobacdn.pages.dev/cdn/styles/winAnimation/default.css' } const delay = setTimeout(() => { if (widgetDOM.widgetInfoLabelWrapper) { widgetDOM.widgetInfoLabelWrapper.innerHTML = '' } log('action: display winner') displayAnimation(props || propsDefault) clearTimeout(delay) }, 1500); } export function displayCommunityWin(props?: displayCommunityJackpotWin) { media.set(props?.mediaProps || { key: 'widget', src: 'https://joobacdn.pages.dev/cdn-v2/lottie/coins1.json', type: 'lottie', }) const infoLabel = document.createElement('p'); infoLabel.innerHTML = props?.message || texts.get().communityJackpotWin; widgetDOM.widgetMediaWrapper.style.position = 'relative' widgetDOM.widgetMediaWrapper.style.zIndex = '99999' widgetDOM.widgetInfoLabelWrapper.innerHTML = ''; widgetDOM.widgetInfoLabelWrapper.appendChild(infoLabel); } export function displayJackpotWin(props?: displayJackpotWinInterface) { media.set(props?.mediaProps || { key: 'widget', src: 'https://joobacdn.pages.dev/cdn-v2/lottie/coins1.json', type: 'lottie', }) const infoLabel = document.createElement('p'); infoLabel.innerHTML = props?.message || texts.get().communityJackpotWin; widgetDOM.widgetMediaWrapper.style.position = 'relative' widgetDOM.widgetMediaWrapper.style.zIndex = '99999' widgetDOM.widgetInfoLabelWrapper.innerHTML = ''; widgetDOM.widgetInfoLabelWrapper.appendChild(infoLabel); } export function defineAndDisplayWin(winResponse: winResponse, updateAmount: (currentAmount: number, amount: number) => null | undefined) { const { amount, notificationType } = winResponse const { amount: currentAmount } = jackpot.get() if (amount) { jackpot.update('amount', amount) updateAmount(currentAmount, amount) } if (notificationType === notificationTypeEnum.COMMUNITY_MAIN || notificationType === notificationTypeEnum.NORMAL_MAIN && !jackpot.get()?.userWin) { jackpot.update('userWin', true) if (!events.customs().userWin) { displayMainWinner({ lottieUrl: 'https://joobacdn.pages.dev/cdn/lottie/coinsFalling.json', cssUrl: 'https://joobacdn.pages.dev/cdn/styles/winAnimation/default.css' }) } events.callback('userWin', { winResponse, displayMainWinner }) const timeout = setTimeout(() => { jackpot.update('userWin', false) clearTimeout(timeout) }, 30000); // 30 seconds to remove the winner status } else if (notificationType === notificationTypeEnum.COMMUNITY_POOL) { if (!events.customs().communityWin) { displayCommunityWin() } events.callback('communityWin', { winResponse, displayCommunityWin }) } else if (notificationType === notificationTypeEnum.NORMAL_INFORMED) { if (!events.customs().jackpotWin) { displayJackpotWin() } events.callback('jackpotWin', { winResponse, displayJackpotWin }) } }