fix(api): align API layer with backend response formats

- wallet: parse {balance: string} response
- favorites: addFavorite returns void (EmptyResp)
- services: handle paginated response from listServicesByPlayer
- files: use query param ?key= instead of path param /:id
- search: remove unsupported selectedGames/minRating params
This commit is contained in:
zetaloop
2026-04-23 21:14:57 +08:00
parent ca4bef959f
commit 4037816998
5 changed files with 22 additions and 18 deletions
+9 -6
View File
@@ -26,19 +26,22 @@ function withOffsetLimit(path: string, options?: ListWalletTransactionsOptions):
return `${path}?${searchParams.toString()}`
}
function unwrapWalletBalance(value: unknown): number | undefined {
if (typeof value === "number") return value
if (typeof value !== "object" || value === null) return undefined
type WalletBalanceResponse = {
balance: string
frozenBalance?: string
}
const v = value as { balance?: unknown; amount?: unknown }
function parseBalance(value: unknown): number | undefined {
if (typeof value !== "object" || value === null) return undefined
const v = value as WalletBalanceResponse
if (typeof v.balance === "string") return Number(v.balance)
if (typeof v.balance === "number") return v.balance
if (typeof v.amount === "number") return v.amount
return undefined
}
export async function getWalletBalance(): Promise<number> {
const res = await httpJson<unknown>("/api/v1/wallet/balance", { cache: "no-store" })
const balance = unwrapWalletBalance(res)
const balance = parseBalance(res)
if (balance === undefined) {
throw new Error("Invalid wallet balance response")
}