Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix all the react lint errors #277

Merged
merged 2 commits into from
Feb 13, 2025
Merged

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Feb 13, 2025

Now bun run build does not show any lint errors, and also fixed some re-rendering of components in some cases.

This should have no visual or functional effect on the application.

Summary by CodeRabbit

  • New Features

    • Animated elements now update dynamically, enhancing visual responsiveness.
    • Countdown timers update every second for improved accuracy.
    • Modal and wallet visuals now use optimized images for better performance.
  • Refactor

    • Updated forms and token lists for more efficient state reactivity.
    • Streamlined wallet connection handling for clearer user interactions.
    • Removed an outdated chain display component.
  • Tests

    • Adjusted image rendering in tests to simplify maintenance.

@hansl hansl requested a review from chalabi2 February 13, 2025 19:05
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Warning

Rate limit exceeded

@hansl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b48a892 and db381a7.

📒 Files selected for processing (1)
  • components/wallet.tsx (3 hunks)

Walkthrough

This pull request introduces several dependency array updates in memoization and effects across multiple components, ensuring dynamic recalculations upon prop and state changes. The changes also include replacing standard <img> tags with Next.js’ optimized Image component in select modals, along with streamlined error handling in modal components. Additionally, it refactors and removes legacy components such as ChainCard and its types, and adjusts test mocks for image components. Minor control flow updates have been applied to components managing countdown timers and wallet connection logic.

Changes

File(s) Change Summary
components/3js/animatedMesh.tsx, components/bank/components/tokenList.tsx, components/bank/forms/ibcSendForm.tsx, components/bank/forms/sendForm.tsx Updated dependency arrays for hooks (useMemo/useEffect) to recalculate values when relevant props (e.g., shapeGeo, pageSize, balances, ibcChains) change.
components/admins/modals/validatorModal.tsx, components/react/authSignerModal.tsx Replaced <img> tags with Next.js’ Image component including specific width and height attributes; simplified related expressions.
components/react/chain-card.tsx, components/react/index.ts, components/types.tsx Removed ChainCard component, its export, and the related ChainCardProps interface.
components/react/modal.tsx Added new error types to the WALLET_ERRORS constant and updated dependency arrays in related hooks to improve QR code actions and error handling.
components/factory/components/__tests__/DenomImage.test.tsx Introduced a mock for the next/image module to simplify image rendering during tests.
components/groups/components/CountdownTimer.tsx Replaced a standalone time calculation function with a state variable updated every second via setInterval, recalculating the countdown via useMemo.
components/wallet.tsx Streamlined wallet connection logic by removing unused memoizations, updating the connect function to synchronous error handling, and restructuring button rendering.

Sequence Diagram(s)

sequenceDiagram
    participant IbcSendForm
    participant State
    IbcSendForm->>State: useEffect triggers when [ibcChains, isGroup] change
    State-->>IbcSendForm: Provide updated chain info
    IbcSendForm->>IbcSendForm: Recompute filteredBalances & initialSelectedToken via useMemo
Loading
sequenceDiagram
    participant CountdownTimer
    participant Timer
    CountdownTimer->>Timer: setInterval (1-sec updates)
    Timer-->>CountdownTimer: Update current time ("now")
    CountdownTimer->>CountdownTimer: Recompute timeLeft using useMemo
Loading

Possibly related PRs

Suggested labels

enhancement, bug

Suggested reviewers

  • fmorency

Poem

I'm a rabbit on a coding spree,
Hopping through hooks so naturally.
Dependencies now dance in time,
With images optimized, so sublime.
Code leaps forward as I cheer with glee 🐇✨!


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.

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 26.53061% with 180 lines in your changes missing coverage. Please review.

Project coverage is 53.53%. Comparing base (74ee6c5) to head (db381a7).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
components/react/modal.tsx 23.25% 99 Missing ⚠️
components/wallet.tsx 2.40% 81 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #277      +/-   ##
==========================================
+ Coverage   53.51%   53.53%   +0.01%     
==========================================
  Files         210      209       -1     
  Lines       17228    17233       +5     
==========================================
+ Hits         9220     9226       +6     
+ Misses       8008     8007       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 4

🧹 Nitpick comments (1)
components/wallet.tsx (1)

181-184: Enhance error handling in onClickConnect.

The error handling could be improved by providing more context and potentially showing an error notification to the user.

 const onClickConnect: MouseEventHandler = e => {
   e.preventDefault();
-  connect().catch(console.error);
+  connect().catch(error => {
+    console.error('Failed to connect wallet:', error);
+    // Show error notification to user
+  });
 };
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 181-181: components/wallet.tsx#L181
Added line #L181 was not covered by tests


[warning] 183-183: components/wallet.tsx#L183
Added line #L183 was not covered by tests

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5d41c2 and b48a892.

📒 Files selected for processing (13)
  • components/3js/animatedMesh.tsx (1 hunks)
  • components/admins/modals/validatorModal.tsx (3 hunks)
  • components/bank/components/tokenList.tsx (1 hunks)
  • components/bank/forms/ibcSendForm.tsx (1 hunks)
  • components/bank/forms/sendForm.tsx (2 hunks)
  • components/factory/components/__tests__/DenomImage.test.tsx (1 hunks)
  • components/groups/components/CountdownTimer.tsx (2 hunks)
  • components/react/authSignerModal.tsx (3 hunks)
  • components/react/chain-card.tsx (0 hunks)
  • components/react/index.ts (0 hunks)
  • components/react/modal.tsx (2 hunks)
  • components/types.tsx (0 hunks)
  • components/wallet.tsx (3 hunks)
💤 Files with no reviewable changes (3)
  • components/types.tsx
  • components/react/index.ts
  • components/react/chain-card.tsx
🧰 Additional context used
🧠 Learnings (1)
components/react/authSignerModal.tsx (1)
Learnt from: fmorency
PR: liftedinit/manifest-app#257
File: components/react/authSignerModal.tsx:313-313
Timestamp: 2025-02-12T14:01:23.163Z
Learning: The `SignModal` component in `components/react/authSignerModal.tsx` should use native `<img>` tags instead of `next/image` to maintain framework agnosticism and reusability across different React applications.
🪛 Biome (1.9.4)
components/react/modal.tsx

[error] 457-457: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 458-458: Forbidden extra non-null assertion.

Safe fix: Remove extra non-null assertion.

(lint/suspicious/noExtraNonNullAssertion)


[error] 462-462: Forbidden extra non-null assertion.

Safe fix: Remove extra non-null assertion.

(lint/suspicious/noExtraNonNullAssertion)

🪛 GitHub Check: codecov/patch
components/react/modal.tsx

[warning] 398-417: components/react/modal.tsx#L398-L417
Added lines #L398 - L417 were not covered by tests


[warning] 420-420: components/react/modal.tsx#L420
Added line #L420 was not covered by tests


[warning] 423-430: components/react/modal.tsx#L423-L430
Added lines #L423 - L430 were not covered by tests


[warning] 433-436: components/react/modal.tsx#L433-L436
Added lines #L433 - L436 were not covered by tests


[warning] 439-439: components/react/modal.tsx#L439
Added line #L439 was not covered by tests


[warning] 442-452: components/react/modal.tsx#L442-L452
Added lines #L442 - L452 were not covered by tests


[warning] 455-455: components/react/modal.tsx#L455
Added line #L455 was not covered by tests


[warning] 457-462: components/react/modal.tsx#L457-L462
Added lines #L457 - L462 were not covered by tests


[warning] 465-473: components/react/modal.tsx#L465-L473
Added lines #L465 - L473 were not covered by tests


[warning] 476-478: components/react/modal.tsx#L476-L478
Added lines #L476 - L478 were not covered by tests


[warning] 481-489: components/react/modal.tsx#L481-L489
Added lines #L481 - L489 were not covered by tests


[warning] 492-499: components/react/modal.tsx#L492-L499
Added lines #L492 - L499 were not covered by tests


[warning] 501-503: components/react/modal.tsx#L501-L503
Added lines #L501 - L503 were not covered by tests


[warning] 506-515: components/react/modal.tsx#L506-L515
Added lines #L506 - L515 were not covered by tests


[warning] 520-522: components/react/modal.tsx#L520-L522
Added lines #L520 - L522 were not covered by tests


[warning] 524-525: components/react/modal.tsx#L524-L525
Added lines #L524 - L525 were not covered by tests

components/wallet.tsx

[warning] 116-116: components/wallet.tsx#L116
Added line #L116 was not covered by tests


[warning] 181-181: components/wallet.tsx#L181
Added line #L181 was not covered by tests


[warning] 183-183: components/wallet.tsx#L183
Added line #L183 was not covered by tests


[warning] 186-186: components/wallet.tsx#L186
Added line #L186 was not covered by tests


[warning] 188-193: components/wallet.tsx#L188-L193
Added lines #L188 - L193 were not covered by tests


[warning] 195-209: components/wallet.tsx#L195-L209
Added lines #L195 - L209 were not covered by tests


[warning] 211-224: components/wallet.tsx#L211-L224
Added lines #L211 - L224 were not covered by tests


[warning] 226-264: components/wallet.tsx#L226-L264
Added lines #L226 - L264 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (12)
components/factory/components/__tests__/DenomImage.test.tsx (1)

18-18: LGTM! ESLint suppressions are appropriate for test mocks.

The ESLint disable comments are correctly used to suppress warnings about image elements in the test environment where we're mocking Next.js' Image component.

components/groups/components/CountdownTimer.tsx (1)

4-20: Great optimization of the countdown timer logic!

The refactoring improves the component by:

  1. Using a single source of truth for current time
  2. Properly cleaning up the interval on unmount
  3. Memoizing time calculations with correct dependencies
components/3js/animatedMesh.tsx (1)

60-60: Correct fix for geometry recalculation!

Adding shapeGeo to the dependency array ensures that the geometry is properly recreated when the shape type changes, preventing stale renders.

components/bank/components/tokenList.tsx (1)

85-85: Good optimization of skeleton items memoization!

Removing totalPages from the dependency array is correct since skeleton items only depend on pageSize. This prevents unnecessary recalculations when totalPages changes.

components/wallet.tsx (1)

116-116:

❓ Verification inconclusive

Verify the dependency array change.

The dependency array for _renderWalletContent has been simplified by removing username and address. While this may improve performance by reducing re-renders, verify that the component still updates correctly when these values change.


🏁 Script executed:

#!/bin/bash
# Search for usages of username or address within the component's render logic
rg -A 5 'username|address' components/wallet.tsx

Length of output: 2471


Dependency Array Verification for Memoized Render Logic

The dependency array for _renderWalletContent now only includes [localStatus, connect, openView]. However, since username and address are still used elsewhere in the render logic (as verified by the grep output), please ensure that omitting them from the dependency array does not lead to stale renders when these values change. Verify that any UI elements relying on username or address update as expected when these values are updated.

  • Confirm that excluding username and address from the _renderWalletContent dependencies does not affect the component's re-rendering behavior.
  • Consider revisiting whether these values should be added back to the dependency array if they directly affect the memoized output.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 116-116: components/wallet.tsx#L116
Added line #L116 was not covered by tests

components/react/authSignerModal.tsx (1)

343-343: Approve the simplified walletIconString assignment.

Good simplification of the walletIconString assignment by removing the unnecessary nullish coalescing operator.

components/bank/forms/sendForm.tsx (1)

53-55: LGTM! Improved memoization dependencies.

Good improvement to include balances in the dependency array. This ensures initialSelectedToken updates correctly when balances change.

components/react/modal.tsx (3)

51-68: LGTM! Enhanced error handling.

The addition of new error types and the updated error checking function improve the robustness of the wallet connection flow.


156-156: LGTM! Fixed hook dependencies.

Adding setQrMessage and setQRState to the dependency array ensures proper state updates and aligns with React's rules of hooks.


386-550:

❓ Verification inconclusive

Add test coverage for modal views.

The refactored _render function and its various modal views lack test coverage. Consider adding tests for:

  • Email/SMS input flows
  • Connected/Connecting states
  • QR code view
  • Error handling
  • Contact selection

Run the following script to check current test coverage:


🏁 Script executed:

#!/bin/bash
# Description: Check test coverage for modal views

# Search for existing tests
rg -A 5 "describe.*TailwindModal|test.*TailwindModal|it.*TailwindModal" --type test

Length of output: 114


Please Add or Verify Test Coverage for Modal Views

The refactored _render function still lacks any automated test coverage for the various modal states. The initial test search using rg --type test returned an error instead of a clear result, so it’s unclear if tests exist under a different naming convention. Please verify manually that tests are in place or add them for:

  • Email/SMS Input Flows: Validate that the email and SMS flows set the login hint and handle connection errors appropriately.
  • Connected/Connecting States: Ensure that the transitions for connected and connecting states behave correctly, especially with tailored messages.
  • QR Code View: Confirm that the QR code modal renders and responds to user actions as expected.
  • Error Handling: Check that error conditions trigger the proper UI responses and callbacks.
  • Contact Selection: Test that the contacts view supports both selection modes, including the message edit modal trigger.
🧰 Tools
🪛 Biome (1.9.4)

[error] 457-457: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 458-458: Forbidden extra non-null assertion.

Safe fix: Remove extra non-null assertion.

(lint/suspicious/noExtraNonNullAssertion)


[error] 462-462: Forbidden extra non-null assertion.

Safe fix: Remove extra non-null assertion.

(lint/suspicious/noExtraNonNullAssertion)

🪛 GitHub Check: codecov/patch

[warning] 398-417: components/react/modal.tsx#L398-L417
Added lines #L398 - L417 were not covered by tests


[warning] 420-420: components/react/modal.tsx#L420
Added line #L420 was not covered by tests


[warning] 423-430: components/react/modal.tsx#L423-L430
Added lines #L423 - L430 were not covered by tests


[warning] 433-436: components/react/modal.tsx#L433-L436
Added lines #L433 - L436 were not covered by tests


[warning] 439-439: components/react/modal.tsx#L439
Added line #L439 was not covered by tests


[warning] 442-452: components/react/modal.tsx#L442-L452
Added lines #L442 - L452 were not covered by tests


[warning] 455-455: components/react/modal.tsx#L455
Added line #L455 was not covered by tests


[warning] 457-462: components/react/modal.tsx#L457-L462
Added lines #L457 - L462 were not covered by tests


[warning] 465-473: components/react/modal.tsx#L465-L473
Added lines #L465 - L473 were not covered by tests


[warning] 476-478: components/react/modal.tsx#L476-L478
Added lines #L476 - L478 were not covered by tests


[warning] 481-489: components/react/modal.tsx#L481-L489
Added lines #L481 - L489 were not covered by tests


[warning] 492-499: components/react/modal.tsx#L492-L499
Added lines #L492 - L499 were not covered by tests


[warning] 501-503: components/react/modal.tsx#L501-L503
Added lines #L501 - L503 were not covered by tests


[warning] 506-515: components/react/modal.tsx#L506-L515
Added lines #L506 - L515 were not covered by tests


[warning] 520-522: components/react/modal.tsx#L520-L522
Added lines #L520 - L522 were not covered by tests


[warning] 524-525: components/react/modal.tsx#L524-L525
Added lines #L524 - L525 were not covered by tests

components/bank/forms/ibcSendForm.tsx (2)

91-91: LGTM! Fixed hook dependencies.

Adding ibcChains to the dependency array ensures that the initial chain is correctly set when the available chains change.


99-99: Optimize memoization dependencies.

The changes to the dependency arrays in filteredBalances and initialSelectedToken have different impacts:

  1. Removing selectedFromChain from filteredBalances is correct as it's not used in the calculation.
  2. Adding balances to initialSelectedToken ensures proper updates when balances change.

Also applies to: 104-104

Copy link
Collaborator

@chalabi2 chalabi2 left a comment

Choose a reason for hiding this comment

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

looks good to me!

@hansl hansl merged commit 3c09adf into liftedinit:main Feb 13, 2025
4 of 5 checks passed
@hansl hansl deleted the react-lint branch February 13, 2025 19:59
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