Skip to content

feat: publish export polish#24

Merged
ECWireless merged 2 commits into
mainfrom
codex/publish-export-polish
Jun 18, 2026
Merged

feat: publish export polish#24
ECWireless merged 2 commits into
mainfrom
codex/publish-export-polish

Conversation

@ECWireless

@ECWireless ECWireless commented Jun 18, 2026

Copy link
Copy Markdown
Member

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:

UI Integration and Display:

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

    • Added quarter balance validation system with variance detection and acknowledgement workflow
    • Added public Reports page displaying accessible quarters with financial summaries
    • Added quarter report views with export to XLSX capability
    • Chain information now displayed in treasury asset breakdown
  • Enhancements

    • Quarter publishing workflow now requires balance validation completion
    • Publication confirmation modal for improved publishing experience
    • Reports navigation link added to application header

Copilot AI review requested due to automatic review settings June 18, 2026 15:40
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
raidguild-accounting Ready Ready Preview, Comment Jun 18, 2026 4:12pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ECWireless, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b859df32-dede-4137-8aaa-1f7938c5594a

📥 Commits

Reviewing files that changed from the base of the PR and between 9a1348b and a357d43.

📒 Files selected for processing (6)
  • src/app/admin/quarters/[id]/transactions/actions.ts
  • src/app/reports/page.tsx
  • src/app/reports/quarters/[id]/export.xlsx/route.ts
  • src/app/reports/quarters/[id]/page.tsx
  • src/lib/quarter-balance-validation.ts
  • src/lib/quarter-report.ts
📝 Walkthrough

Walkthrough

Introduces a full quarter balance validation feature: new DB schema, a 632-line core library computing and persisting per-quarter variance checks, a new "validate" workflow step, admin server actions for running/acknowledging validations, a BalanceValidationPanel UI, and new public /reports and /reports/quarters/[id] pages with an XLSX export route. Also adds chainIds to TreasuryAssetBalance with chain-aware balance aggregation and dashboard display.

Changes

Quarter Balance Validation & Reports Feature

Layer / File(s) Summary
DB schema and migration
drizzle/0017_happy_silver_fox.sql, drizzle/meta/_journal.json, src/db/schema.ts
Adds quarter_balance_validation_status enum and quarter_balance_validations table with counters, JSONB details, optional acknowledgement fields, cascading FK to quarters, and unique/status indexes.
Balance validation core library
src/lib/quarter-balance-validation.ts
Defines exported types, DB-to-domain mapping with note decryption, movement-sign helpers, the main runQuarterBalanceValidation upsert workflow, acknowledgeQuarterBalanceValidation, and CRUD query helpers.
Quarter workflow model: validate step and export readiness
src/lib/quarter-sync.ts, src/lib/quarter-export-readiness.ts, src/lib/quarters.ts
Extends QuarterWorkflowStep.key with "validate", gates ready/publish steps on validationComplete, updates isQuarterExportReady to require satisfied balance validation, and extends QuarterReportingPeriod with balanceValidation.
XLSX export type refactor and quarter report data module
src/lib/quarter-xlsx-export.ts, src/lib/quarter-report.ts
Exports QuarterExportLedgerRow and renames buildQuarterLedgerRows; adds QuarterReportData types and getQuarterReportData for concurrent ledger/balance data assembly.
Admin transaction validation server actions and invalidation hooks
src/app/admin/quarters/[id]/transactions/actions.ts, src/app/raids/transaction-lookup-actions.ts
Adds runBalanceValidation and acknowledgeBalanceVariance server actions; wires invalidateQuarterValidation into all ledger-mutating admin and raid actions; extends path revalidation to cover /reports routes.
Admin transactions page: BalanceValidationPanel
src/app/admin/quarters/[id]/transactions/page.tsx
Adds BalanceValidationPanel component showing variance summary/table, acknowledgement details, and conditional action forms; wires getQuarterBalanceValidation into data fetch and workflow/export readiness computation.
Admin quarters list: status gating and PublishQuarterConfirmation modal
src/app/admin/quarters/actions.ts, src/app/admin/quarters/page.tsx, src/app/admin/quarters/publish-quarter-confirmation.tsx
Adds validation-satisfied precondition in updateQuarterStatus; replaces direct publish button with a PublishQuarterConfirmation confirmation modal; replaces single XLSX link with View Report + Export XLSX links to /reports/quarters/....
New /reports pages and XLSX export route
src/app/reports/page.tsx, src/app/reports/quarters/[id]/page.tsx, src/app/reports/quarters/[id]/export.xlsx/route.ts, src/components/app-header.tsx, src/components/quarters/quarter-workflow-progress.tsx
Adds ReportsPage, QuarterReportPage (metrics, balance table, ranked tables, validation status), and XLSX export route with auth/readiness guards; adds Reports nav link; updates QuarterWorkflowProgress compact-mode layout for the five-step grid.

Treasury Asset Chain Awareness

Layer / File(s) Summary
TreasuryAssetBalance chainIds type and balance computation
src/lib/treasury/types.ts, src/lib/treasury/balances.ts
Adds chainIds: number[] to TreasuryAssetBalance and propagates chain context through empty-balance creation, aggregation, cached snapshot mapping, and live sync.
Treasury dashboard chain display and report links
src/components/treasury/treasury-dashboard.tsx
Adds getChainName helper; reworks balance card with per-chain USD totals and multi-chain label; adds Chain column to Asset Breakdown table; replaces disabled export button with View Report and Export navigable links.

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
Loading
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)
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • raid-guild/accounting#23: Both PRs modify isQuarterExportReady — this PR extends it to require satisfied balance validation on top of the balancesStatus gate added in that PR.
  • raid-guild/accounting#15: Both PRs directly modify src/lib/quarter-sync.ts and src/components/quarters/quarter-workflow-progress.tsx — this PR adds the "validate" workflow step to the foundation established there.
  • raid-guild/accounting#12: Both PRs touch classifyQuarterTransfer in src/app/admin/quarters/[id]/transactions/actions.ts — this PR wires invalidateQuarterValidation directly into the classification flow introduced in that PR.

Poem

🐇 Hoppity-hop, the ledger aligns,
Each quarter now validated with signs!
Variances checked, acknowledged with care,
Reports published proudly for all to share.
The rabbit checks balances — chain by chain,
No token escapes the accounting domain! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'feat: publish export polish' is vague and does not accurately reflect the primary changes, which center on quarter balance validation rather than publishing or exporting. Consider a more descriptive title such as 'feat: add quarter balance validation workflow' or 'feat: implement quarter balance validation and reconciliation' that better captures the main objective of the PR.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/publish-export-polish

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_validations table + 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.

Comment thread src/lib/quarter-balance-validation.ts
Comment thread src/lib/quarter-balance-validation.ts Outdated
Comment thread src/app/reports/quarters/[id]/export.xlsx/route.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2811dba and 9a1348b.

📒 Files selected for processing (24)
  • drizzle/0017_happy_silver_fox.sql
  • drizzle/meta/0017_snapshot.json
  • drizzle/meta/_journal.json
  • src/app/admin/quarters/[id]/transactions/actions.ts
  • src/app/admin/quarters/[id]/transactions/page.tsx
  • src/app/admin/quarters/actions.ts
  • src/app/admin/quarters/page.tsx
  • src/app/admin/quarters/publish-quarter-confirmation.tsx
  • src/app/raids/transaction-lookup-actions.ts
  • src/app/reports/page.tsx
  • src/app/reports/quarters/[id]/export.xlsx/route.ts
  • src/app/reports/quarters/[id]/page.tsx
  • src/components/app-header.tsx
  • src/components/quarters/quarter-workflow-progress.tsx
  • src/components/treasury/treasury-dashboard.tsx
  • src/db/schema.ts
  • src/lib/quarter-balance-validation.ts
  • src/lib/quarter-export-readiness.ts
  • src/lib/quarter-report.ts
  • src/lib/quarter-sync.ts
  • src/lib/quarter-xlsx-export.ts
  • src/lib/quarters.ts
  • src/lib/treasury/balances.ts
  • src/lib/treasury/types.ts

Comment thread src/app/admin/quarters/[id]/transactions/actions.ts
Comment thread src/app/reports/page.tsx Outdated
Comment thread src/app/reports/quarters/[id]/export.xlsx/route.ts Outdated
Comment thread src/lib/quarter-balance-validation.ts Outdated
Comment thread src/lib/quarter-balance-validation.ts
@ECWireless ECWireless merged commit fa09a10 into main Jun 18, 2026
5 checks passed
@ECWireless ECWireless deleted the codex/publish-export-polish branch June 18, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants