feat(admin): see every user's activity and volume in one place - #245
Merged
Conversation
Adds /admin/users: a sortable, searchable table of all 285 merchant accounts with their counts and USD volume across the four things a merchant can transact with — crypto payments, invoices, escrows and Stripe — plus platform-wide totals in the header and a CSV export. Aggregation lives in two Postgres functions rather than the route, so a page of stats is one round trip instead of five queries per user. Both are granted to service_role only and reached through requireAdmin(), the same guard the existing admin pages use. Two things deliberately not reported, because reporting them would be worse than omitting them: - Platform fees on crypto payments and escrows are held in chain units. Summing 0.14 across BTC, ETH, SOL and USDC produces a number with no meaning, so only invoice fees (which are USD) are shown. - Four invoices are priced in ETH/USDC_BASE. They are counted but kept out of the USD column, so the count and the total legitimately disagree — the page says so rather than quietly adding 0.05 ETH to a dollar figure. The per-merchant CTEs are separate on purpose: joining businesses to payments and invoices and escrows in one query fans out the row set and multiplies every count by the cardinality of the other branches. Sort keys are whitelisted in SQL and again in TypeScript, and the search term is bound as a parameter — a quote in the search box returns zero rows rather than reaching the statement text. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ThreatCrush Security Scan325 finding(s) HIGH/CRITICAL: 35 | MEDIUM: 37 | LOW: 253
…and 275 more. Full results in the Security tab. Snippets are redacted; ThreatCrush never prints matched credential material. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
/admin/users— a sortable, searchable table of every merchant account with their activity and USD volume, plus platform-wide totals and a CSV export.What you get
Header tiles — users (with 7d/30d signups), logged-in-in-30d, businesses, crypto volume, Stripe volume, invoiced.
Per-user row — signed up, last active (most recent of login/payment/invoice/escrow/Stripe), businesses, settled/total payments, crypto USD, paid/total invoices, Stripe USD, and a combined total. Click a row to expand plan, auth provider, escrow and invoice-fee detail, and the merchant id.
Sort by any column, search by email or name, page through 50 at a time, export up to 500 matching rows as CSV.
How it's built
supabase/migrations/20260813120000_admin_user_stats.sql—admin_user_stats()+admin_platform_stats()src/lib/stats/admin-user-stats.tssrc/app/api/admin/users/route.ts, behind the existingrequireAdmin()src/app/admin/users/Aggregation is in Postgres rather than the route, so a page of stats is one round trip instead of five queries per user. Both functions are granted to
service_roleonly — noanon/authenticatedgrant, so a browser cannot reach them through PostgREST. Per-merchant CTEs are kept separate on purpose: joining businesses to payments and invoices and escrows in one query fans out the row set and multiplies every count by the cardinality of the other branches.Two things deliberately not reported
payments.fee_amountandescrows.fee_amountare in chain units. Summing 0.14 across BTC, ETH, SOL and USDC yields a meaningless number, so only invoice fees (which are USD) appear."Settled" matches
public_landing_stats():confirmedorforwarded. Expired payment windows stay inpayments_total, which is what makes the settle rate readable.Migration is already applied
The two functions are live on
mlywdeoogwsebabohskk(coinpayportal.com) — applied via the Supabase MCP, since no CI applies migrations for this repo. They're additive and read-only, so this branch is safe to merge whenever. Verified against prod: 285 users, 752 of 2,212 payments settled, $24,163.83 crypto volume, $37,493.28 Stripe.Checks
vitest run— 272 files, 3781 passed, 3 skipped (21 of those are new)tsc --noEmit— cleaneslinton touched paths — cleannext build --webpack— compiles;/admin/usersand/api/admin/usersregister as dynamic routes' or 1=1--returns 0 rows; unknown sort keys fall back; limit/offset clamp🤖 Generated with Claude Code