Skip to content

Commit

Permalink
[Issue-117] Restricted Access for Game By Device
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Aug 14, 2024
1 parent 8152b90 commit 5630c15
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/extension-koni-ui/src/Popup/Home/Games/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { WalletModalContext } from '@subwallet/extension-koni-ui/contexts/Wallet
import { useSetCurrentPage } from '@subwallet/extension-koni-ui/hooks';
import { GameApp } from '@subwallet/extension-koni-ui/Popup/Home/Games/gameSDK';
import { ThemeProps } from '@subwallet/extension-koni-ui/types';
import { populateTemplateString } from '@subwallet/extension-koni-ui/utils';
import { isDesktop, isMobile, populateTemplateString } from '@subwallet/extension-koni-ui/utils';
import { ModalContext } from '@subwallet/react-ui';
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -76,8 +76,34 @@ const Component = ({ className }: Props): React.ReactElement => {
}, 600);
}, []);

const checkAccess = useCallback((game: Game) => {
const restrictedAccess = game.restrictedAccess || [];

if (restrictedAccess.length > 0) {
if (isDesktop() && restrictedAccess.indexOf('desktop') > -1) {
return false;
}

if (isMobile() && restrictedAccess.indexOf('mobile') > -1) {
return false;
}
}

return true;
}, []);

const playGame = useCallback((game: Game) => {
return () => {
if (!checkAccess(game)) {
const alertContent = game.restrictedAccessText || 'This game is not available on your device';

telegramConnector.showAlert(alertContent, () => {
// Do nothing
});

return;
}

setCurrentGame(game);

const checkInterval = setInterval(() => {
Expand All @@ -95,7 +121,7 @@ const Component = ({ className }: Props): React.ReactElement => {
}
}, 30);
};
}, [exitGame]);
}, [checkAccess, exitGame]);

// @ts-ignore
const onOpenShop = useCallback((gameId?: number) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/extension-koni-ui/src/connector/booka/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export interface Game {
pointConversionRate: number;
gameType: 'casual' | 'farming';
leaderboard_groups: LeaderboardGroups[];
restrictedAccess: string[] | null;
restrictedAccessText: string | null;
}

export enum TaskHistoryStatus {
Expand Down

0 comments on commit 5630c15

Please sign in to comment.