fixed matches fee calc
This commit is contained in:
@@ -4,6 +4,40 @@ import Link from "next/link";
|
||||
import { ClickableUserId } from "@/components/clickable-user-id";
|
||||
import { formatRcLabelFromCoinsBigInt } from "@/lib/coins-rc";
|
||||
|
||||
/** Ledger rows are per player; both players pay → show `1.0 RC x 2 = 2.0 RC`. */
|
||||
function rcPerPlayerTimesTwoLine(coinStr: string | null): string {
|
||||
if (coinStr == null || String(coinStr).trim() === "") return "—";
|
||||
try {
|
||||
const perPlayer = BigInt(String(coinStr).trim());
|
||||
const bothPlayers = perPlayer * BigInt(2);
|
||||
return `${formatRcLabelFromCoinsBigInt(perPlayer)} x 2 = ${formatRcLabelFromCoinsBigInt(bothPlayers)}`;
|
||||
} catch {
|
||||
return "—";
|
||||
}
|
||||
}
|
||||
|
||||
function entryCombinedPerPlayerTimesTwoLine(
|
||||
feeCoins: string | null,
|
||||
holdCoins: string | null,
|
||||
): string {
|
||||
if (
|
||||
feeCoins == null ||
|
||||
holdCoins == null ||
|
||||
String(feeCoins).trim() === "" ||
|
||||
String(holdCoins).trim() === ""
|
||||
) {
|
||||
return "—";
|
||||
}
|
||||
try {
|
||||
const perPlayer =
|
||||
BigInt(String(feeCoins).trim()) + BigInt(String(holdCoins).trim());
|
||||
const bothPlayers = perPlayer * BigInt(2);
|
||||
return `${formatRcLabelFromCoinsBigInt(perPlayer)} x 2 = ${formatRcLabelFromCoinsBigInt(bothPlayers)}`;
|
||||
} catch {
|
||||
return "—";
|
||||
}
|
||||
}
|
||||
|
||||
type PlayerSide = {
|
||||
id: number | null;
|
||||
username: string | null;
|
||||
@@ -16,7 +50,7 @@ type Props = {
|
||||
matchId: number;
|
||||
statusLabel: string;
|
||||
createdAtLabel: string;
|
||||
/** `matches.entry_fee` as coin string (bigint); RC shown in footer. */
|
||||
/** Ledger `entry_fee` / player as coin string; null if unknown. */
|
||||
entryFeeCoins: string | null;
|
||||
/** Ledger `entry_hold` / player as coin string; null if unknown. */
|
||||
entryHoldPerPlayerCoins: string | null;
|
||||
@@ -28,35 +62,6 @@ type Props = {
|
||||
winnerId: number | string | null;
|
||||
};
|
||||
|
||||
function rcLabelFromCoinString(s: string | null): string {
|
||||
if (s == null || String(s).trim() === "") return "—";
|
||||
try {
|
||||
return formatRcLabelFromCoinsBigInt(BigInt(String(s).trim()));
|
||||
} catch {
|
||||
return "—";
|
||||
}
|
||||
}
|
||||
|
||||
function entryTotalRcLabel(
|
||||
feeCoins: string | null,
|
||||
holdCoins: string | null,
|
||||
): string {
|
||||
if (
|
||||
feeCoins == null ||
|
||||
holdCoins == null ||
|
||||
String(feeCoins).trim() === "" ||
|
||||
String(holdCoins).trim() === ""
|
||||
) {
|
||||
return "—";
|
||||
}
|
||||
try {
|
||||
const sum = BigInt(String(feeCoins).trim()) + BigInt(String(holdCoins).trim());
|
||||
return formatRcLabelFromCoinsBigInt(sum);
|
||||
} catch {
|
||||
return "—";
|
||||
}
|
||||
}
|
||||
|
||||
function idsMatch(
|
||||
a: number | string | null | undefined,
|
||||
b: number | string | null | undefined,
|
||||
@@ -185,9 +190,12 @@ export function MatchHistoryBattleCard({
|
||||
right,
|
||||
winnerId,
|
||||
}: Props) {
|
||||
const entryRc = entryTotalRcLabel(entryFeeCoins, entryHoldPerPlayerCoins);
|
||||
const entryFeeRc = rcLabelFromCoinString(entryFeeCoins);
|
||||
const entryHoldRc = rcLabelFromCoinString(entryHoldPerPlayerCoins);
|
||||
const entryLine = entryCombinedPerPlayerTimesTwoLine(
|
||||
entryFeeCoins,
|
||||
entryHoldPerPlayerCoins,
|
||||
);
|
||||
const entryHoldLine = rcPerPlayerTimesTwoLine(entryHoldPerPlayerCoins);
|
||||
const entryFeeLine = rcPerPlayerTimesTwoLine(entryFeeCoins);
|
||||
const prizeCcDisplay = prizeCcLabel.trim() === "" ? "—" : prizeCcLabel;
|
||||
const hasWinner =
|
||||
winnerId != null &&
|
||||
@@ -238,16 +246,16 @@ export function MatchHistoryBattleCard({
|
||||
Time {createdAtLabel}
|
||||
</span>
|
||||
<span className="rounded bg-zinc-900/10 px-2 py-1 dark:bg-zinc-100/10">
|
||||
Entry {entryRc}
|
||||
Entry {entryLine}
|
||||
</span>
|
||||
<span className="rounded bg-zinc-900/10 px-2 py-1 dark:bg-zinc-100/10">
|
||||
Entry hold {entryHoldRc}
|
||||
Entry hold {entryHoldLine}
|
||||
</span>
|
||||
<span className="rounded bg-zinc-900/10 px-2 py-1 dark:bg-zinc-100/10">
|
||||
Prize {prizeCcDisplay} CC
|
||||
</span>
|
||||
<span className="rounded-md border border-emerald-200/90 bg-emerald-50 px-2 py-1 text-[11px] font-medium text-emerald-600 dark:border-emerald-300/35 dark:bg-emerald-400/15 dark:text-emerald-200">
|
||||
Entry fee {entryFeeRc}
|
||||
<span className="rounded-md border border-emerald-200/90 bg-emerald-50 px-2 py-1 text-[11px] font-medium text-emerald-600 tabular-nums dark:border-emerald-300/35 dark:bg-emerald-400/15 dark:text-emerald-200">
|
||||
Entry fee {entryFeeLine}
|
||||
</span>
|
||||
</div>
|
||||
<Link
|
||||
|
||||
Reference in New Issue
Block a user