jevstrudel.git / website / src / jev / budget.mjs

Today's Jev budget in words, from the account's state (account.mjs: { user, budget: { used, limit } }, which the relay's Jev-Budget header keeps current): the Jev pane's (JevBudget.jsx) and the request log's picks (JevPicks.jsx). Signed out, calls are charged to nobody, only held to this address's rate limit. Plain, so the Node tests load it without 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}