fixed matches fee calc

This commit is contained in:
2026-05-12 16:32:05 +05:30
parent e5414a9920
commit fcf7654e78
5 changed files with 112 additions and 73 deletions
+14 -10
View File
@@ -18,7 +18,7 @@ import {
type MatchmakerLogSource,
} from "@/lib/matchmaker-log-source";
import { readMatchmakerLogFile } from "@/lib/matchmaker-logs-server";
import { fetchEntryHoldPerPlayerCoinsByMatchIds } from "@/lib/match-entry-hold-from-ledger";
import { fetchMatchEntryHoldAndFeePerPlayerCoinsByMatchIds } from "@/lib/match-entry-hold-from-ledger";
import type {
AdminMatchRow,
DbMatch,
@@ -144,21 +144,25 @@ export default async function Home({
matchesError = matchesRes.error.message;
} else {
const rawMatches = (matchesRes.data ?? []) as DbMatch[];
const holdByMatch = await fetchEntryHoldPerPlayerCoinsByMatchIds(
supabase,
rawMatches
.map((m) => Number(m.id))
.filter((id) => Number.isFinite(id)),
);
const { holdPerPlayer, feePerPlayer } =
await fetchMatchEntryHoldAndFeePerPlayerCoinsByMatchIds(
supabase,
rawMatches
.map((m) => Number(m.id))
.filter((id) => Number.isFinite(id)),
);
matches = rawMatches.map((m) => {
const idNum = Number(m.id);
const hold = Number.isFinite(idNum)
? holdByMatch.get(idNum)
: undefined;
const hold =
Number.isFinite(idNum) ? holdPerPlayer.get(idNum) : undefined;
const fee =
Number.isFinite(idNum) ? feePerPlayer.get(idNum) : undefined;
return {
...m,
entryHoldPerPlayerCoins:
hold !== undefined ? hold.toString() : null,
entryFeePerPlayerCoins:
fee !== undefined ? fee.toString() : null,
};
});
}