feat: publish export polish#24
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
More reviews will be available in 28 minutes and 34 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughIntroduces a full quarter balance validation feature: new DB schema, a 632-line core library computing and persisting per-quarter variance checks, a new ChangesQuarter Balance Validation & Reports Feature
Treasury Asset Chain Awareness
Sequence Diagram(s)sequenceDiagram
participant Admin
participant TransactionsPage as Admin Transactions Page
participant ValidationActions as runBalanceValidation / acknowledgeBalanceVariance
participant CoreLib as quarter-balance-validation.ts
participant DB as Database
Admin->>TransactionsPage: view quarter transactions page
TransactionsPage->>DB: getQuarterBalanceValidation(quarterId)
DB-->>TransactionsPage: QuarterBalanceValidation | null
TransactionsPage-->>Admin: render BalanceValidationPanel
Admin->>ValidationActions: submit "Run Validation" form
ValidationActions->>CoreLib: runQuarterBalanceValidation(quarter, classificationSummary, syncStatus)
CoreLib->>DB: fetch snapshots + transfer rows + manual entries
DB-->>CoreLib: rows
CoreLib->>DB: upsert quarterBalanceValidations
DB-->>CoreLib: saved record
CoreLib-->>ValidationActions: QuarterBalanceValidation
ValidationActions->>TransactionsPage: revalidatePath + redirect ?validation=...
Admin->>ValidationActions: submit "Acknowledge Variance" form
ValidationActions->>CoreLib: acknowledgeQuarterBalanceValidation(quarterId, note, walletAddress)
CoreLib->>DB: update status="acknowledged"
DB-->>CoreLib: updated record
CoreLib-->>ValidationActions: QuarterBalanceValidation
ValidationActions->>TransactionsPage: revalidatePath + redirect ?validation=acknowledged
sequenceDiagram
participant User
participant ReportsPage as /reports
participant QuarterReportPage as /reports/quarters/[id]
participant XlsxRoute as /reports/quarters/[id]/export.xlsx
participant CoreLib as getQuarterReportData / isQuarterExportReady
User->>ReportsPage: GET /reports
ReportsPage->>CoreLib: listQuarterReportingPeriods + isQuarterExportReady filter
CoreLib-->>ReportsPage: filtered export-ready quarters
ReportsPage-->>User: report cards grid
User->>QuarterReportPage: GET /reports/quarters/:id
QuarterReportPage->>CoreLib: isQuarterExportReady(quarter)
QuarterReportPage->>CoreLib: getQuarterReportData(quarter)
CoreLib-->>QuarterReportPage: QuarterReportData
QuarterReportPage-->>User: metrics + balances + ranked tables + validation status
User->>XlsxRoute: GET /reports/quarters/:id/export.xlsx
XlsxRoute->>CoreLib: isQuarterExportReady(quarter)
XlsxRoute->>CoreLib: buildQuarterXlsxExport(quarter)
CoreLib-->>XlsxRoute: XLSX buffer
XlsxRoute-->>User: file download (Content-Disposition attachment)
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds a quarter balance validation workflow (persisted in DB) and exposes “Reports” pages/routes for viewing quarter summaries and exporting XLSX, gating report/export readiness on sync, classification, and balance validation status.
Changes:
- Introduces
quarter_balance_validationstable + server utilities to run/acknowledge/delete validations and integrates validation into quarter workflow gating. - Adds member/admin Reports pages (
/reports,/reports/quarters/[id]) and a Node.js route for XLSX export (/reports/quarters/[id]/export.xlsx). - Enhances treasury dashboard balances to show multi-chain asset coverage and adds report/export links.
Reviewed changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/treasury/types.ts | Extends TreasuryAssetBalance to track chainIds per aggregated asset. |
| src/lib/treasury/balances.ts | Populates and aggregates chainIds across account snapshots/assets. |
| src/lib/quarters.ts | Loads balanceValidation per quarter and passes it into workflow step construction. |
| src/lib/quarter-xlsx-export.ts | Exports ledger-row type and ledger row builder for reuse in reports. |
| src/lib/quarter-sync.ts | Adds a new “validate” workflow step and gates ready/publish on validation completion. |
| src/lib/quarter-report.ts | New server-only helper to build report datasets/metrics from ledger rows + balances. |
| src/lib/quarter-export-readiness.ts | Makes export readiness depend on satisfied balance validation. |
| src/lib/quarter-balance-validation.ts | New server-only implementation for running/acknowledging/deleting validations. |
| src/db/schema.ts | Adds validation status enum + quarter_balance_validations table definition + indexes. |
| src/components/treasury/treasury-dashboard.tsx | Displays chain breakdowns and adds “View Report”/“Export” links for quarters. |
| src/components/quarters/quarter-workflow-progress.tsx | Tweaks layout/styling for the now 5-step workflow. |
| src/components/app-header.tsx | Adds a top-level “Reports” nav item. |
| src/app/reports/page.tsx | New reports index page listing available quarter reports/exports. |
| src/app/reports/quarters/[id]/page.tsx | New quarter report page with balances, linked breakdowns, and validation summary. |
| src/app/reports/quarters/[id]/export.xlsx/route.ts | New authenticated XLSX export route for reports. |
| src/app/raids/transaction-lookup-actions.ts | Invalidates quarter validation and revalidates report paths after manual ledger changes. |
| src/app/admin/quarters/publish-quarter-confirmation.tsx | New client modal to confirm publishing a quarter. |
| src/app/admin/quarters/page.tsx | Updates quarter card actions to link to Reports and use publish confirmation modal. |
| src/app/admin/quarters/actions.ts | Enforces validation completion before ready/publish and revalidates report paths. |
| src/app/admin/quarters/[id]/transactions/page.tsx | Adds validation panel UI and loads validation + readiness state. |
| src/app/admin/quarters/[id]/transactions/actions.ts | Adds server actions to run/acknowledge validations and invalidates validations on relevant edits. |
| drizzle/meta/0017_snapshot.json | Drizzle snapshot updated for new enum/table. |
| drizzle/meta/_journal.json | Adds migration journal entry for migration 0017. |
| drizzle/0017_happy_silver_fox.sql | Migration creating enum + quarter_balance_validations table + indexes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/admin/quarters/`[id]/transactions/actions.ts:
- Around line 899-917: The acknowledgeBalanceVariance function currently uses a
fallback to an empty string for the wallet address when session.address is
missing, which can result in blank audit trails. After calling
requireAdminSession(), add validation to require that session.address is
non-empty and throw an error immediately if it is missing (fail fast). Store the
validated wallet address in a variable and use that same variable consistently
throughout the function in both the acknowledgeQuarterBalanceValidation call and
the writeAuditEvent metadata to ensure proper audit traceability is maintained.
In `@src/app/reports/page.tsx`:
- Around line 103-105: The badge span element on line 103 uses a hardcoded
emerald color scheme regardless of the isPreview state, causing unpublished
previews to appear published. Conditionally apply different className values to
the span element based on the isPreview variable: when isPreview is true, use a
different color scheme (such as amber or orange tones) to visually distinguish
the preview state from the published state shown with the current emerald
styling. Use a ternary operator within the className attribute to toggle between
these two style sets based on the isPreview boolean value.
In `@src/app/reports/quarters/`[id]/export.xlsx/route.ts:
- Around line 49-50: The error message returned by the responseText call for
export readiness only mentions sync and classification requirements, but it
should also mention the balance validation requirement that is checked by
isQuarterExportReady(quarter). Update the message string to include all three
requirements: syncing activity, classifying transactions, and validating
balances, so users understand the complete set of conditions that must be
satisfied before the quarter export is ready.
In `@src/lib/quarter-balance-validation.ts`:
- Around line 86-94: The toNumber function converts values to JavaScript Number
type which uses floating-point arithmetic, causing precision loss for
high-precision decimal calculations (36/18 precision token fields). Replace the
Number-based arithmetic in the toNumber function and throughout the validation
calculations at movement, variance, and totalVarianceUsd computation sections
(referenced at lines 446-447, 503-505, and 514-555) with exact decimal math
using a precision-safe library like decimal.js or bignumber.js to prevent
rounding drift that persists incorrect validation status and totals.
- Around line 605-609: The acknowledgement update operation has a race condition
where the status can change between the initial existence check and the update.
Modify the update query in the acknowledgement function to include a WHERE
clause predicate that checks the status equals needs_review in addition to the
quarterId condition. After executing the update, verify that at least one row
was actually updated by checking the result, and if no rows were matched, throw
an error indicating the status has changed (preventing overwriting a fresh
validated row). Apply this same pattern to all update operations mentioned in
the affected range that perform similar status transitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 00403250-0e4b-44fd-a9ee-539b9a7aaa56
📒 Files selected for processing (24)
drizzle/0017_happy_silver_fox.sqldrizzle/meta/0017_snapshot.jsondrizzle/meta/_journal.jsonsrc/app/admin/quarters/[id]/transactions/actions.tssrc/app/admin/quarters/[id]/transactions/page.tsxsrc/app/admin/quarters/actions.tssrc/app/admin/quarters/page.tsxsrc/app/admin/quarters/publish-quarter-confirmation.tsxsrc/app/raids/transaction-lookup-actions.tssrc/app/reports/page.tsxsrc/app/reports/quarters/[id]/export.xlsx/route.tssrc/app/reports/quarters/[id]/page.tsxsrc/components/app-header.tsxsrc/components/quarters/quarter-workflow-progress.tsxsrc/components/treasury/treasury-dashboard.tsxsrc/db/schema.tssrc/lib/quarter-balance-validation.tssrc/lib/quarter-export-readiness.tssrc/lib/quarter-report.tssrc/lib/quarter-sync.tssrc/lib/quarter-xlsx-export.tssrc/lib/quarters.tssrc/lib/treasury/balances.tssrc/lib/treasury/types.ts
This pull request introduces a comprehensive quarter balance validation feature for the admin quarter transactions workflow. It adds a new database table and supporting types for tracking quarter balance validations, integrates the validation process into the admin UI, and ensures that validation status is kept up-to-date in response to relevant actions. The UI now displays validation results, variances, and supports acknowledgment and re-running of validations.
Database and Backend Infrastructure:
quarter_balance_validationstable andquarter_balance_validation_statusenum to track the status, results, and metadata of quarter balance validations. [1] [2]UI Integration and Display:
BalanceValidationPanelReact component to the admin quarter transactions page, displaying the status, summary statistics, top variances, and excluded ledger rows for the current quarter's balance validation. It also provides controls for running/re-running validation, acknowledging variances, and marking the quarter as ready for review. (src/app/admin/quarters/[id]/transactions/page.tsxR357-R583, src/app/admin/quarters/[id]/transactions/page.tsxR1556-R1562)Workflow and Data Consistency:
Page Data Loading and Readiness Checks:
These changes collectively provide a robust reconciliation workflow for quarter balances, improving auditability and administrative control.
Summary by CodeRabbit
Release Notes
New Features
Enhancements