diff --git a/src/env.ts b/src/env.ts index 948f8cf..fbb3f46 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,2 +1,5 @@ export const API_URL = 'https://api_drmmina.kadircan.org/'; -export const WEB_URL = 'https://drm-mina.kadircan.org/'; +export const WEB_URL = + process.env.NODE_ENV === 'development' + ? 'http://localhost:3000/' + : 'https://drm-mina.kadircan.org/'; diff --git a/src/renderer/lib/api.ts b/src/renderer/lib/api.ts index 21f6d41..8675008 100644 --- a/src/renderer/lib/api.ts +++ b/src/renderer/lib/api.ts @@ -54,3 +54,26 @@ export async function fetchWishlist(userPubKey: string) { } return json; } + +export async function fetchComments( + gameId: number, + page: number = 1, + limit: number = 10, +): Promise { + const headers = { 'Content-Type': 'application/json' }; + const res = await fetch( + `${API_URL}comments/${gameId}?page=${page}&limit=${limit}`, + { + headers, + method: 'GET', + }, + ); + if (!res.ok) { + const errorResponse = await res.json(); + console.error(errorResponse.message); + throw new Error(`Failed to fetch comments: ${errorResponse.message}`); + } + + const json = await res.json(); + return json; +} diff --git a/src/renderer/lib/globals.d.ts b/src/renderer/lib/globals.d.ts index 237ff95..ebcd025 100644 --- a/src/renderer/lib/globals.d.ts +++ b/src/renderer/lib/globals.d.ts @@ -11,41 +11,25 @@ interface Game { discount: number; tags: string[]; downloadable: boolean; + averageRating: number; + ratingCount: number; } - -interface GamePrices { - data: { - runtime: { - GameToken: { - gamePrice: { - value: string | null; - }; - discount: { - value: string | null; - }; - }; - }; - }; -} - -interface GameNumber { - data: { - runtime: { - GameToken: { - totalGameNumber: { - value: string | null; - }; - }; - }; - }; +interface RawIdentifiers { + cpuId: string; + systemSerial: string; + systemUUID: string; + baseboardSerial: string; + macAddress: string[]; + diskSerial: string; } - -interface Library { - data: { - runtime: { - GameToken: { - users: boolean | null; - }; - }; +interface IComment { + _id: string; + user: { + publicKey: string; + _id: string; }; + gameId: number; + content: string; + rating: number; + createdAt: string; } diff --git a/src/renderer/lib/utils.ts b/src/renderer/lib/utils.ts new file mode 100644 index 0000000..028637a --- /dev/null +++ b/src/renderer/lib/utils.ts @@ -0,0 +1,18 @@ +export function base58Decode(input: string): number { + const alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; + const base = BigInt(58); + let result = BigInt(0); + + for (let i = 0; i < input.length; i++) { + const char = input[i]; + const index = alphabet.indexOf(char); + + if (index === -1) { + throw new Error(`Invalid Base58 character '${char}' at position ${i}`); + } + + result = result * base + BigInt(index); + } + + return Number(result % BigInt(Number.MAX_SAFE_INTEGER)); +}