From ad204e38793b4b38e0b3cde3a65d3fd5e32b4272 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:06:27 -0300 Subject: [PATCH] fix: issues --- src/main/events/auth/get-session-hash.ts | 2 ++ src/main/events/cloud-save/get-game-artifacts.ts | 6 +++++- src/main/events/misc/open-checkout.ts | 11 ++--------- .../src/context/game-details/game-details.context.tsx | 10 +++------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/main/events/auth/get-session-hash.ts b/src/main/events/auth/get-session-hash.ts index 2a17bcf11..c9dd39cc0 100644 --- a/src/main/events/auth/get-session-hash.ts +++ b/src/main/events/auth/get-session-hash.ts @@ -9,6 +9,8 @@ const getSessionHash = async (_event: Electron.IpcMainInvokeEvent) => { if (!auth) return null; const payload = jwt.decode(auth.accessToken) as jwt.JwtPayload; + if (!payload) return null; + return payload.sessionId; }; diff --git a/src/main/events/cloud-save/get-game-artifacts.ts b/src/main/events/cloud-save/get-game-artifacts.ts index dbdcb8536..3fa8552c7 100644 --- a/src/main/events/cloud-save/get-game-artifacts.ts +++ b/src/main/events/cloud-save/get-game-artifacts.ts @@ -1,7 +1,7 @@ import { HydraApi } from "@main/services"; import { registerEvent } from "../register-event"; import type { GameArtifact, GameShop } from "@types"; -import { SubscriptionRequiredError } from "@shared"; +import { SubscriptionRequiredError, UserNotLoggedInError } from "@shared"; const getGameArtifacts = async ( _event: Electron.IpcMainInvokeEvent, @@ -22,6 +22,10 @@ const getGameArtifacts = async ( return []; } + if (err instanceof UserNotLoggedInError) { + return []; + } + throw err; }); }; diff --git a/src/main/events/misc/open-checkout.ts b/src/main/events/misc/open-checkout.ts index 5d087be00..ba48f03b8 100644 --- a/src/main/events/misc/open-checkout.ts +++ b/src/main/events/misc/open-checkout.ts @@ -1,16 +1,10 @@ import { shell } from "electron"; import { registerEvent } from "../register-event"; -import { - userAuthRepository, - userPreferencesRepository, -} from "@main/repository"; +import { userAuthRepository } from "@main/repository"; import { HydraApi } from "@main/services"; const openCheckout = async (_event: Electron.IpcMainInvokeEvent) => { - const [userAuth, userPreferences] = await Promise.all([ - userAuthRepository.findOne({ where: { id: 1 } }), - userPreferencesRepository.findOne({ where: { id: 1 } }), - ]); + const userAuth = await userAuthRepository.findOne({ where: { id: 1 } }); if (!userAuth) { return; @@ -22,7 +16,6 @@ const openCheckout = async (_event: Electron.IpcMainInvokeEvent) => { const params = new URLSearchParams({ token: paymentToken, - lng: userPreferences?.language || "en", }); shell.openExternal( diff --git a/src/renderer/src/context/game-details/game-details.context.tsx b/src/renderer/src/context/game-details/game-details.context.tsx index 09ac7257d..9242d9a6a 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -117,11 +117,7 @@ export function GameDetailsContextProvider({ abortControllerRef.current = abortController; window.electron - .getGameShopDetails( - objectId!, - shop as GameShop, - getSteamLanguage(i18n.language) - ) + .getGameShopDetails(objectId, shop, getSteamLanguage(i18n.language)) .then((result) => { if (abortController.signal.aborted) return; @@ -140,14 +136,14 @@ export function GameDetailsContextProvider({ setIsLoading(false); }); - window.electron.getGameStats(objectId, shop as GameShop).then((result) => { + window.electron.getGameStats(objectId, shop).then((result) => { if (abortController.signal.aborted) return; setStats(result); }); if (userDetails) { window.electron - .getUnlockedAchievements(objectId, shop as GameShop) + .getUnlockedAchievements(objectId, shop) .then((achievements) => { if (abortController.signal.aborted) return; setAchievements(achievements);