Skip to content

Commit

Permalink
show overlay for games with quests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettCleary committed Oct 2, 2024
1 parent f39c2f2 commit 05af746
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/backend/ipcHandlers/quests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Quest[]> {
let url = `${DEV_PORTAL_URL}api/v1/quests?questStatus=ACTIVE`
if (projectId) {
url += `&projectId=${projectId}`
Expand All @@ -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}`)
Expand Down
23 changes: 22 additions & 1 deletion src/backend/utils/shouldOpenOverlay.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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 }
Expand All @@ -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
}
}
36 changes: 8 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down

0 comments on commit 05af746

Please sign in to comment.