zc2 0.0.53

P2P compute broker with yen-denominated billing, WAL, and broker mesh support
import type { Overview } from "../lib/overview";
import type { AgentHook } from "../lib/useAgent";
import { yen } from "../lib/format";
import { host } from "../lib/agent";
import { Button, Kpi, ScreenHead } from "../components/ui";
import { Ledger } from "../components/Ledger";
import { Price } from "./Price";

// Earnings: what the account holds and earned, and what this machine's time
// costs. (Price used to be a page of its own with two rows on it.)

export function Wallet({ hook, ov, prefill, onPrefillDone, onResources }: { hook: AgentHook; ov: Overview | null; prefill?: Record<string, unknown> | null; onPrefillDone?: () => void; onResources: () => void }) {
  const l = ov?.ledger;
  const week = l?.days.length ? l.days.reduce((a, d) => a + d.earned, 0) : null;
  return (
    <>
      <ScreenHead title="Earnings" sub="What you earned by lending, what you spent, and your price">
        <Button disabled={!ov} onClick={() => ov && host.openExternal(ov.hub.url)}>
          Open the hub ↗
        </Button>
      </ScreenHead>
      <div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-2.5">
        <Kpi label="Balance" value={yen(ov?.account?.balance)} sub={ov?.account?.email} />
        <Kpi label="Earned today" value={yen(l?.todayEarned)} sub={l?.tz} />
        <Kpi label="Earned 7 d" value={yen(week)} />
        <Kpi label="Spent this month" value={yen(l?.monthSpent)} />
      </div>
      <Price hook={hook} ov={ov} prefill={prefill} onPrefillDone={onPrefillDone} onResources={onResources} />
      <Ledger />
    </>
  );
}