jevstrudel.git / website / src / jev / budget.mjs
1// Today's Jev budget in words, from the account's state (account.mjs:
2// `{ user, budget: { used, limit } }`, which the relay's `Jev-Budget` header
3// keeps current): the Jev pane's (JevBudget.jsx) and the request log's
4// picks (JevPicks.jsx). Signed out, calls are charged to nobody, only held
5// to this address's rate limit. Plain, so the Node tests load it without
6// the account's WebAuthn library.
7export function budgetText({ user, budget }) {
8  if (!user) return { text: 'budget: shared', title: 'Signed out, Jev calls are not charged, only rate-limited per address.' };
9  if (!budget || !Number.isFinite(budget.limit)) return { text: 'budget: …', title: 'Your daily Jev budget.' };
10  const left = Math.max(0, budget.limit - budget.used);
11  return {
12    text: `budget ${budget.used}/${budget.limit}`,
13    title: `Your Jev calls today: ${budget.used} of ${budget.limit}, ${left} left; it resets at 00:00 UTC.`,
14    spent: left === 0,
15  };
16}