diff --git a/src/lib/hypixel/general/stats.ts b/src/lib/hypixel/general/stats.ts index 9cd9ac9..d4926fa 100644 --- a/src/lib/hypixel/general/stats.ts +++ b/src/lib/hypixel/general/stats.ts @@ -1,5 +1,6 @@ import { MULTIPLIER, RANKMULTIPLIER } from "@/data/hypixel/general" import { Player } from "@/lib/schema/player" +import z from "zod" type ReturnType = { level: true @@ -66,12 +67,23 @@ export function getCoinMultiplier(level: number, rank?: string, specialRank?: st } } -export function getTotalCoins(stats: Record> | undefined) { +const coinsSchema = z.record( + z.string(), + z.object({ + coins: z.number().optional() + }) +) + +export function getTotalCoins(stats: Player["player"]["stats"]) { if (!stats) { return 0 } - return Object.values(stats).reduce((total, stat) => total + (stat.coins || 0), 0) + const { data } = coinsSchema.safeParse(stats) + + if (!data) return 0 + + return Object.values(data).reduce((total, stat) => total + (stat.coins || 0), 0) } export function getTotalQuests(quests: Player["player"]["quests"]) {