MCPcopy Index your code
hub / github.com/codeaashu/claude-code / formatX402Cost

Function formatX402Cost

src/services/x402/tracker.ts:48–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46
47/** Format x402 payment summary for display */
48export function formatX402Cost(): string {
49 if (sessionPayments.length === 0) {
50 return ''
51 }
52
53 const lines: string[] = []
54 lines.push(
55 `x402 payments: $${sessionTotalUSD.toFixed(4)} (${sessionPayments.length} ${sessionPayments.length === 1 ? 'payment' : 'payments'})`,
56 )
57
58 // Group by resource domain
59 const byDomain: Record<string, { count: number; totalUSD: number }> = {}
60 for (const payment of sessionPayments) {
61 try {
62 const domain = new URL(payment.resource).hostname
63 if (!byDomain[domain]) {
64 byDomain[domain] = { count: 0, totalUSD: 0 }
65 }
66 byDomain[domain].count += 1
67 byDomain[domain].totalUSD += payment.amountUSD
68 } catch {
69 // Skip malformed URLs
70 }
71 }
72
73 for (const [domain, stats] of Object.entries(byDomain)) {
74 lines.push(
75 `${domain}:`.padStart(21) +
76 ` ${formatNumber(stats.count)} ${stats.count === 1 ? 'request' : 'requests'} ($${stats.totalUSD.toFixed(4)})`,
77 )
78 }
79
80 return chalk.dim(lines.join('\n'))
81}

Callers 2

formatTotalCostFunction · 0.85
handleStatusFunction · 0.85

Calls 3

formatNumberFunction · 0.85
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected