Skip to content

Feat/indexeddb storage#185

Merged
kumawatkaran523 merged 3 commits into
StabilityNexus:mainfrom
Atharva0506:feat/indexeddb-storage
Jul 12, 2026
Merged

Feat/indexeddb storage#185
kumawatkaran523 merged 3 commits into
StabilityNexus:mainfrom
Atharva0506:feat/indexeddb-storage

Conversation

@Atharva0506

@Atharva0506 Atharva0506 commented Jul 10, 2026

Copy link
Copy Markdown
Member

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:

  • IndexedDB Service: Implemented invoiceDB.js to handle local caching of invoices using a multi-chain composite key (chainId-invoiceId).
  • Performance Boost: SentInvoice and ReceivedInvoice pages 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.
  • Backup Support: Added useInvoiceStorage hook with built-in export/import functionality via @aossie-org/idb-backup.
  • Toast Standardization: Replaced all leftover react-toastify instances with react-hot-toast in 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:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: Claude Opus 4.6

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • New Features

    • Added local invoice storage to preserve decrypted invoice details and improve loading efficiency.
    • Added invoice backup export and restore through downloadable JSON files.
    • Newly created invoices are saved locally after successful blockchain confirmation.
    • Sent and received invoice views now reuse cached data and synchronize payment and cancellation statuses.
  • Bug Fixes

    • Improved invoice loading by avoiding unnecessary repeated decryption.
    • Standardized success, informational, and error notifications across invoice workflows.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Atharva0506, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2d697705-9e1a-4851-bdbe-2949e840917b

📥 Commits

Reviewing files that changed from the base of the PR and between 11c62dd and ec158de.

📒 Files selected for processing (6)
  • frontend/src/page/BatchPayment.jsx
  • frontend/src/page/CreateInvoice.jsx
  • frontend/src/page/ReceivedInvoice.jsx
  • frontend/src/page/SentInvoice.jsx
  • frontend/src/services/invoiceStorage/invoiceBackup.js
  • frontend/src/services/invoiceStorage/invoiceDB.js

Walkthrough

Adds IndexedDB invoice storage with backup/restore helpers, persists newly created invoices locally, reuses cached invoice data during sent/received views, synchronizes statuses, and replaces react-toastify imports with react-hot-toast.

Changes

Invoice storage and backup

Layer / File(s) Summary
IndexedDB storage foundation
frontend/package.json, frontend/src/services/invoiceStorage/*
Defines the invoice database, indexes, CRUD operations, status updates, deletion, and public re-exports.
Backup and storage hook
frontend/src/services/invoiceStorage/invoiceBackup.js, frontend/src/hooks/useInvoiceStorage.js
Adds JSON backup import/export and a React hook exposing storage APIs and operation state.
Invoice creation persistence
frontend/src/page/CreateInvoice.jsx, frontend/src/page/CreateInvoicesBatch.jsx
Extracts InvoiceCreated IDs from confirmed receipts and stores matching invoice payloads locally.
Cached invoice hydration and toast migration
frontend/src/page/SentInvoice.jsx, frontend/src/page/ReceivedInvoice.jsx, frontend/src/page/BatchPayment.jsx, frontend/src/hooks/useInvoiceExport.js, frontend/package.json
Reuses cached decrypted invoice data, synchronizes payment status, caches missing records, and switches notifications to react-hot-toast.

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
Loading

Possibly related PRs

Suggested labels: Typescript Lang

Suggested reviewers: adityabhattad2021

Poem

A bunny found invoices tucked away,
In IndexedDB beneath the hay.
Receipts bloom with IDs bright,
Cached data makes the path just right.
Toasts hop hot through every day.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: introducing IndexedDB-based storage.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@socket-security

socket-security Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​idb@​8.0.310010010080100
Addednpm/​@​aossie-org/​idb-backup@​1.0.0100100100100100

View full report

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 584c0dc and 11c62dd.

📒 Files selected for processing (11)
  • frontend/package.json
  • frontend/src/hooks/useInvoiceExport.js
  • frontend/src/hooks/useInvoiceStorage.js
  • frontend/src/page/BatchPayment.jsx
  • frontend/src/page/CreateInvoice.jsx
  • frontend/src/page/CreateInvoicesBatch.jsx
  • frontend/src/page/ReceivedInvoice.jsx
  • frontend/src/page/SentInvoice.jsx
  • frontend/src/services/invoiceStorage/index.js
  • frontend/src/services/invoiceStorage/invoiceBackup.js
  • frontend/src/services/invoiceStorage/invoiceDB.js

Comment thread frontend/src/page/BatchPayment.jsx
Comment thread frontend/src/page/CreateInvoice.jsx
Comment thread frontend/src/page/ReceivedInvoice.jsx
Comment thread frontend/src/page/SentInvoice.jsx
Comment thread frontend/src/services/invoiceStorage/invoiceBackup.js
Comment thread frontend/src/services/invoiceStorage/invoiceDB.js
Comment thread frontend/src/services/invoiceStorage/invoiceDB.js
Comment thread frontend/src/services/invoiceStorage/invoiceDB.js
Comment thread frontend/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
@kumawatkaran523
kumawatkaran523 merged commit 56caa69 into StabilityNexus:main Jul 12, 2026
4 of 5 checks passed
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