feat: manual raid revenue flow#17
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
More reviews will be available in 16 minutes and 53 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 We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. 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 (4)
📝 WalkthroughWalkthroughThis PR introduces a complete manual raid revenue ledger entry system. Users can record off-chain raid revenue by looking up manual transactions and saving them as ledger entries. The system includes server-side validation, deduplication via ChangesManual Raid Revenue Ledger System
Sequence DiagramsequenceDiagram
participant User
participant TransactionLookupPanel
participant saveManualRaidRevenue
participant TransactionAPI
participant Database
participant AuditLog
User->>TransactionLookupPanel: Enter chain, tx hash
TransactionLookupPanel->>saveManualRaidRevenue: lookupRaidTransaction()
saveManualRaidRevenue->>TransactionAPI: Fetch transaction details
TransactionAPI-->>saveManualRaidRevenue: Returns transfers, amounts
saveManualRaidRevenue-->>TransactionLookupPanel: Returns lookup result
User->>TransactionLookupPanel: Select transfer, USD amount, submit
TransactionLookupPanel->>saveManualRaidRevenue: saveManualRaidRevenue(formData)
saveManualRaidRevenue->>Database: Check sourceExternalId uniqueness
saveManualRaidRevenue->>Database: Fetch/create accounting quarter
saveManualRaidRevenue->>Database: Validate quarter draft status
saveManualRaidRevenue->>Database: Insert ledger entry with encrypted notes
saveManualRaidRevenue->>AuditLog: Log entry creation
saveManualRaidRevenue-->>TransactionLookupPanel: Return savedEntry
TransactionLookupPanel->>TransactionLookupPanel: Show SavedRevenuePanel
User->>TransactionLookupPanel: Click Remove button
TransactionLookupPanel->>saveManualRaidRevenue: removeManualRaidRevenue(ledgerEntryId)
saveManualRaidRevenue->>Database: Load entry + verify quarter draft
saveManualRaidRevenue->>Database: Delete ledger entry
saveManualRaidRevenue->>AuditLog: Log deletion
saveManualRaidRevenue-->>TransactionLookupPanel: Return removed: true
TransactionLookupPanel->>User: Show removal success
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
Adds an end-to-end “manual raid revenue” flow so raid revenue transfers can be manually looked up, saved into the quarter ledger as ledger_entries with source="manual", and (while draft) removed again—surfacing these entries in both the /raids workflow and the admin quarter transactions review.
Changes:
- Introduces server actions to save/remove manual raid revenue entries with permission checks, quarter-status validation, de-duplication via
source_external_id, and audit logging. - Updates
/raidsUI to support transaction lookup + saving revenue to a selected raid, plus shows/removes saved manual revenue per raid. - Updates admin quarter transactions page to list manual ledger entries for the quarter and allow removal (draft only), and extends DB schema/migrations to support
source_external_id.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/transaction-classification.ts | Adds a manual-ledger-entry view model and query to list manual ledger entries for a quarter. |
| src/db/schema.ts | Adds ledger_entries.source_external_id and a unique index to prevent duplicate external-source entries. |
| src/components/treasury/treasury-dashboard.tsx | Layout/UI tweaks for the “included accounts” list presentation. |
| src/app/raids/transaction-lookup-panel.tsx | Extends the lookup panel UI to save manual raid revenue and remove it with toast feedback. |
| src/app/raids/transaction-lookup-actions.ts | Implements server actions and validation for saving/removing manual raid revenue, including audit + revalidation. |
| src/app/raids/page.tsx | Updates raids page to pass raids into the lookup panel, adds modal-based navigation, and displays/removes manual revenue entries per raid. |
| src/app/admin/quarters/[id]/transactions/page.tsx | Fetches/displays manual ledger entries for a quarter and exposes a removal action (draft only). |
| drizzle/meta/0012_snapshot.json | Drizzle snapshot update reflecting the new schema. |
| drizzle/meta/_journal.json | Drizzle journal updated to include the new migration. |
| drizzle/0012_lively_wind_dancer.sql | Migration adding source_external_id and a unique index on it. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/app/raids/transaction-lookup-actions.ts (1)
335-350: 💤 Low valueUnnecessary optional chaining on
entry?.id.On line 347,
entry?.iduses optional chaining, butentryis guaranteed to exist at this point due to the check on lines 331-333. This is a minor inconsistency that could mislead readers about the variable's guaranteed presence.🔧 Suggested fix
await writeAuditEvent({ action: "import", actorWalletAddress: session.address, metadata: { chainId, quarterId: quarter.id, raidId: raid.id, sourceExternalId, transferIndex, txHash: result.txHash, }, quarterId: quarter.id, - subjectId: entry?.id, + subjectId: entry.id, subjectTable: "ledger_entries", summary: "Saved manual raid revenue", });🤖 Prompt for 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. In `@src/app/raids/transaction-lookup-actions.ts` around lines 335 - 350, The audit event call uses unnecessary optional chaining on entry (entry?.id) even though entry is guaranteed to exist earlier; update the writeAuditEvent metadata/subjectId to use entry.id (remove the ?) in the call sites referencing writeAuditEvent so the code reflects the guaranteed presence of entry and avoids the misleading optional chaining.src/app/raids/page.tsx (1)
1036-1081: 💤 Low valueConsider adding focus management for improved accessibility.
The modal has proper ARIA attributes (
role="dialog",aria-modal,aria-label) and visible close affordances. For enhanced accessibility, consider:
- Focus trap: Focus should be contained within the modal while open
- Escape key: Allow closing with keyboard
- Initial focus: Focus the first focusable element or close button on open
- Restore focus: Return focus to trigger element on close
This would require converting to a Client Component or using a modal library like
@headlessui/reactor@radix-ui/react-dialog.🤖 Prompt for 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. In `@src/app/raids/page.tsx` around lines 1036 - 1081, ModalShell lacks focus management; convert it to a Client Component (add "use client" at top) and implement accessible modal behaviors: capture and save document.activeElement on open and restore on close, trap focus within the modal (cycle focus among tabbable elements inside the ModalShell container), move initial focus to the close Link or first focusable child when mounting, and listen for Escape to trigger the same close navigation (use router.push or Link navigation handler). Alternatively, replace ModalShell with a tested dialog from `@radix-ui/react-dialog` or `@headlessui/react-dialog` and wire the same close/navigation to /raids so focus restoration and trapping are handled by the library.
🤖 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/page.tsx:
- Around line 740-748: The remove form for manual raid revenue entries currently
submits destructively without confirmation; add a client-side confirmation step
by attaching an onSubmit handler to the <form> that wraps the hidden
ledgerEntryId and calls confirm('Remove this manual entry? This action cannot be
undone.'), calling event.preventDefault() when the user cancels; implement this
on the form that uses removeManualRaidRevenueFromForm (or alternatively
implement a two-step confirm state on the Remove <Button>) so the destructive
action only proceeds after explicit user confirmation.
---
Nitpick comments:
In `@src/app/raids/page.tsx`:
- Around line 1036-1081: ModalShell lacks focus management; convert it to a
Client Component (add "use client" at top) and implement accessible modal
behaviors: capture and save document.activeElement on open and restore on close,
trap focus within the modal (cycle focus among tabbable elements inside the
ModalShell container), move initial focus to the close Link or first focusable
child when mounting, and listen for Escape to trigger the same close navigation
(use router.push or Link navigation handler). Alternatively, replace ModalShell
with a tested dialog from `@radix-ui/react-dialog` or `@headlessui/react-dialog` and
wire the same close/navigation to /raids so focus restoration and trapping are
handled by the library.
In `@src/app/raids/transaction-lookup-actions.ts`:
- Around line 335-350: The audit event call uses unnecessary optional chaining
on entry (entry?.id) even though entry is guaranteed to exist earlier; update
the writeAuditEvent metadata/subjectId to use entry.id (remove the ?) in the
call sites referencing writeAuditEvent so the code reflects the guaranteed
presence of entry and avoids the misleading optional chaining.
🪄 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: a88d26ff-eda3-4f7b-ba26-f7c245507699
📒 Files selected for processing (10)
drizzle/0012_lively_wind_dancer.sqldrizzle/meta/0012_snapshot.jsondrizzle/meta/_journal.jsonsrc/app/admin/quarters/[id]/transactions/page.tsxsrc/app/raids/page.tsxsrc/app/raids/transaction-lookup-actions.tssrc/app/raids/transaction-lookup-panel.tsxsrc/components/treasury/treasury-dashboard.tsxsrc/db/schema.tssrc/lib/transaction-classification.ts
This pull request introduces support for managing manual raid revenue entries in the admin quarter transactions workflow. It adds backend logic and UI components for saving and removing manual revenue entries, ensures proper validation and permissions, and updates the database schema to support these features.
Manual Raid Revenue Management
transaction-lookup-actions.tsto allow saving and removing manual raid revenue entries, including validation for permissions, duplicate entries, and quarter status. Also added utility functions for quarter calculation and data validation. [1] [2]page.tsx) to fetch and display manual ledger entries for the quarter, including a newManualLedgerEntryCardcomponent with UI for removal (only in draft quarters). (src/app/admin/quarters/[id]/transactions/page.tsxR658-R754, src/app/admin/quarters/[id]/transactions/page.tsxL705-R813, src/app/admin/quarters/[id]/transactions/page.tsxR923-R940, src/app/admin/quarters/[id]/transactions/page.tsxL829-R954)Database Schema Changes
ledger_entriestable to add asource_external_idcolumn and created a unique index to prevent duplicate manual entries for the same source.User Interface Enhancements
SaveSubmitButton,RemoveRevenueButton) and toast notifications for user feedback. [1] [2]These changes collectively enable admins to manually classify and manage raid revenue transactions that are not imported automatically, improving the flexibility and accuracy of the accounting workflow.
Summary by CodeRabbit
Release Notes
New Features
Style
Refactor