Skip to content

Conversation

@rodrigopavezi
Copy link
Member

@rodrigopavezi rodrigopavezi commented Jan 21, 2025

Fixes #229

Problem

Dashboard component does not work with SDK pagination and request query caching so UX for showing encrypted requests is too slow as it has to load all the wallets requests at once.

Changes

Add support to SDK pagination so it can retrieve requests on demand
Add query caching with prefetching so it enhances UX

Summary by CodeRabbit

Release Notes

  • New Features

    • Added pagination support for request viewing.
    • Implemented advanced data fetching with query management.
  • Dependencies

    • Added @tanstack/svelte-query library for improved data handling.
    • Updated various dependencies for enhanced functionality.
  • Performance

    • Enhanced request retrieval with caching and stale-time optimization.
    • Improved data management for request lists.
  • Chores

    • Removed outdated changelog files from several packages.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces a new dependency, @tanstack/svelte-query, to manage data fetching and caching in the project. It implements pagination in the view-requests.svelte file by adding variables and functions to handle request fetching asynchronously. A new file, queryClient.ts, is created to export a configured queryClient instance. Additionally, several CHANGELOG.md files are removed across different packages, eliminating historical records of version changes.

Changes

File Change Summary
package.json Added @tanstack/svelte-query dependency at version ^5.64.2
packages/invoice-dashboard/src/lib/view-requests.svelte - Added pagination variables (itemsPerPage, currentPage, hasMoreRequests)
- Introduced fetchRequests and getRequestsQueryKey functions
- Modified request fetching logic to use queryClient
shared/utils/queryClient.ts Created new file exporting queryClient with default query configuration
packages/add-stakeholder/CHANGELOG.md Removed file documenting version history
packages/create-invoice-form/CHANGELOG.md Removed file documenting version history
packages/invoice-dashboard/CHANGELOG.md Removed file documenting version history
packages/payment-widget/CHANGELOG.md Removed file documenting version history
packages/create-invoice-form/package.json Updated version from 0.12.1 to 0.12.2 and updated dependencies
packages/invoice-dashboard/package.json Updated version from 0.13.0 to 0.14.0 and updated dependencies
packages/payment-widget/package.json Updated version from 0.3.7 to 0.3.8

Sequence Diagram

sequenceDiagram
    participant UI as View Requests UI
    participant QC as QueryClient
    participant API as Request Network API

    UI->>QC: fetchQuery(requestsQueryKey)
    QC->>API: Fetch Requests
    API-->>QC: Return Paginated Requests
    QC-->>UI: Update Requests Data
    UI->>UI: Render Requests
    UI->>QC: Check hasMoreRequests
Loading

Possibly related PRs

Suggested reviewers

  • MantisClone
  • aimensahnoun

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rodrigopavezi rodrigopavezi marked this pull request as ready for review January 21, 2025 01:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/invoice-dashboard/src/lib/view-requests.svelte (2)

209-209: Remove unnecessary console.log statement

The console.log statement can clutter production logs and potentially expose sensitive information. It's advisable to remove it or replace it with a proper logging mechanism if needed.

Apply this diff to remove the console log:

-          console.log("requestsData", requestsData);

526-526: Avoid redundant loading state assignment

The getRequests function already manages the loading state by setting it to false upon completion. Setting loading = false; here is redundant and may lead to inconsistencies.

Apply this diff to remove the redundant assignment:

-        loading = false;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5193365 and 5afdf2a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • packages/invoice-dashboard/src/lib/view-requests.svelte (9 hunks)
  • shared/utils/queryClient.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • shared/utils/queryClient.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
package.json (1)

34-34: Verify @tanstack/svelte-query version and security.

The addition of @tanstack/svelte-query aligns well with the PR objectives for implementing pagination and caching. However, let's verify the version specification.

Let's check for the latest stable version and any security advisories:

✅ Verification successful

@tanstack/svelte-query version is up-to-date and secure.

You're using the latest version (5.64.2) released on January 19, 2025, and there are no security advisories for this package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify @tanstack/svelte-query version and security

# Check NPM for latest version
echo "Latest version from NPM:"
npm view @tanstack/svelte-query version

# Check for security advisories
echo -e "\nSecurity advisories:"
npm audit @tanstack/svelte-query@5.64.2

# Check release date to ensure it's a stable version
echo -e "\nRelease date:"
npm view @tanstack/svelte-query@5.64.2 time.modified

Length of output: 17175

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/invoice-dashboard/src/lib/view-requests.svelte (4)

115-117: Consider making itemsPerPage configurable.

The page size is currently hardcoded to 10. Consider making it configurable through props to allow for different use cases and screen sizes.

-  const itemsPerPage = 10;
+  export let itemsPerPage = 10;

199-214: Enhance error handling and type safety in fetchRequests.

Consider these improvements:

  1. Add retry logic for transient failures
  2. Add TypeScript return type annotation
  3. Add specific error types for better error handling
-  const fetchRequests = async (address: string, page: number, pageSize: number) => {
+  const fetchRequests = async (address: string, page: number, pageSize: number): Promise<Types.IRequestData | null> => {
     if (!address || !requestNetwork) return null;
     try {
       const requestsData = await requestNetwork.fromIdentity({
         type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
         value: address,
       }, undefined, { 
         page: page,
         pageSize: pageSize,
       });
       return requestsData;
     } catch (error) {
-      console.error("Failed to fetch requests:", error);
-      throw error;
+      if (error instanceof NetworkError) {
+        console.error("Network error while fetching requests:", error);
+        throw new Error(`Failed to fetch requests: ${error.message}`);
+      }
+      console.error("Unexpected error while fetching requests:", error);
+      throw error;
     }
   };

Line range hint 944-967: Add ARIA labels for better accessibility.

The pagination buttons should have proper ARIA labels to improve accessibility for screen readers.

 <button
   class="chevron-button"
   disabled={currentPage === 1}
+  aria-label="Previous page"
   on:click={() => goToPage(currentPage - 1)}
 >
   <i>
     <ChevronLeft />
   </i>
 </button>

 <button
   class="chevron-button"
   disabled={!hasMoreRequests}
+  aria-label="Next page"
   on:click={() => goToPage(currentPage + 1)}
 >
   <i>
     <ChevronRight />
   </i>
 </button>

529-531: Optimize query invalidation and refetch.

The current implementation invalidates queries and immediately triggers a refetch, which could cause unnecessary network requests. Consider using the invalidateQueries options to control refetching behavior.

-    queryClient.invalidateQueries()
-    await getRequests(currentAccount, currentRequestNetwork);
+    await queryClient.invalidateQueries({
+      queryKey: ['requestsData'],
+      refetchType: 'active'
+    });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5afdf2a and 6789b14.

📒 Files selected for processing (1)
  • packages/invoice-dashboard/src/lib/view-requests.svelte (9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
packages/invoice-dashboard/src/lib/view-requests.svelte (1)

223-242: Well-implemented query caching and prefetching!

The implementation includes several good practices:

  • Proper query key management
  • Data nullability handling
  • Next page prefetching for better UX
  • Appropriate error handling

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
packages/invoice-dashboard/package.json (1)

Line range hint 1-70: Add missing @tanstack/svelte-query dependency.

The AI summary indicates that @tanstack/svelte-query is used for managing data fetching and caching, but it's not listed in the dependencies.

  "dependencies": {
+   "@tanstack/svelte-query": "^5.0.0",
    "@requestnetwork/payment-detection": "0.51.0",
    "@requestnetwork/payment-processor": "0.54.0",
    "@requestnetwork/request-client.js": "0.56.0",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6789b14 and 3fa8ef4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • packages/add-stakeholder/CHANGELOG.md (0 hunks)
  • packages/create-invoice-form/CHANGELOG.md (0 hunks)
  • packages/create-invoice-form/package.json (2 hunks)
  • packages/invoice-dashboard/CHANGELOG.md (0 hunks)
  • packages/invoice-dashboard/package.json (2 hunks)
  • packages/payment-widget/CHANGELOG.md (0 hunks)
  • packages/payment-widget/package.json (2 hunks)
  • packages/single-invoice/package.json (2 hunks)
💤 Files with no reviewable changes (4)
  • packages/invoice-dashboard/CHANGELOG.md
  • packages/add-stakeholder/CHANGELOG.md
  • packages/create-invoice-form/CHANGELOG.md
  • packages/payment-widget/CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (6)
packages/single-invoice/package.json (1)

3-3: LGTM on version bump.

The version change from 0.0.0 to 0.1.1 follows semantic versioning principles, appropriate for a first minor release.

packages/payment-widget/package.json (2)

3-3: Verify if version bump aligns with changes.

The minor version bump from 0.3.7 to 0.3.8 suggests backward-compatible changes. Let's verify if this aligns with the changes in this package.

✅ Verification successful

Version bump is appropriate for the changes

The version bump from 0.3.7 to 0.3.8 aligns with the scope of changes, which only includes dependency updates to @RequestNetwork packages. This follows semantic versioning principles for patch-level changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the scope of changes in this package to verify if version bump is appropriate

# Check for breaking changes in this package
git diff HEAD~1 packages/payment-widget/ | grep '^[-+]' | grep -v '^[-+]package.json' | grep -v '^[-+]package-lock.json'

# Check commit messages for this package
git log -n 10 --oneline packages/payment-widget/

Length of output: 931


59-61: Verify if @tanstack/svelte-query is needed in this package.

The PR objectives mention implementing query caching, and the AI summary indicates the addition of @tanstack/svelte-query. However, this dependency is not listed here. Let's verify if this package requires it.

packages/create-invoice-form/package.json (2)

3-3: Consider bumping the minor version instead of patch.

The PR implements new features (pagination with caching) rather than just bug fixes. According to semantic versioning, new features should trigger a minor version bump (0.13.0) rather than a patch version bump (0.12.2).


36-37: Verify compatibility with the updated dependencies.

The updates to @requestnetwork/data-format (0.19.7) and @requestnetwork/request-client.js (0.56.0) might include breaking changes. Please ensure:

  1. The new request-client.js version supports the pagination features being implemented
  2. All features depending on these libraries still work as expected
packages/invoice-dashboard/package.json (1)

40-42: LGTM! Dependencies are consistently updated.

The minor version updates across all RequestNetwork dependencies are consistent, which is good practice.

@rodrigopavezi rodrigopavezi merged commit 4014447 into main Jan 22, 2025
2 checks passed
@rodrigopavezi rodrigopavezi deleted the feat/pagination branch January 22, 2025 20:15
@MantisClone MantisClone linked an issue Mar 3, 2025 that may be closed by this pull request
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.

Add Tanstack query to Invoicing dashboard (cache)

5 participants