sendou.ink/app/features/user-card/user-card-utils.ts
Kalle 621fe301f1
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
User card only allow unverified if also verified exists
2026-07-05 18:01:31 +03:00

23 lines
726 B
TypeScript

import { USER_CARD } from "./user-card-constants";
/**
* Whether a self-reported unverified peak XP is a valid claim on top of the user's verified XP: the
* user must have a verified XP, and the claim must be higher than it but by no more than
* {@link USER_CARD.MAX_UNVERIFIED_XP_ABOVE_VERIFIED}. Shared by the edit action (to validate) and the
* card query (to decide whether the value is surfaced), so both apply the exact same rule.
*/
export function isValidUnverifiedXp({
unverified,
verified,
}: {
unverified: number;
verified: number | null;
}): boolean {
if (verified === null) return false;
return (
unverified > verified &&
unverified <= verified + USER_CARD.MAX_UNVERIFIED_XP_ABOVE_VERIFIED
);
}