- clis/lepton (@settlekit/lepton-cli): operator CLI (deploy/config/settlements/lineage/proof) on real domain logic - apps/agent-console: Next.js agentic-commerce surface, real domain logic (agent-services + citation-toll + attribution) - apps/stream-meter: Next.js live per-second streaming meter (RFB 4) on real @settlekit/streaming - packages/payouts-cpn (@settlekit/payouts-cpn): Circle CPN fiat off-ramp, credential-gated + local provider + tests - common: make ids.ts isomorphic (Web Crypto) so domain packages bundle into client components - wire clis/lepton into pnpm-workspace + vitest; 1031 tests, typecheck, all next builds green
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
// Formatting helpers. Money here is a decimal USDC string (the shape the
|
|
// settlement spine produces, e.g. "0.0008"), not minor units.
|
|
|
|
/** Format a decimal USDC string, keeping sub-cent precision when present. */
|
|
export function formatUsdc(amount: string | null | undefined): string {
|
|
if (amount == null || amount === "") return "—";
|
|
const value = Number(amount);
|
|
if (Number.isNaN(value)) return `${amount} USDC`;
|
|
const formatted = value.toLocaleString("en-US", {
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 6,
|
|
});
|
|
return `${formatted} USDC`;
|
|
}
|
|
|
|
export function formatNumber(n: number | null | undefined): string {
|
|
if (n == null) return "—";
|
|
return n.toLocaleString("en-US");
|
|
}
|
|
|
|
/** Render an ISO timestamp as a short readable date-time. */
|
|
export function formatDateTime(iso: string | null | undefined): string {
|
|
if (!iso) return "—";
|
|
const d = new Date(iso);
|
|
if (Number.isNaN(d.getTime())) return iso;
|
|
return d.toLocaleString("en-US", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
});
|
|
}
|
|
|
|
/** Title-case a snake_case enum value for display. */
|
|
export function humanize(value: string | null | undefined): string {
|
|
if (!value) return "—";
|
|
return value.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
}
|
|
|
|
/** Shorten a wallet address for display: 0x1234…abcd. */
|
|
export function shortWallet(wallet: string): string {
|
|
if (wallet.length <= 12) return wallet;
|
|
return `${wallet.slice(0, 6)}…${wallet.slice(-4)}`;
|
|
}
|