From 5630c15632fa77af68e2effe18ceb3356d1e96bb Mon Sep 17 00:00:00 2001 From: AnhMTV Date: Wed, 14 Aug 2024 12:18:38 +0700 Subject: [PATCH] [Issue-117] Restricted Access for Game By Device --- .../src/Popup/Home/Games/index.tsx | 30 +++++++++++++++++-- .../src/connector/booka/types.ts | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/extension-koni-ui/src/Popup/Home/Games/index.tsx b/packages/extension-koni-ui/src/Popup/Home/Games/index.tsx index bc26bceadc..2a84f3d3ee 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Games/index.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Games/index.tsx @@ -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'; @@ -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(() => { @@ -95,7 +121,7 @@ const Component = ({ className }: Props): React.ReactElement => { } }, 30); }; - }, [exitGame]); + }, [checkAccess, exitGame]); // @ts-ignore const onOpenShop = useCallback((gameId?: number) => { diff --git a/packages/extension-koni-ui/src/connector/booka/types.ts b/packages/extension-koni-ui/src/connector/booka/types.ts index 5e892cfe89..f72b9b0adb 100644 --- a/packages/extension-koni-ui/src/connector/booka/types.ts +++ b/packages/extension-koni-ui/src/connector/booka/types.ts @@ -83,6 +83,8 @@ export interface Game { pointConversionRate: number; gameType: 'casual' | 'farming'; leaderboard_groups: LeaderboardGroups[]; + restrictedAccess: string[] | null; + restrictedAccessText: string | null; } export enum TaskHistoryStatus {