From 05af7466f9bf97ea27f00e70b8fd133f8c489cef Mon Sep 17 00:00:00 2001 From: Brett <27568879+BrettCleary@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:12:13 -0700 Subject: [PATCH] show overlay for games with quests --- package.json | 1 + src/backend/ipcHandlers/quests.ts | 9 ++++--- src/backend/utils/shouldOpenOverlay.ts | 23 +++++++++++++++- yarn.lock | 36 ++++++-------------------- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 332080924..d7d713ebe 100644 --- a/package.json +++ b/package.json @@ -183,6 +183,7 @@ "@sentry/electron": "^4.24.0", "@sentry/react": "7.50.0", "@shockpkg/icon-encoder": "^2.1.3", + "@tanstack/query-core": "^5.59.0", "@tanstack/react-query": "^5.51.23", "@walletconnect/browser-utils": "^1.8.0", "@walletconnect/ethereum-provider": "^2.10.6", diff --git a/src/backend/ipcHandlers/quests.ts b/src/backend/ipcHandlers/quests.ts index 5a22bf5af..f5c637b2c 100644 --- a/src/backend/ipcHandlers/quests.ts +++ b/src/backend/ipcHandlers/quests.ts @@ -4,11 +4,12 @@ import { DEV_PORTAL_URL } from 'common/constants' import { ConfirmClaimParams, GenericApiResponse, - PointsClaimReturn + PointsClaimReturn, + Quest } from 'common/types' import { app, ipcMain } from 'electron' -ipcMain.handle('getQuests', async (e, projectId) => { +export async function getQuests(projectId?: string): Promise { let url = `${DEV_PORTAL_URL}api/v1/quests?questStatus=ACTIVE` if (projectId) { url += `&projectId=${projectId}` @@ -29,7 +30,9 @@ ipcMain.handle('getQuests', async (e, projectId) => { questsMetaJson = questsMetaJson.concat(testQuestsMetaJson) } return questsMetaJson -}) +} + +ipcMain.handle('getQuests', async (e, projectId) => getQuests(projectId)) ipcMain.handle('getQuest', async (e, questId) => { const questResult = await fetch(`${DEV_PORTAL_URL}api/v1/quests/${questId}`) diff --git a/src/backend/utils/shouldOpenOverlay.ts b/src/backend/utils/shouldOpenOverlay.ts index 9ba4e6bab..617b97ee6 100644 --- a/src/backend/utils/shouldOpenOverlay.ts +++ b/src/backend/utils/shouldOpenOverlay.ts @@ -1,3 +1,5 @@ +import { QueryCache, QueryClient } from '@tanstack/query-core' +import { getQuests } from 'backend/ipcHandlers/quests' import { getHyperPlayNameToReleaseMap } from 'backend/storeManagers/hyperplay/utils' import { GameInfo } from 'common/types' @@ -13,6 +15,16 @@ export async function gameIsEpicForwarderOnHyperPlay(gameInfo: GameInfo) { return { hyperPlayListing, gameIsEpicForwarderOnHP } } +const queryClient = new QueryClient({ + queryCache: new QueryCache(), + defaultOptions: { + queries: { + staleTime: 1000 * 60 * 5, // Cache the data for 5 minutes + retry: 1 // Retry failed request once + } + } +}) + export async function launchingGameShouldOpenOverlay(gameInfo?: GameInfo) { if (!gameInfo) { return { shouldOpenOverlay: false } @@ -22,11 +34,20 @@ export async function launchingGameShouldOpenOverlay(gameInfo?: GameInfo) { const gameIsDirectOnHyperPlay = gameInfo.runner === 'hyperplay' const gameIsSideloadedWithWeb3 = gameInfo.runner === 'sideload' && !!gameInfo.web3?.supported + + const quests = await queryClient.fetchQuery({ + queryKey: ['getQuests'], + queryFn: async () => getQuests(gameInfo.app_name) + }) + const gameHasAnActiveQuest = + quests.findIndex((val) => val.project_id === gameInfo.app_name) >= 0 + return { shouldOpenOverlay: gameIsDirectOnHyperPlay || gameIsSideloadedWithWeb3 || - gameIsEpicForwarderOnHP, + gameIsEpicForwarderOnHP || + gameHasAnActiveQuest, hyperPlayListing } } diff --git a/yarn.lock b/yarn.lock index a95e1359b..9bcaa572e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3042,6 +3042,11 @@ resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.52.2.tgz#a023864a892fda9858b724d667eb19cd84ce054a" integrity sha512-9vvbFecK4A0nDnrc/ks41e3UHONF1DAnGz8Tgbxkl59QcvKWmc0ewhYuIKRh8NC4ja5LTHT9EH16KHbn2AIYWA== +"@tanstack/query-core@^5.59.0": + version "5.59.0" + resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.59.0.tgz#d8323f1c6eb0e573ab0aa85a7b7690d0c263818a" + integrity sha512-WGD8uIhX6/deH/tkZqPNcRyAhDUqs729bWKoByYHSogcshXfFbppOdTER5+qY7mFvu8KEFJwT0nxr8RfPTVh0Q== + "@tanstack/react-query@^5.51.23": version "5.52.2" resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.52.2.tgz#3fffbc86351edcaeec335bc8958bcab4204bd169" @@ -12533,16 +12538,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -12643,14 +12639,7 @@ stringify-entities@^4.0.0: character-entities-html4 "^2.0.0" character-entities-legacy "^3.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -13917,7 +13906,7 @@ word-wrap@^1.2.5: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -13935,15 +13924,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"