Feat/indexeddb storage#185
Conversation
|
Warning Review limit reached
Next review available in: 37 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?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 reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. 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, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughAdds IndexedDB invoice storage with backup/restore helpers, persists newly created invoices locally, reuses cached invoice data during sent/received views, synchronizes statuses, and replaces ChangesInvoice storage and backup
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant InvoiceView
participant ChainvoiceContract
participant invoiceDB
InvoiceView->>ChainvoiceContract: fetch sent or received invoices
InvoiceView->>invoiceDB: load local invoices by address and chain
alt cached decrypted data exists
invoiceDB-->>InvoiceView: return cached data and status
InvoiceView->>invoiceDB: updateInvoiceStatus when status differs
else no cached data
InvoiceView->>InvoiceView: decrypt and parse encrypted payload
InvoiceView->>invoiceDB: storeInvoice(payload and metadata)
end
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ 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 |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 9
🤖 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 `@frontend/src/page/BatchPayment.jsx`:
- Line 10: The batch-payment flow uses unsupported toast.info calls from
react-hot-toast. Locate the toast invocations in BatchPayment and replace each
toast.info call with toast(...) or the appropriate toast.success(...) call while
preserving the existing messages and flow behavior.
In `@frontend/src/page/CreateInvoice.jsx`:
- Around line 436-472: Handle the case where the InvoiceCreated event cannot be
resolved after iterating through receipt.logs in CreateInvoice: warn the user
and prevent the success redirect, or otherwise clearly report that local
persistence was skipped. Add this branch immediately after the event-parsing
loop and ensure it returns before the existing redirect flow when invoiceId
remains null.
In `@frontend/src/page/ReceivedInvoice.jsx`:
- Line 22: Replace every toast.info(...) call in ReceivedInvoice with a
supported react-hot-toast API, such as toast(...), while preserving the existing
messages and payment/PDF flow behavior.
In `@frontend/src/page/SentInvoice.jsx`:
- Line 22: Replace the unsupported toast.info call in SentInvoice with the
supported toast("Generating PDF...") API, ensuring PDF export continues to the
download step without throwing.
In `@frontend/src/services/invoiceStorage/invoiceBackup.js`:
- Around line 48-56: Replace the dynamic import inside getLocalInvoiceCount with
a static getAllInvoices import from ./invoiceDB.js, alongside the existing
DB_NAME import, and call getAllInvoices directly while preserving the current
error handling.
In `@frontend/src/services/invoiceStorage/invoiceDB.js`:
- Around line 43-45: Update makeKey to produce an unambiguous composite key by
encoding each chainId and invoiceId component or using a collision-safe
structured representation; ensure different values containing separators cannot
generate the same key, while preserving consistent key generation for reads and
writes.
- Around line 53-67: Validate that invoice.from and invoice.to are defined in
storeInvoice alongside chainId and invoiceId, throwing the same required-fields
error pattern before calling getDB or writing the record. Keep the existing
normalization and indexing behavior unchanged.
- Around line 13-35: Cache the IndexedDB connection promise used by getDB()
instead of calling openDB() on every invocation. Add a module-level promise
variable and have getDB() initialize it only once, returning the cached promise
thereafter; preserve the existing upgrade logic and error logging, and reset the
cached promise if opening fails so later calls can retry.
- Around line 144-157: updateInvoiceStatus must perform its read and write
atomically to avoid lost updates. Use a single readwrite transaction on
STORE_NAME, retrieve the existing record through that transaction, merge updates
and updatedAt, then write the result through the same transaction before
returning it; preserve the existing missing-record and error handling behavior.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: ea223c27-3d1f-4a4d-92be-2a778834ac51
📒 Files selected for processing (11)
frontend/package.jsonfrontend/src/hooks/useInvoiceExport.jsfrontend/src/hooks/useInvoiceStorage.jsfrontend/src/page/BatchPayment.jsxfrontend/src/page/CreateInvoice.jsxfrontend/src/page/CreateInvoicesBatch.jsxfrontend/src/page/ReceivedInvoice.jsxfrontend/src/page/SentInvoice.jsxfrontend/src/services/invoiceStorage/index.jsfrontend/src/services/invoiceStorage/invoiceBackup.jsfrontend/src/services/invoiceStorage/invoiceDB.js
- Replace all toast.info() with toast() (react-hot-toast compatibility) - Cache IndexedDB connection to avoid reopening on every call - Add from/to validation in storeInvoice to prevent silent index failures - Use atomic readwrite transaction in updateInvoiceStatus - Switch dynamic import to static import in invoiceBackup.js - Warn user when InvoiceCreated event is not found in tx logs
Addressed Issues:
Fixes #(TODO:issue number)
Screenshots/Recordings:
TODO: If applicable, add screenshots or recordings that demonstrate the interface before and after the changes.
Additional Notes:
This PR completely migrates local invoice storage from volatile browser storage/state to robust IndexedDB storage.
Key Technical Changes:
invoiceDB.jsto handle local caching of invoices using a multi-chain composite key (chainId-invoiceId).SentInvoiceandReceivedInvoicepages now use a smart merge strategy. They fetch from the local IndexedDB first, drastically reducing load times and preventing unnecessary on-chain decoding for previously fetched invoices.useInvoiceStoragehook with built-in export/import functionality via@aossie-org/idb-backup.react-toastifyinstances withreact-hot-toastin the modified files to ensure a consistent UX across the app.AI Usage Disclosure:
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Check one of the checkboxes below:
I have used the following AI models and tools: Claude Opus 4.6
Checklist
Summary by CodeRabbit
New Features
Bug Fixes