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

2.2.x b1 #675

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

2.2.x b1 #675

wants to merge 14 commits into from

Conversation

mjadach-iv
Copy link
Contributor

@mjadach-iv mjadach-iv commented Mar 21, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced user interactions in various modals by adding keyboard support (triggering actions with the Enter key) and improved input validation and autofocus management.
    • Introduced a new SessionsPage component for managing session data and retrieving session-related information upon connecting to the node.
    • Added an OpenSessionModal for managing session interactions within the messaging application.
    • Upgraded ticket management with bulk ticket redemption and a new reset option, along with expanded details on network metrics such as current log status and network probability visible in info views.
  • Chores

    • Updated project version to 2.2.0-beta.1 with dependency improvements.

Copy link

coderabbitai bot commented Mar 21, 2025

📝 Walkthrough

Walkthrough

The pull request removes numerous exported constants from the configuration file and updates the project version and dependency in package.json. Several modal components now include new state variables for enabling actions, keydown event listeners (specifically handling the Enter key), and improved focus/blur behavior. Additionally, modifications have been made across various pages to adjust state management and event handling. Redux-related files have been updated to rename ticket redemption identifiers and to add new thunks and state properties. Lastly, a new dispatch is added in the routing logic to retrieve session-related information after login.

Changes

File(s) Change Summary
config.ts Removed exported constants for smart contracts, safe contracts, subgraphs, wallet connect, and funding requirements; retained only the environment export.
package.json Updated project version from 2.1.15 to 2.2.0-beta.1 and upgraded @hoprnet/hopr-sdk from 2.1.9 to 2.2.0-beta.5.
src/components/ConnectNode/modal.tsx
src/components/Modal/node/{AddAliasModal,FundChannelModal,OpenChannelModal,OpenMultipleChannelsModal,PingModal,SendMessageModal,WithdrawModal}.tsx
Added new state variables (e.g. canConnectToNode, canAddAlias, canFund, canOpen, canPing, canSendMessage, canWithdraw), introduced Enter key event listeners and corresponding handleEnter functions, updated button disabled logic and autoFocus properties, and included input blurring on modal opening.
src/pages/node/aliases.tsx Integrated new Redux selectors and variables (peerId, peerIdToAliasLink, peerIdsWithAliases), updated CSV upload logic to conditionally manage aliases, and reformatted object destructuring.
src/pages/node/configuration.tsx Introduced a new canSave constant and a handleEnter function for saving settings; converted handleSaveSettings from an async arrow function to a regular function; updated keydown event handling and button disabled state.
src/pages/node/info/index.tsx Removed obsolete block number variables and replaced them with new Redux selectors (indexerLastLogBlock, indexerLastLogChecksum, minimumNetworkProbability); adjusted JSX to display the updated state.
src/pages/node/tickets.tsx Renamed ticket redemption variables to redeemAllTickets, modified the redemption function to include apiEndpoint and apiToken, introduced a new function for resetting ticket statistics, and integrated additional ticket info (info, ticketPrice, minimumNetworkProbability) into state management and UI components.
src/store/slices/node/{actionsAsync.ts,actionsFetching.ts,initialState.ts} Renamed thunks and actions from redeemTickets to redeemAllTickets, added new thunks (resetTicketStatisticsThunk, getMinimumNetworkProbabilityThunk), incorporated a new probability property in the state, and updated fetching state handling accordingly.
src/router.tsx Added a new dispatch call to trigger getSessionsThunk (with apiEndpoint and apiToken) after a successful login.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant M as Modal Component
    participant E as Keydown Listener
    participant A as Action Handler

    U->>M: Open modal
    M->>E: Attach keydown (Enter) event listener
    U->>M: Press Enter key
    E->>M: Invoke handleEnter()
    alt Valid input & modal open
        M->>A: Execute associated action (e.g., connect, add alias, fund)
    else Invalid/disabled
        M-->>U: No action triggered
    end
Loading
sequenceDiagram
    participant U as User
    participant R as Router/Layout
    participant S as Redux Store

    U->>R: Successful login
    R->>S: Dispatch getSessionsThunk({apiEndpoint, apiToken})
    S-->>R: Update session state
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

@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: 2

🧹 Nitpick comments (14)
src/future-hopr-lib-components/PeerInfo/index.tsx (1)

31-35: Enhanced Destructuring in PeersInfo

The multi-line destructuring of props (extracting peerId, nodeAddress, and the rest via ...rest) increases readability. Note that while peerId and nodeAddress are immediately extracted, other props (e.g. shortenPeerId and shortenPeerIdIfAliasPresent) are still accessed via props. For uniformity, consider destructuring all used properties if that suits the project style.

src/future-hopr-lib-components/Modal/index.tsx (1)

39-48: Refined Component Props Destructuring in Modal

The Modal component now destructures its props (onClose, selectedValue, open, title, children, maxWidth, and disableScrollLock) in a multi-line format, enhancing readability. As a side note, the use of @ts-ignore in the handleClose function suggests there may be a type mismatch; consider revisiting the type definitions for onClose to eliminate the need for suppression.

src/future-hopr-lib-components/Modal/styled.tsx (1)

4-7: Enhanced Destructuring Improves Readability

The multi-line destructuring of the props (extracting maxWidth and the rest) in the SDialog component improves code clarity and maintainability without altering functionality.

src/components/Modal/node/FundChannelModal.tsx (1)

113-118: Minor typesafety improvement opportunity

While the keyboard event handler works correctly, consider using the more specific KeyboardEvent type instead of any for better type safety.

-function handleEnter(event: any) {
+function handleEnter(event: KeyboardEvent) {
src/pages/node/configuration.tsx (3)

65-70: Consider updating the useEffect dependency array.

The dependency array only includes localNotificationSettings, but the handleEnter function also depends on canSave. This could potentially lead to stale closures where the event handler uses outdated values.

- }, [localNotificationSettings]);
+ }, [localNotificationSettings, canSave]);

134-138: Consider using a more specific type for the event parameter.

The event: any type is too generic and loses type safety. Using the imported KeyboardEvent type would be more appropriate.

-function handleEnter(event: any) {
+function handleEnter(event: KeyboardEvent) {
-  if (canSave && (event as KeyboardEvent).key === 'Enter') {
+  if (canSave && event.key === 'Enter') {
    handleSaveSettings();
  }
}

168-168: Remove console.log statement.

This console.log statement should be removed before merging to production.

-                        console.log('localNotificationSettings', localNotificationSettings);
src/store/slices/node/actionsFetching.ts (1)

89-94: Good implementation of reducer cases for new actions.

The reducer cases for the new actions are well-implemented and follow the same pattern as existing cases. However, there's a minor formatting issue with the semicolon placement.

  builder.addCase(setRedeemAllTicketsFetching, (state, action) => {
    state.redeemAllTickets.isFetching = action.payload;
-  });
+  }),
  builder.addCase(setResetTicketStatisticsFetching, (state, action) => {
    state.resetTicketStatistics.isFetching = action.payload;
  });
src/components/Modal/node/SendMessageModal.tsx (3)

116-122: Good addition of the canSendMessage variable but check the logic.

The variable neatly encapsulates multiple conditions for enabling the send button, improving code readability. However, there may be a logical issue in one of the conditions:

(sendMode !== 'directMessage' && sendMode !== 'automaticPath' && numberOfHops < 0 && path === '')

Should this be using || between the numberOfHops < 0 and path === '' parts? As written, both conditions must be true, but the intent might be that either condition should disable sending.

Verify the intent of this condition, especially when sendMode is neither 'directMessage' nor 'automaticPath'.


132-137: Consider updating the useEffect dependency array.

The dependency array doesn't include canSendMessage which is used in the handleEnter function. This could potentially lead to stale closures.

- }, [loginData, message, selectedReceiver, sendMode]);
+ }, [loginData, message, selectedReceiver, sendMode, canSendMessage]);

282-287: Consider improving the handleEnter function.

There's unnecessary type casting and a console.log statement that should be removed before merging to production.

function handleEnter(event: KeyboardEvent) {
-  if (canSendMessage && (event as KeyboardEvent)?.key === 'Enter') {
+  if (canSendMessage && event.key === 'Enter') {
-    console.log('SendMessageModal event');
    handleSendMessage();
  }
}
src/components/Modal/node/WithdrawModal.tsx (2)

116-121: Consider updating the useEffect dependency array.

The dependency array includes all necessary state variables, but doesn't include canWithdraw which is used in the handleEnter function. This could potentially lead to stale closures.

- }, [recipient, amount, apiEndpoint, apiToken, currency, loginData]);
+ }, [recipient, amount, apiEndpoint, apiToken, currency, loginData, canWithdraw]);

197-202: Improve the handleEnter function.

The function has unnecessary type casting and a console.log statement that should be removed before merging to production.

-function handleEnter(event: any) {
+function handleEnter(event: KeyboardEvent) {
-  if (canWithdraw && (event as KeyboardEvent)?.key === 'Enter') {
+  if (canWithdraw && event.key === 'Enter') {
-    console.log('WithdrawModal event');
    handleWithdraw();
  }
}
src/pages/node/tickets.tsx (1)

95-106: Consider using distinct loading states for the two buttons

Both action buttons use redeemAllTicketsFetching for their loading state, which means they can't display independent loading states. This could confuse users if both actions are triggered in succession.

Consider using resetTicketStatistics.isFetching for the reset button's loading state:

-  reloading={redeemAllTicketsFetching}
+  reloading={useAppSelector((store) => store.node.resetTicketStatistics.isFetching)}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6cfaeb3 and abe4264.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (40)
  • config.ts (0 hunks)
  • package.json (1 hunks)
  • src/components/Card/index.tsx (1 hunks)
  • src/components/Code/CodeCopyBox/index.tsx (1 hunks)
  • src/components/ConnectNode/modal.tsx (3 hunks)
  • src/components/Faq/index.tsx (2 hunks)
  • src/components/Modal/node/AddAliasModal.tsx (5 hunks)
  • src/components/Modal/node/FundChannelModal.tsx (5 hunks)
  • src/components/Modal/node/OpenChannelModal.tsx (5 hunks)
  • src/components/Modal/node/OpenMultipleChannelsModal.tsx (4 hunks)
  • src/components/Modal/node/PingModal.tsx (5 hunks)
  • src/components/Modal/node/SendMessageModal.tsx (6 hunks)
  • src/components/Modal/node/WithdrawModal.tsx (7 hunks)
  • src/components/Stepper/index.tsx (1 hunks)
  • src/components/SubpageTitle/index.tsx (1 hunks)
  • src/future-hopr-lib-components/Button/chain-button.jsx (1 hunks)
  • src/future-hopr-lib-components/Button/index.tsx (1 hunks)
  • src/future-hopr-lib-components/Cards/GrayCard.tsx (1 hunks)
  • src/future-hopr-lib-components/Icons/JazzIcon.tsx (1 hunks)
  • src/future-hopr-lib-components/Modal/index.tsx (2 hunks)
  • src/future-hopr-lib-components/Modal/styled.tsx (1 hunks)
  • src/future-hopr-lib-components/NFT/index.jsx (1 hunks)
  • src/future-hopr-lib-components/Navbar/navBar.tsx (1 hunks)
  • src/future-hopr-lib-components/Navbar/navBarItems.tsx (1 hunks)
  • src/future-hopr-lib-components/Navbar/navButton.jsx (1 hunks)
  • src/future-hopr-lib-components/PeerInfo/index.tsx (1 hunks)
  • src/future-hopr-lib-components/Table/table-pro.tsx (1 hunks)
  • src/future-hopr-lib-components/Tooltip/tooltip-fixed-width.tsx (1 hunks)
  • src/hooks/useWatcher/index.ts (1 hunks)
  • src/pages/node/aliases.tsx (1 hunks)
  • src/pages/node/configuration.tsx (5 hunks)
  • src/pages/node/info/index.tsx (1 hunks)
  • src/pages/node/messages.tsx (1 hunks)
  • src/pages/node/metrics.tsx (1 hunks)
  • src/pages/node/ping.tsx (1 hunks)
  • src/pages/node/tickets.tsx (4 hunks)
  • src/store/slices/auth/actionsAsync.ts (1 hunks)
  • src/store/slices/node/actionsAsync.ts (32 hunks)
  • src/store/slices/node/actionsFetching.ts (3 hunks)
  • src/store/slices/node/initialState.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • config.ts
🧰 Additional context used
🧬 Code Definitions (13)
src/future-hopr-lib-components/Tooltip/tooltip-fixed-width.tsx (2)
src/future-hopr-lib-components/Button/chain-button.jsx (1) (1)
  • rest (26-30)
src/future-hopr-lib-components/Navbar/navButton.jsx (1) (1)
  • rest (45-48)
src/future-hopr-lib-components/Button/chain-button.jsx (1)
src/future-hopr-lib-components/Navbar/navButton.jsx (1) (1)
  • rest (45-48)
src/future-hopr-lib-components/PeerInfo/index.tsx (2)
src/future-hopr-lib-components/Button/chain-button.jsx (1) (1)
  • rest (26-30)
src/future-hopr-lib-components/Navbar/navButton.jsx (1) (1)
  • rest (45-48)
src/hooks/useWatcher/index.ts (1)
src/store/index.ts (1) (1)
  • useAppSelector (26-26)
src/pages/node/messages.tsx (1)
src/store/index.ts (1) (1)
  • useAppSelector (26-26)
src/store/slices/auth/actionsAsync.ts (1)
src/store/index.ts (1) (1)
  • RootState (20-20)
src/pages/node/info/index.tsx (1)
src/store/index.ts (1) (1)
  • useAppSelector (26-26)
src/future-hopr-lib-components/Button/index.tsx (2)
src/future-hopr-lib-components/Button/chain-button.jsx (1) (1)
  • rest (26-30)
src/future-hopr-lib-components/Navbar/navButton.jsx (1) (1)
  • rest (45-48)
src/pages/node/configuration.tsx (1)
src/store/slices/app/index.ts (1) (1)
  • appActions (118-118)
src/components/Modal/node/WithdrawModal.tsx (1)
src/store/index.ts (1) (1)
  • useAppSelector (26-26)
src/store/slices/node/actionsAsync.ts (2)
src/store/slices/node/actionsFetching.ts (1) (1)
  • nodeActionsFetching (24-43)
src/store/index.ts (1) (1)
  • RootState (20-20)
src/pages/node/tickets.tsx (3)
src/store/index.ts (2) (2)
  • useAppDispatch (25-25)
  • useAppSelector (26-26)
src/store/slices/node/actionsAsync.ts (1) (1)
  • actionsAsync (1685-1719)
src/future-hopr-lib-components/Button/IconButton.tsx (1) (1)
  • IconButton (55-83)
src/components/Modal/node/OpenMultipleChannelsModal.tsx (2)
src/future-hopr-lib-components/Modal/styled.tsx (1) (1)
  • SDialogContent (25-33)
src/future-hopr-lib-components/Navbar/navButton.jsx (1) (1)
  • Button (44-109)
🔇 Additional comments (88)
src/components/Code/CodeCopyBox/index.tsx (1)

11-15: Improved code readability with multi-line destructuring.

The parameter destructuring has been reformatted from a single line to a multi-line format, improving readability without changing any functionality.

src/pages/node/ping.tsx (1)

20-23: Improved readability with multi-line object destructuring.

The destructuring of loginData has been reformatted from a single line to a multi-line format, which is consistent with similar formatting changes throughout the codebase.

package.json (2)

3-3: Version bump to beta release.

The project version has been updated from 2.1.15 to 2.2.0-beta.0, indicating this PR is preparing for a new beta release.


9-9:

❓ Verification inconclusive

SDK dependency update for compatibility with new version.

The @hoprnet/hopr-sdk dependency has been updated from version 2.1.9 to 2.2.0-beta.4 to align with the project's version bump.

Let's verify the compatibility between the new SDK version and the application's current implementation:


🏁 Script executed:

#!/bin/bash
# Look for any breaking changes or migration-related comments in the codebase
rg -i "breaking|migration|upgrade|2\.2\." --type ts --type tsx --type jsx

Length of output: 103


Below is an updated verification step. The previous search command failed due to an unrecognized file type error. To re‐verify the absence of any migration notes or breaking changes in TypeScript/TSX/JSX files related to the SDK upgrade, please run this revised script:

#!/bin/bash
# Re-run the search for migration or breaking changes related to the SDK upgrade
rg -i "breaking|migration|upgrade|2\.2\." -g "*.ts" -g "*.tsx" -g "*.jsx"

If no output is produced, it indicates no migration-related comments were found—suggesting that the dependency update to @hoprnet/[email protected] is aligned with the version bump. However, please manually verify the script’s output and ensure that no compatibility issues are missed.

Action:

  • Re-run the above script.
  • Confirm that no migration or breaking change messages are present.
  • Then approve the dependency update accordingly.
src/future-hopr-lib-components/Button/chain-button.jsx (1)

26-30: Improved readability with multi-line props destructuring.

The destructuring of the props object has been reformatted from a single line to a multi-line format, consistent with similar changes in other components (e.g., navButton.jsx).

src/future-hopr-lib-components/Navbar/navBarItems.tsx (1)

29-37: Improved Function Signature Formatting

The updated multi-line parameter formatting for the NavBarItems component enhances readability and aligns the code with our formatting guidelines. No change in functionality was introduced.

src/hooks/useWatcher/index.ts (1)

13-16: Improved Destructuring for API Credentials

Changing the destructuring of apiEndpoint and apiToken to a multi-line format improves clarity and consistency with similar changes elsewhere in the codebase.

src/pages/node/aliases.tsx (1)

341-345: Clearer Destructuring in handleChange

Switching to a multi-line destructuring for event.target in the handleChange function improves clarity without affecting functionality.

src/pages/node/messages.tsx (1)

19-22: Refined Destructuring for Auth Data

The updated multi-line destructuring for apiEndpoint and apiToken from the login data enhances the readability of the code. This change is consistent with similar updates in other parts of the codebase.
As a side note, please verify that omitting these variables from the dependency array in the associated useEffect is intentional.

src/future-hopr-lib-components/Icons/JazzIcon.tsx (1)

11-16: Enhanced Readability in Parameter Destructuring

The reformatting of the destructuring in the JazzIcon component—placing each parameter (address, diameter, className, and ...rest) on its own line—improves the code’s readability. There are no functional changes, and the component continues to perform as expected.

src/future-hopr-lib-components/Navbar/navButton.jsx (1)

45-48: Consistent Multi-Line Destructuring

The updated multi-line destructuring of the props object (extracting subMenu and the rest of the properties) enhances clarity and aligns with our formatting standards. No functionality has been altered.

src/future-hopr-lib-components/Tooltip/tooltip-fixed-width.tsx (1)

9-13: Improved Props Destructuring in Tooltip Component

Expanding the single-line destructuring into a multi-line format (listing className, notWide, and ...rest on separate lines) makes the component easier to read and maintain. The functionality remains unchanged.

src/future-hopr-lib-components/Modal/index.tsx (1)

11-14: Enhanced Destructuring in Styled SDialog Component

Reformatting the destructuring of props in the SDialog styled component (extracting maxWidthCss and ...rest) into multiple lines improves legibility without affecting behavior.

src/future-hopr-lib-components/Navbar/navBar.tsx (1)

17-21: Improved Destructuring in Styled AppBar Definition

The refactoring of the AppBar component’s props destructuring into a multi-line format (listing tallerNavBarOnMobile, webapp, and ...rest) significantly enhances readability. This change is purely stylistic and does not affect the component’s behavior.

src/pages/node/metrics.tsx (1)

159-162: Enhanced Readability through Multi-line Destructuring

By reformatting the destructuring of loginData into a multi-line structure, the code is now more readable and consistent with similar changes across the codebase. No functional changes are introduced.

src/components/SubpageTitle/index.tsx (1)

59-64: Improved Parameter Formatting in Component Signature

Transforming the SubpageTitle component’s function signature to a multi-line format makes the component's props clearer without modifying its functionality.

src/pages/node/info/index.tsx (1)

39-42: Consistent Multi-line Destructuring for Redux State

Expanding the destructuring of loginData into a multi-line format improves clarity and maintains consistency across different pages. The change is purely stylistic while keeping the logic intact.

src/future-hopr-lib-components/NFT/index.jsx (1)

60-68: Clearer Function Signature with Multi-line Destructuring

The adjusted multi-line destructuring in the CustomWidthTooltip component enhances readability without affecting its behavior. The formatting aligns well with similar improvements across components.

src/future-hopr-lib-components/Table/table-pro.tsx (1)

58-63: Refactored Pagination Props Destructuring for Clarity

Changing the destructuring of props (count, page, rowsPerPage, onPageChange) in the TablePaginationActions function into a multi-line format significantly improves the readability of the code. This is a purely cosmetic change with no impact on functionality.

src/components/Card/index.tsx (1)

56-62: Improved Parameter Formatting

The reformatting of the Card component’s parameters into a multi-line destructuring format enhances readability. No functional impact is introduced with this purely stylistic update.

src/components/Stepper/index.tsx (1)

154-157: Refactored Function Signature for Clarity

The updated multi-line destructuring in the getStepState function makes the parameter list (i.e., index and currentStep) clearer and easier to read. This change is purely cosmetic and does not affect the function’s logic.

src/future-hopr-lib-components/Cards/GrayCard.tsx (1)

85-94: Enhanced Parameter Destructuring in GrayCard

Splitting the props into separate lines in the GrayCard component improves code readability and adheres to consistent formatting practices without changing any functionality.

src/future-hopr-lib-components/Button/index.tsx (1)

101-111: Improved Props Destructuring in Button Component

The multi-line destructuring of the Button component’s props (including imageOnly, size70, standardWidth, etc.) enhances clarity. The changes are stylistic and have no impact on functionality.

src/components/Faq/index.tsx (2)

2-8: Good improvement on code readability.

Breaking down Material UI imports into multiple lines makes the code more maintainable and easier to read.


117-121: Function signature formatting improvement.

The multi-line destructuring pattern enhances readability and is consistent with the formatting changes across the codebase.

src/components/ConnectNode/modal.tsx (4)

153-153: Good variable extraction for condition logic.

Creating the canConnectToNode variable makes the code more readable and centralizes the condition logic.


155-160: Well-implemented keyboard event handling.

Adding the event listener for keyboard events enhances user experience by allowing keyboard navigation. The cleanup function properly removes the listener when the component unmounts.


369-374: Good implementation of Enter key functionality.

The handleEnter function improves user experience by allowing the Enter key to submit the form. The console log statement helps with debugging.


457-457: Consistent use of the new condition variable.

Using the canConnectToNode variable here maintains consistency with its definition above.

src/store/slices/auth/actionsAsync.ts (2)

8-11: Improved import destructuring format.

Breaking down the API destructuring into multiple lines improves readability.


17-24: Enhanced function parameter formatting.

The multi-line formatting of the thunk parameters and payload destructuring makes the code more readable and maintainable.

src/components/Modal/node/AddAliasModal.tsx (6)

37-43: Excellent consolidation of condition logic.

Creating the canAddAlias variable centralizes all validation conditions in one place, making the code more maintainable and easier to understand.


45-50: Well-implemented keyboard event handling.

Adding the event listener for keyboard events improves user experience. The cleanup function properly removes the listener on unmount.


76-76: Good UX improvement for modal opening.

Blurring the active element when opening the modal prevents unintended interactions and improves user experience.


139-144: Good implementation of Enter key functionality.

The handleEnter function improves form submission experience by supporting keyboard interaction, consistent with other modals in the application.


189-190: Smart autofocus implementation.

The conditional autofocus ensures the empty field receives focus, improving user experience when the modal opens.

Also applies to: 207-208


212-213: Consistent use of the consolidated condition variable.

Using the canAddAlias variable here maintains consistency with its definition above and simplifies the code.

src/components/Modal/node/PingModal.tsx (7)

1-1: Good update to imports

Adding the KeyboardEvent type import is necessary for the new keyboard event handling functionality.


30-30: Good refactoring with descriptive variable

Creating a dedicated canPing variable improves code readability by clearly expressing the condition for enabling the ping button.


32-37: Good implementation of keyboard event listener

The useEffect correctly sets up and cleans up the keyboard event listener. This follows React best practices for event handling.


54-54: Improved focus management

Blurring the active element when opening the modal provides a better user experience by removing focus from previously active elements.


119-124: Good addition of keyboard shortcut functionality

The handleEnter function enhances usability by allowing users to submit the form using the Enter key, which is a common UX pattern.


167-167: Enhanced user experience with autoFocus

Setting autoFocus on the input field improves usability by allowing immediate typing after the modal opens.


172-172: Improved code readability with canPing variable

Using the canPing variable instead of an inline condition makes the code more maintainable and easier to understand.

src/components/Modal/node/OpenMultipleChannelsModal.tsx (7)

1-1: Good update to imports

Adding the useRef import is necessary for the file input reference implementation.


29-29: Enhanced code readability with descriptive variable

Creating a dedicated canOpen variable improves code maintainability by centralizing the logic for enabling the action button.


31-36: Well-implemented keyboard event handling

The useEffect hook properly manages event listener lifecycle, adding it when dependencies change and cleaning it up on unmount.


179-179: Improved focus management

Blurring the active element before opening the file input dialog improves user experience by ensuring clear focus states.


183-188: Enhanced user experience with keyboard shortcuts

The handleEnter function properly implements the Enter key functionality, consistent with other modal components in the application.


244-244: Better user experience with autoFocus

Adding autoFocus to the amount field ensures users can immediately start typing after the CSV is loaded.


250-250: Improved code clarity with canOpen variable

Using the canOpen variable instead of repeating the validation logic inline makes the code more maintainable.

src/components/Modal/node/OpenChannelModal.tsx (7)

1-1: Good update to imports

Adding the useEffect import is necessary for the keyboard event handling implementation.


37-37: Enhanced code readability with descriptive variable

The canOpen variable centralizes the validation logic, making it reusable and self-documenting.


39-44: Properly implemented keyboard event handling

The useEffect hook correctly sets up and cleans up event listeners, with appropriate dependencies.


52-52: Improved focus management

Blurring the active element when opening the dialog ensures a clean focus state in the modal.


111-116: Enhanced user experience with keyboard shortcuts

The handleEnter function implementation is consistent with other modals, creating a unified user experience.


158-158: Smart implementation of conditional autoFocus

Alternating the autoFocus between fields based on whether peerAddress is already provided improves user workflow.

Also applies to: 168-168


174-174: Improved code clarity with canOpen variable

Using the canOpen variable for the button's disabled state ensures consistent validation throughout the component.

src/components/Modal/node/FundChannelModal.tsx (6)

1-1: Good update to imports

Adding the useEffect import supports the new keyboard event handling functionality.


31-31: Improved code clarity with canFund variable

The descriptive canFund variable makes the validation logic more readable and maintainable.


33-38: Well-implemented event handling

The useEffect hook properly manages the event listener lifecycle with appropriate dependencies.


41-41: Enhanced focus management

Blurring the active element before opening the dialog ensures a clean focus state transition.


155-155: Smart implementation of conditional autoFocus

The conditional autoFocus implementation intelligently focuses on the right field based on whether channelId is already provided.

Also applies to: 165-165


171-171: Improved code readability

Using the canFund variable for the button's disabled state makes the code more maintainable and self-documenting.

src/pages/node/configuration.tsx (3)

57-63: Good addition of the canSave variable for better code clarity.

This new boolean condition cleanly encapsulates the logic for determining when the save button should be enabled or disabled, making the code more readable and maintainable.


128-132: Nice refactoring from arrow function to regular function.

The function signature change from an async arrow function to a regular function is good for consistency.


235-235: Good use of the canSave variable for button enabling/disabling.

Using the canSave variable to control the disabled state of the button improves both code readability and user experience.

src/store/slices/node/actionsFetching.ts (2)

21-22: Good addition of new actions for ticket management.

The new actions for redeeming all tickets and resetting ticket statistics are well-named and follow the same pattern as existing actions.


41-42: Properly exported new action creators.

The action creators are correctly exported in the nodeActionsFetching object, maintaining consistency with the existing code structure.

src/components/Modal/node/SendMessageModal.tsx (2)

232-232: Good UX improvement with blur on modal open.

Blurring the active element when opening the modal ensures that keyboard focus is properly managed.


355-355: Good UX improvements with autoFocus and disabled state.

Adding autoFocus to the message input when a receiver is selected and disabling the send button based on the canSendMessage variable are excellent UX improvements.

Also applies to: 403-403

src/components/Modal/node/WithdrawModal.tsx (5)

6-12: Improved import formatting.

Breaking the imports into individual lines improves readability and will make future changes easier.


88-91: Good use of destructuring for API credentials.

Destructuring apiEndpoint and apiToken from loginData makes the code cleaner and easier to read.


104-110: Good addition of the canWithdraw variable.

This variable clearly defines the conditions for when withdrawals are allowed, improving code readability and maintainability.


149-149: Good TODO comment.

The TODO comment clearly indicates a future enhancement to update the balances after a withdrawal operation.


288-288: Good use of the canWithdraw variable for button enabling/disabling.

Using the canWithdraw variable to control the disabled state of the button improves both code readability and user experience.

src/store/slices/node/initialState.ts (1)

221-224: Renamed state property for better clarity

The rename from redeemTickets to redeemAllTickets provides better clarity about what this state property represents - the action of redeeming all tickets rather than individual ones.

src/pages/node/tickets.tsx (5)

17-19: Icons added for improved UI clarity

Good addition of appropriate icons for the ticket management actions.


25-26: State variables renamed for consistency

Properly renamed state variables to match the state property rename in the store.


44-55: Updated function to use renamed thunk

The function now correctly calls the renamed thunk with proper parameters and handles the result.


57-68: Added new function for resetting ticket statistics

Good implementation of the new reset functionality, following the same pattern as other similar functions.


83-94: Updated button for ticket redemption

Button properly using the renamed fetching state.

src/store/slices/node/actionsAsync.ts (6)

81-83: Added new SDK API function imports

Added redeemAllTickets and resetTicketStatistics to the list of imported API functions.


856-881: Properly implemented redeemAllTicketsThunk

The thunk is correctly implemented, following the established patterns. It dispatches the appropriate action to set the loading state and handles errors properly.


883-908: Added new resetTicketStatisticsThunk

Good implementation of the new reset functionality as a thunk. It follows the established patterns and correctly dispatches the loading state action.


1331-1346: Updated reducer cases for redeemAllTicketsThunk

The reducer cases have been properly updated to match the renamed state property.


1347-1354: Added reducer case for resetTicketStatisticsThunk

The implementation resets all the relevant ticket statistics values when the thunk is successfully fulfilled. This ensures a clean state for future statistics.


1712-1713: Updated exports to include new thunks

Properly added the new and renamed thunks to the exported actionsAsync object.

Comment on lines +753 to 754
dispatch(nodeActionsFetching.setRedeemAllTicketsFetching(true));
try {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect fetching action in redeemChannelTicketsThunk

The redeemChannelTicketsThunk is using setRedeemAllTicketsFetching instead of a separate action specific to channel tickets. This could lead to unexpected loading state behavior.

Consider creating and using a dedicated action for channel ticket redemption:

- dispatch(nodeActionsFetching.setRedeemAllTicketsFetching(true));
+ dispatch(nodeActionsFetching.setRedeemChannelTicketsFetching(true));

This would require adding the new action in the actionsFetching.ts file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dispatch(nodeActionsFetching.setRedeemAllTicketsFetching(true));
try {
dispatch(nodeActionsFetching.setRedeemChannelTicketsFetching(true));
try {

Comment on lines +1669 to 1673
state.redeemAllTickets.isFetching = false;
});
builder.addCase(redeemChannelTicketsThunk.rejected, (state) => {
state.redeemTickets.isFetching = false;
state.redeemAllTickets.isFetching = false;
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent state reference in redeemChannelTicketsThunk handlers

The fulfilled and rejected handlers for redeemChannelTicketsThunk are setting state.redeemAllTickets.isFetching to false. This is inconsistent with the action they're dispatching and could cause state management issues.

Consider updating to use a dedicated state property for channel tickets:

- state.redeemAllTickets.isFetching = false;
+ state.redeemChannelTickets.isFetching = false;

This would require adding the new state property in initialState.ts as well.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
state.redeemAllTickets.isFetching = false;
});
builder.addCase(redeemChannelTicketsThunk.rejected, (state) => {
state.redeemTickets.isFetching = false;
state.redeemAllTickets.isFetching = false;
});
state.redeemChannelTickets.isFetching = false;
});
builder.addCase(redeemChannelTicketsThunk.rejected, (state) => {
state.redeemChannelTickets.isFetching = false;
});

Copy link

@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 (1)
src/pages/node/aliases.tsx (1)

94-103: Improved alias update logic to handle existing mappings.

This enhancement checks if a peerId already has an alias and removes it before setting a new one, preventing orphaned or duplicate aliases. This is a good improvement for data consistency.

However, there's a missing trailing comma at the end of line 101 which should be fixed:

  apiToken: loginData.apiToken ? loginData.apiToken : '',
- })
+ }),
🧰 Tools
🪛 ESLint

[error] 101-102: Missing trailing comma.

(comma-dangle)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between abe4264 and b73e82e.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/pages/node/aliases.tsx (3 hunks)
  • src/store/slices/node/actionsAsync.ts (32 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🧬 Code Definitions (2)
src/pages/node/aliases.tsx (3)
src/store/index.ts (1) (1)
  • useAppSelector (26-26)
src/store/slices/node/actionsAsync.ts (1) (1)
  • actionsAsync (1685-1719)
src/store/slices/auth/actionsAsync.ts (1) (1)
  • actionsAsync (144-144)
src/store/slices/node/actionsAsync.ts (2)
src/store/slices/node/actionsFetching.ts (1) (1)
  • nodeActionsFetching (24-43)
src/store/index.ts (1) (1)
  • RootState (20-20)
🪛 ESLint
src/pages/node/aliases.tsx

[error] 101-102: Missing trailing comma.

(comma-dangle)

🔇 Additional comments (9)
src/store/slices/node/actionsAsync.ts (7)

81-82: API update with additional ticket management functions.

The API has been updated to include redeemAllTickets and resetTicketStatistics functions, which aligns with the new thunks added in this file.


753-753: Incorrect fetching action in redeemChannelTicketsThunk

The redeemChannelTicketsThunk is using setRedeemAllTicketsFetching instead of a dedicated action specific to channel tickets. This could lead to unexpected loading state behavior.

Consider creating and using a dedicated action for channel ticket redemption:

- dispatch(nodeActionsFetching.setRedeemAllTicketsFetching(true));
+ dispatch(nodeActionsFetching.setRedeemChannelTicketsFetching(true));

This would require adding the new action in the actionsFetching.ts file.


766-767: Inconsistent state reference in redeemChannelTicketsThunk condition

The condition check for redeemChannelTicketsThunk is using state.redeemAllTickets.isFetching which is inconsistent with the action name and purpose. This could cause unexpected behavior if both redemption processes run simultaneously.

Consider using a dedicated state property for channel tickets:

- const isFetching = getState().node.redeemAllTickets.isFetching;
+ const isFetching = getState().node.redeemChannelTickets.isFetching;

This would require adding the new state property in the initialState.


856-881: New thunk for redeeming all tickets.

This new thunk provides a dedicated function for redeeming all tickets, which separates this functionality from channel-specific ticket redemption. The implementation follows the established pattern for thunks in this file.


883-908: New thunk for resetting ticket statistics.

This adds functionality to reset ticket statistics, which complements the ticket management feature set. The implementation properly handles fetching state and error conditions.


1669-1673: Inconsistent state reference in redeemChannelTicketsThunk handlers

The fulfilled and rejected handlers for redeemChannelTicketsThunk are setting state.redeemAllTickets.isFetching to false. This is inconsistent with the action they're dispatching and could cause state management issues.

Consider updating to use a dedicated state property for channel tickets:

- state.redeemAllTickets.isFetching = false;
+ state.redeemChannelTickets.isFetching = false;

This would require adding the new state property in initialState.ts as well.


1712-1713: Exported newly added thunks.

The new thunks have been properly exported in the actionsAsync object, making them available for use throughout the application.

src/pages/node/aliases.tsx (2)

37-38: Added utility for mapping peerIds to aliases.

The addition of these selectors improves the component's ability to track which peer IDs already have aliases assigned, enabling more robust alias management.


357-360: Improved code readability with multi-line destructuring.

The destructuring assignment has been reformatted to a multi-line structure, which improves readability, especially as more properties might be added in the future.

@mjadach-iv mjadach-iv linked an issue Mar 24, 2025 that may be closed by this pull request
Copy link

@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

♻️ Duplicate comments (2)
src/store/slices/node/actionsAsync.ts (2)

697-697: ⚠️ Potential issue

Incorrect fetching action in redeemChannelTicketsThunk

The redeemChannelTicketsThunk is using setRedeemAllTicketsFetching instead of a dedicated action specific to channel tickets. This could lead to unexpected loading state behavior.

Consider creating and using a dedicated action for channel ticket redemption:

- dispatch(nodeActionsFetching.setRedeemAllTicketsFetching(true));
+ dispatch(nodeActionsFetching.setRedeemChannelTicketsFetching(true));

This would require adding the new action in the actionsFetching.ts file.


1623-1627: ⚠️ Potential issue

Inconsistent state reference in redeemChannelTicketsThunk handlers

The fulfilled and rejected handlers for redeemChannelTicketsThunk are setting state.redeemAllTickets.isFetching to false. This is inconsistent with the action they're dispatching and could cause state management issues.

Consider updating to use a dedicated state property for channel tickets:

- state.redeemAllTickets.isFetching = false;
+ state.redeemChannelTickets.isFetching = false;

This would require adding the new state property in initialState.ts as well.

🧹 Nitpick comments (5)
src/components/Modal/node/FundChannelModal.tsx (2)

113-118: Consider adding type safety to the event parameter.

The any type for the event parameter could be replaced with a more specific type.

-function handleEnter(event: any) {
+function handleEnter(event: KeyboardEvent) {
   if (openChannelModal && canFund && event.key === 'Enter') {
     console.log('FundChannelModal event');
     handleAction();
   }
 }

115-115: Remove or improve console.log statement.

This console log doesn't provide meaningful information for debugging and should be removed or enhanced with more context.

 function handleEnter(event: any) {
   if (openChannelModal && canFund && event.key === 'Enter') {
-    console.log('FundChannelModal event');
+    // Handled Enter key press in FundChannelModal
     handleAction();
   }
 }
src/components/Modal/node/SendMessageModal.tsx (3)

116-122: Complex validation logic could be simplified.

The canSendMessage logic is quite complex with multiple nested conditions. Consider breaking it down into smaller, more readable parts.

-const canSendMessage = !(
-  selectedReceiver === null ||
-  (sendMode !== 'directMessage' && sendMode !== 'automaticPath' && numberOfHops < 0 && path === '') ||
-  message.length === 0 ||
-  ((sendMode === 'directMessage' || (sendMode !== 'path' && numberOfHops < 1)) && selectedReceiver === hoprAddress) ||
-  (sendMode === 'path' && path.length === 0)
-);
+// Check if a receiver is selected
+const hasReceiver = selectedReceiver !== null;
+// Check if message is not empty
+const hasMessage = message.length > 0;
+// Check if trying to send to self in direct mode
+const isSendingToSelf = selectedReceiver === hoprAddress;
+const isDirectToSelf = isSendingToSelf && (sendMode === 'directMessage' || (sendMode !== 'path' && numberOfHops < 1));
+// Check if path mode has a valid path
+const hasValidPath = sendMode !== 'path' || path.length > 0;
+// Check if routing configuration is valid
+const hasValidRouting = sendMode === 'directMessage' || sendMode === 'automaticPath' || 
+                       !(numberOfHops < 0 && path === '');
+
+const canSendMessage = hasReceiver && hasMessage && !isDirectToSelf && hasValidPath && hasValidRouting;

282-287: Consider handling modifier keys in the Enter key event.

The current implementation triggers on any Enter key press. Consider checking for modifier keys to avoid triggering when user is pressing Ctrl+Enter or Shift+Enter to create new lines in the message.

 function handleEnter(event: KeyboardEvent) {
-  if (canSendMessage && (event as KeyboardEvent)?.key === 'Enter') {
+  if (canSendMessage && event.key === 'Enter' && !event.shiftKey && !event.ctrlKey && !event.altKey) {
     console.log('SendMessageModal event');
     handleSendMessage();
   }
 }

284-284: Remove or improve console.log statement.

This console log statement doesn't provide meaningful information for debugging and should be removed or enhanced.

 function handleEnter(event: KeyboardEvent) {
   if (canSendMessage && (event as KeyboardEvent)?.key === 'Enter') {
-    console.log('SendMessageModal event');
+    // Handled Enter key press in SendMessageModal
     handleSendMessage();
   }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd57a61 and da40c6f.

📒 Files selected for processing (15)
  • src/components/ConnectNode/modal.tsx (4 hunks)
  • src/components/Modal/node/AddAliasModal.tsx (5 hunks)
  • src/components/Modal/node/FundChannelModal.tsx (5 hunks)
  • src/components/Modal/node/OpenChannelModal.tsx (5 hunks)
  • src/components/Modal/node/OpenMultipleChannelsModal.tsx (4 hunks)
  • src/components/Modal/node/PingModal.tsx (5 hunks)
  • src/components/Modal/node/SendMessageModal.tsx (6 hunks)
  • src/components/Modal/node/WithdrawModal.tsx (6 hunks)
  • src/pages/node/aliases.tsx (2 hunks)
  • src/pages/node/configuration.tsx (5 hunks)
  • src/pages/node/info/index.tsx (5 hunks)
  • src/pages/node/tickets.tsx (5 hunks)
  • src/router.tsx (1 hunks)
  • src/store/slices/node/actionsAsync.ts (15 hunks)
  • src/store/slices/node/initialState.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/pages/node/configuration.tsx
  • src/components/Modal/node/PingModal.tsx
  • src/components/ConnectNode/modal.tsx
  • src/components/Modal/node/OpenMultipleChannelsModal.tsx
  • src/pages/node/aliases.tsx
  • src/components/Modal/node/WithdrawModal.tsx
  • src/components/Modal/node/OpenChannelModal.tsx
  • src/components/Modal/node/AddAliasModal.tsx
  • src/store/slices/node/initialState.ts
🧰 Additional context used
🧬 Code Definitions (5)
src/router.tsx (1)
src/store/slices/node/index.ts (1)
  • nodeActionsAsync (64-64)
src/components/Modal/node/FundChannelModal.tsx (2)
src/future-hopr-lib-components/Modal/styled.tsx (1)
  • SDialogContent (22-30)
src/future-hopr-lib-components/Navbar/navButton.jsx (1)
  • Button (44-106)
src/pages/node/info/index.tsx (1)
src/store/index.ts (1)
  • useAppSelector (26-26)
src/store/slices/node/actionsAsync.ts (2)
src/store/slices/node/actionsFetching.ts (1)
  • nodeActionsFetching (24-43)
src/store/index.ts (1)
  • RootState (20-20)
src/pages/node/tickets.tsx (3)
src/store/index.ts (2)
  • useAppDispatch (25-25)
  • useAppSelector (26-26)
src/store/slices/node/actionsAsync.ts (1)
  • actionsAsync (1648-1683)
src/future-hopr-lib-components/Button/IconButton.tsx (1)
  • IconButton (55-83)
🔇 Additional comments (25)
src/components/Modal/node/FundChannelModal.tsx (5)

31-31: Improved validation logic with canFund variable.

Centralizing the validation logic in a single variable improves code readability and maintainability.


33-38: Good addition of keyboard event handling.

The useEffect hook appropriately sets up and cleans up the keyboard event listener, allowing users to submit the form with the Enter key. The dependency array correctly includes all relevant state variables.


41-41: Improved focus management when opening modal.

Blurring the active element before opening the modal prevents focus-related issues and improves user experience.


155-155: Smart focus management with autoFocus properties.

The conditional autoFocus properties improve user experience by focusing on the appropriate input field based on whether the channelId is already populated.

Also applies to: 165-165


171-171: Simplified button disabled logic using the canFund variable.

Using the centralized canFund variable for the button's disabled state improves code readability and consistency.

src/components/Modal/node/SendMessageModal.tsx (4)

132-137: Good implementation of keyboard event handling.

The useEffect hook properly sets up and cleans up the keyboard event listener. This enhances user experience by allowing message sending with the Enter key.


232-232: Improved focus management when opening the modal.

Blurring the active element before opening the modal prevents focus-related issues and improves user experience.


355-355: Good usage of autoFocus for better user experience.

The conditional autoFocus property on the message field improves user experience by focusing on the field when a receiver is selected.


403-403: Simplified button disabled logic using canSendMessage.

Using the centralized canSendMessage variable for the button's disabled state improves code readability and consistency.

src/router.tsx (1)

326-331: New dispatch added to fetch minimum network probability after login

This addition enhances the node connection process by retrieving the minimum network probability after a successful login. The implementation is clean and follows the established pattern of other API calls in this useEffect hook.

src/pages/node/info/index.tsx (4)

60-62: Block number variables refactored for clarity

The implementation now uses more descriptive variable names from the Redux store, improving readability and maintainability.


64-64: Added minimum network probability state

Added state to expose the minimum network probability data from Redux, which aligns with the new functionality introduced throughout this PR.


330-381: Enhanced node information display with improved block data

The UI has been updated to provide more detailed information about the node's synchronization status, including provider address, current block, last indexed log block, and log checksum. These changes offer users greater visibility into node operations.


463-491: Added ticket properties section with minimum network probability

New table section displays ticket information including minimum ticket winning probability, providing valuable context about the network configuration. The tooltip includes dynamic network name from the info object.

src/store/slices/node/actionsAsync.ts (5)

800-822: Renamed redeemTicketsThunk to redeemAllTicketsThunk

The function has been renamed to better reflect its purpose of redeeming all tickets at once. The implementation has been updated consistently with the new naming.


824-846: Added new resetTicketStatisticsThunk

New thunk to reset ticket statistics, enhancing the ticket management functionality. The implementation follows the established pattern for async thunks.


959-985: Added new getMinimumNetworkProbabilityThunk

New thunk to retrieve the minimum network probability from the API. This enhances the available information about network configuration.


1637-1645: Added reducer cases for minimum network probability

Added proper handlers for the new getMinimumNetworkProbabilityThunk to update Redux state with the probability data. The implementation follows the established pattern for other similar thunks.


1675-1678: Updated actionsAsync exports with new and renamed thunks

The exported actionsAsync object has been updated to include the new thunks and the renamed thunk, ensuring they're available for use throughout the application.

src/pages/node/tickets.tsx (6)

17-20: Added imports for new UI functionality

Added icon imports to support the new reset ticket statistics button.


25-30: Updated state variables for consistency with backend changes

Renamed variables to match the backend naming changes and added new state variables to access ticket price, network info, and minimum probability data.


47-58: Updated redeemAllTickets handler to use renamed thunk

The function has been updated to call the renamed thunk with the required parameters. The implementation is clean and includes proper error handling.


60-71: Added new handler for resetting ticket statistics

New function to reset ticket statistics using the new thunk, following the same pattern as other API calls in this component.


86-109: Enhanced UI with new reset statistics button

Added a new button to reset ticket statistics and updated the reloading props to reflect the correct loading state. This provides users with more control over their ticket data.


119-147: Added ticket properties display section

New table section displays ticket properties including price and minimum winning probability, providing users with important network configuration information. This complements the changes in the info page.

Copy link

@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: 12

♻️ Duplicate comments (2)
src/store/slices/node/actionsAsync.ts (2)

700-700: ⚠️ Potential issue

Incorrect fetching action in redeemChannelTicketsThunk

The redeemChannelTicketsThunk is using setRedeemAllTicketsFetching instead of a dedicated action for channel tickets. This could lead to unexpected loading state behavior.

Consider creating and using a dedicated action for channel ticket redemption:

- dispatch(nodeActionsFetching.setRedeemAllTicketsFetching(true));
+ dispatch(nodeActionsFetching.setRedeemChannelTicketsFetching(true));

This would require adding the new action in the actionsFetching.ts file.


1659-1663: ⚠️ Potential issue

Inconsistent state reference in redeemChannelTicketsThunk handlers

The fulfilled and rejected handlers for redeemChannelTicketsThunk are setting state.redeemAllTickets.isFetching to false. This is inconsistent with the action they're dispatching and could cause state management issues.

Consider updating to use a dedicated state property for channel tickets:

- state.redeemAllTickets.isFetching = false;
+ state.redeemChannelTickets.isFetching = false;

This would require adding the new state property in initialState.ts as well.

🧹 Nitpick comments (5)
src/components/ConnectNode/modal.tsx (1)

389-394: Good implementation of the Enter key functionality.

The handleEnter function successfully complements the UI button by providing keyboard functionality, improving accessibility and user experience.

Consider removing or conditionally showing the console.log statement in production environments:

  function handleEnter(event: KeyboardEvent) {
    if (props.open && canConnectToNode && event.key === 'Enter') {
-      console.log('ConnectNode event');
      useNode({});
    }
  }
src/components/Modal/node/OpenSessionModal.tsx (3)

117-123: Complex condition for canSendMessage could be simplified

The condition for canSendMessage is quite complex and might be difficult to understand and maintain.

Consider breaking it down into separate, named conditions for better readability:

- const canSendMessage = !(
-   selectedReceiver === null ||
-   (sendMode !== 'directMessage' && sendMode !== 'automaticPath' && numberOfHops < 0 && path === '') ||
-   message.length === 0 ||
-   ((sendMode === 'directMessage' || (sendMode !== 'path' && numberOfHops < 1)) && selectedReceiver === hoprAddress) ||
-   (sendMode === 'path' && path.length === 0)
- );
+ const hasReceiver = selectedReceiver !== null;
+ const hasValidPath = !(sendMode === 'path' && path.length === 0);
+ const hasMessage = message.length > 0;
+ const isNotSendingToSelf = !((sendMode === 'directMessage' || (sendMode !== 'path' && numberOfHops < 1)) && selectedReceiver === hoprAddress);
+ const hasValidHopsForMode = !(sendMode !== 'directMessage' && sendMode !== 'automaticPath' && numberOfHops < 0 && path === '');
+ 
+ const canSendMessage = hasReceiver && hasValidPath && hasMessage && isNotSendingToSelf && hasValidHopsForMode;

161-161: Remove commented out code

There's a commented line that should be removed as it's no longer needed and may cause confusion.

- //const validatedReceiver = validatePeerId(selectedReceiver);

183-183: Use strict equality comparison

Using strict equality (===) is preferred over loose equality (==) in TypeScript/JavaScript.

- if (sendMode == 'path') {
+ if (sendMode === 'path') {
src/pages/node/sessions.tsx (1)

347-362: Simplify unnecessary Fragment

The Fragment wrapping the IconButton is unnecessary since there's only one child element.

actions={
-  <>
    <IconButton
      iconComponent={<GetAppIcon />}
      tooltipText={
        <span>
          EXPORT
          <br />
          {tabLabel} channels as a CSV
        </span>
      }
      disabled={!channelsData || Object.keys(channelsData).length === 0}
      onClick={handleExport}
    />
-  </>
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 348-361: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between da40c6f and ebf42fd.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (10)
  • package.json (1 hunks)
  • src/components/ConnectNode/modal.tsx (4 hunks)
  • src/components/Modal/node/OpenSessionModal.tsx (1 hunks)
  • src/pages/node/channelsOutgoing.tsx (3 hunks)
  • src/pages/node/sessions.tsx (1 hunks)
  • src/pages/node/tickets.tsx (5 hunks)
  • src/router.tsx (4 hunks)
  • src/store/slices/node/actionsAsync.ts (15 hunks)
  • src/store/slices/node/actionsFetching.ts (3 hunks)
  • src/store/slices/node/initialState.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/store/slices/node/initialState.ts
🧰 Additional context used
🧬 Code Definitions (6)
src/pages/node/channelsOutgoing.tsx (1)
src/components/Modal/node/OpenSessionModal.tsx (1)
  • OpenSessionModal (98-433)
src/router.tsx (1)
src/store/slices/node/index.ts (1)
  • nodeActionsAsync (64-64)
src/pages/node/sessions.tsx (1)
src/store/slices/node/actionsAsync.ts (1)
  • actionsAsync (1693-1729)
src/store/slices/node/actionsAsync.ts (2)
src/store/slices/node/actionsFetching.ts (1)
  • nodeActionsFetching (26-47)
src/store/index.ts (1)
  • RootState (20-20)
src/pages/node/tickets.tsx (3)
src/store/index.ts (2)
  • useAppDispatch (25-25)
  • useAppSelector (26-26)
src/store/slices/node/actionsAsync.ts (1)
  • actionsAsync (1693-1729)
src/future-hopr-lib-components/Button/IconButton.tsx (1)
  • IconButton (55-83)
src/components/ConnectNode/modal.tsx (1)
src/store/slices/node/index.ts (1)
  • nodeActionsAsync (64-64)
🪛 ESLint
src/router.tsx

[error] 347-348: Missing trailing comma.

(comma-dangle)


[error] 354-355: Missing trailing comma.

(comma-dangle)

src/pages/node/sessions.tsx

[error] 58-59: Missing trailing comma.

(comma-dangle)


[error] 65-66: Missing trailing comma.

(comma-dangle)

src/components/ConnectNode/modal.tsx

[error] 332-333: Missing trailing comma.

(comma-dangle)


[error] 339-340: Missing trailing comma.

(comma-dangle)

🪛 Biome (1.9.4)
src/pages/node/sessions.tsx

[error] 348-361: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

🔇 Additional comments (27)
src/components/ConnectNode/modal.tsx (3)

153-153: Improving code clarity with a state variable.

Creating the canConnectToNode variable improves readability by centralizing the button enabling logic in one place.


155-160: Good implementation of keyboard event handling.

Adding the keydown event listener with proper cleanup enhances the user experience by allowing Enter key functionality. The dependencies array is comprehensive, ensuring the listener updates when relevant state changes.


477-477: Good use of state variable for button disabled property.

Replacing the direct check with the canConnectToNode variable improves consistency and makes the code more maintainable.

src/pages/node/channelsOutgoing.tsx (2)

25-25: Good addition of OpenSessionModal import

The import is correctly placed with other modal imports, providing a logical organization of the code.


188-189: Appropriately increased width for Actions column

Increasing the width from '188px' to '225px' accommodates the new OpenSessionModal component that's being added to the actions section.

src/router.tsx (3)

29-29: Good import of SessionsPage component

The import of the SessionsPage component is properly placed with the other page imports.


58-58: Appropriate icon import for Sessions feature

The SettingsPhoneIcon is a suitable choice for representing sessions functionality.


162-169: Well-structured addition of Sessions navigation item

The Sessions menu item is correctly added to the NETWORKING section with appropriate properties.

Note: The numberSessions key is used, but there doesn't appear to be a corresponding entry in the numberForDrawer object. Consider adding this to display session counts in the drawer.

src/components/Modal/node/OpenSessionModal.tsx (2)

1-58: Well-structured imports and styled components

The imports are organized by category (React, HOPR Components, MUI) and the styled components are well defined with appropriate styles.


69-97: Well-implemented utility functions and types

The component props interface and the sortAddresses utility function are well-designed, providing clear types and functionality.

src/store/slices/node/actionsFetching.ts (3)

21-24: Proper action additions for ticket-related operations

These new action creators align well with the expanded functionality for ticket management in the application. They follow the existing naming conventions and action type patterns.


43-46: Export of new action creators follows established patterns

The new action creators are properly exported in the nodeActionsFetching object, maintaining the existing structure and organization of the code.


93-104: Appropriate reducer cases added for new actions

The new reducer cases correctly update the corresponding state properties when the actions are dispatched. The implementation follows the established pattern in the codebase.

src/pages/node/tickets.tsx (6)

17-19: Appropriate icon imports for new functionality

The added icon imports support the new UI elements for ticket management operations.


25-30: Redux state selector updates for ticket functionality

State selectors have been updated from redeemTicketsFetching to redeemAllTicketsFetching to align with the renamed Redux actions. New selectors for info, ticketPrice, and minimumNetworkProbability have been added to support the additional ticket properties display.


47-58: Refactored handleRedeemAllTickets implementation

The function has been updated to use the new redeemAllTicketsThunk and properly unwraps the promise to handle successful redemption.


60-71: New handleResetTicketsStatistics function

This new function provides the ability to reset ticket statistics, using the newly added resetTicketStatisticsThunk.


95-96: Updated reloading prop for ticket redemption button

The IconButton now correctly references redeemAllTicketsFetching to show the loading state during ticket redemption.


179-207: Well-structured table for ticket properties

The new table for displaying ticket properties is well-structured and includes helpful tooltips to explain each property to users. It properly displays formatted values and handles null/undefined cases.

src/store/slices/node/actionsAsync.ts (8)

43-46: New type imports for extended functionality

The type imports have been correctly added to support the new session and probability functionality.


76-87: Integrated new API functions

The API functions for minimum ticket probability, sessions, and resetting ticket statistics have been properly added to the destructured import list.


803-809: Renamed redeemAllTicketsThunk implementation

The thunk has been properly renamed from redeemTickets to redeemAllTickets to better represent its functionality of redeeming all tickets.


827-853: New resetTicketStatisticsThunk implementation

The new thunk for resetting ticket statistics is well-implemented, following the established patterns for async thunks in the codebase.


966-992: New getMinimumNetworkProbabilityThunk implementation

The implementation of the thunk for fetching minimum network probability follows the codebase's established patterns for async operations.


994-1020: New getSessionsThunk implementation

The implementation of the thunk for fetching sessions follows the codebase's established patterns for async operations.


1673-1690: Properly implemented handlers for new thunks

The fulfilled and rejected handlers for the new thunks (getMinimumNetworkProbabilityThunk and getSessionsThunk) are correctly implemented, following the established patterns in the codebase.


1720-1724: Updated actionsAsync export object

The actionsAsync object has been properly updated to include the new thunks, making them available for use throughout the application.

Comment on lines +322 to +341
dispatch(
nodeActionsAsync.getMinimumNetworkProbabilityThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
}),
);
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'udp'
}),
)
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp'
}),
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix missing trailing commas in dispatch calls.

ESLint has flagged missing trailing commas in the session thunk dispatches.

          nodeActionsAsync.getSessionsThunk({
            apiEndpoint,
            apiToken: apiToken ? apiToken : '',
-            protocol: 'udp'
+            protocol: 'udp',
          }),

          nodeActionsAsync.getSessionsThunk({
            apiEndpoint,
            apiToken: apiToken ? apiToken : '',
-            protocol: 'tcp'
+            protocol: 'tcp',
          }),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dispatch(
nodeActionsAsync.getMinimumNetworkProbabilityThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
}),
);
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'udp'
}),
)
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp'
}),
);
dispatch(
nodeActionsAsync.getMinimumNetworkProbabilityThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
}),
);
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'udp',
}),
)
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp',
}),
);
🧰 Tools
🪛 ESLint

[error] 332-333: Missing trailing comma.

(comma-dangle)


[error] 339-340: Missing trailing comma.

(comma-dangle)

Comment on lines +343 to +356
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'udp'
}),
)
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp'
}),
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing trailing commas in thunk parameters

The protocol parameter objects are missing trailing commas, which is inconsistent with the code style in the rest of the file.

Apply these fixes:

dispatch(
  nodeActionsAsync.getSessionsThunk({
    apiEndpoint,
    apiToken: apiToken ? apiToken : '',
-   protocol: 'udp'
+   protocol: 'udp',
  }),
)
dispatch(
  nodeActionsAsync.getSessionsThunk({
    apiEndpoint,
    apiToken: apiToken ? apiToken : '',
-   protocol: 'tcp'
+   protocol: 'tcp',
  }),
);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'udp'
}),
)
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp'
}),
);
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'udp',
}),
)
dispatch(
nodeActionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp',
}),
);
🧰 Tools
🪛 ESLint

[error] 347-348: Missing trailing comma.

(comma-dangle)


[error] 354-355: Missing trailing comma.

(comma-dangle)

import GetAppIcon from '@mui/icons-material/GetApp';
import { truncateEthereumAddress } from '../../utils/blockchain';

function ChannelsPage() {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Component name doesn't match file name

The file is named sessions.tsx but exports a component named ChannelsPage. This could lead to confusion when importing and using the component.

Rename the component to match the file or update the file name:

- function ChannelsPage() {
+ function SessionsPage() {

And update the export:

- export default ChannelsPage;
+ export default SessionsPage;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function ChannelsPage() {
function SessionsPage() {
// ... component implementation
}
export default SessionsPage;

Comment on lines +58 to +66
protocol: 'udp'
}),
)
dispatch(
actionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp'
}),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing trailing commas in thunk parameters

The protocol parameter objects are missing trailing commas, which is inconsistent with the code style in the rest of the file.

Apply these fixes:

dispatch(
  actionsAsync.getSessionsThunk({
    apiEndpoint,
    apiToken: apiToken ? apiToken : '',
-   protocol: 'udp'
+   protocol: 'udp',
  }),
)
dispatch(
  actionsAsync.getSessionsThunk({
    apiEndpoint,
    apiToken: apiToken ? apiToken : '',
-   protocol: 'tcp'
+   protocol: 'tcp',
  }),
);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
protocol: 'udp'
}),
)
dispatch(
actionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp'
}),
protocol: 'udp',
}),
)
dispatch(
actionsAsync.getSessionsThunk({
apiEndpoint,
apiToken: apiToken ? apiToken : '',
protocol: 'tcp',
}),
);
🧰 Tools
🪛 ESLint

[error] 58-59: Missing trailing comma.

(comma-dangle)


[error] 65-66: Missing trailing comma.

(comma-dangle)

Comment on lines +98 to +109
<IconButton
iconComponent={<RotateLeftIcon />}
tooltipText={
<span>
RESET
<br />
ticket statistics
</span>
}
reloading={redeemAllTicketsFetching}
onClick={handleResetTicketsStatistics}
/>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect loading state reference for reset statistics button

The reset statistics button is using redeemAllTicketsFetching for its loading state, but it should use a dedicated loading state related to resetting statistics.

Apply this fix:

-              reloading={redeemAllTicketsFetching}
+              reloading={useAppSelector((store) => store.node.resetTicketStatistics.isFetching)}

Or add a dedicated variable at the top of the component:

+  const resetTicketStatisticsFetching = useAppSelector((store) => store.node.resetTicketStatistics.isFetching);

   // Then use it in the component
-              reloading={redeemAllTicketsFetching}
+              reloading={resetTicketStatisticsFetching}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<IconButton
iconComponent={<RotateLeftIcon />}
tooltipText={
<span>
RESET
<br />
ticket statistics
</span>
}
reloading={redeemAllTicketsFetching}
onClick={handleResetTicketsStatistics}
/>
// ... (other imports and code at the top of your component file)
import { useAppSelector } from 'path-to-your-store-hook';
const TicketsPage = () => {
// Declare the dedicated loading state variable for resetting statistics
const resetTicketStatisticsFetching = useAppSelector(
(store) => store.node.resetTicketStatistics.isFetching
);
// Other component logic and state declarations
// ...
return (
<>
{/* ... other component JSX ... */}
<IconButton
iconComponent={<RotateLeftIcon />}
tooltipText={
<span>
RESET
<br />
ticket statistics
</span>
}
reloading={resetTicketStatisticsFetching}
onClick={handleResetTicketsStatistics}
/>
{/* ... other component JSX ... */}
</>
);
};
export default TicketsPage;

Comment on lines +1337 to +1344
// resetTicketStatisticsThunk
builder.addCase(resetTicketStatisticsThunk.fulfilled, (state) => {
if (!state.statistics.data) return;
state.statistics.data.neglectedValue = '0';
state.statistics.data.redeemedValue = '0';
state.statistics.data.rejectedValue = '0';
state.statistics.data.winningCount = 0;
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing apiEndpoint check in resetTicketStatisticsThunk handler

The fulfilled handler for resetTicketStatisticsThunk is missing the check for whether the API endpoint matches the current one, which is present in other thunk handlers.

Apply this fix:

  builder.addCase(resetTicketStatisticsThunk.fulfilled, (state) => {
+   if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
    if (!state.statistics.data) return;
    state.statistics.data.neglectedValue = '0';
    state.statistics.data.redeemedValue = '0';
    state.statistics.data.rejectedValue = '0';
    state.statistics.data.winningCount = 0;
  });

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +713 to 714
const isFetching = getState().node.redeemAllTickets.isFetching;
if (isFetching) {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent condition check in redeemChannelTicketsThunk

The condition check is using redeemAllTickets.isFetching which is shared with the all tickets redemption functionality, potentially causing race conditions.

Apply this fix:

-      const isFetching = getState().node.redeemAllTickets.isFetching;
+      const isFetching = getState().node.redeemChannelTickets.isFetching;

This would require adding a new state property in the initialState.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isFetching = getState().node.redeemAllTickets.isFetching;
if (isFetching) {
const isFetching = getState().node.redeemChannelTickets.isFetching;
if (isFetching) {

Copy link

@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 (4)
src/components/Modal/node/OpenSessionModal.tsx (4)

23-24: Add a trailing comma after the last import for compliance with ESLint rules.

ESLint flagged a missing trailing comma (comma-dangle). This helps maintain cleaner diffs and consistent code style.

-import {
-  DialogTitle,
-  DialogActions,
-  CircularProgress,
-  TextField,
-  SelectChangeEvent,
-  Select,
-  MenuItem,
-  Autocomplete,
-  Tooltip,
-  IconButton as IconButtonMui
-} from '@mui/material';
+import {
+  DialogTitle,
+  DialogActions,
+  CircularProgress,
+  TextField,
+  SelectChangeEvent,
+  Select,
+  MenuItem,
+  Autocomplete,
+  Tooltip,
+  IconButton as IconButtonMui,
+} from '@mui/material';
🧰 Tools
🪛 ESLint

[error] 23-24: Missing trailing comma.

(comma-dangle)


154-159: Simplify or extract the complex send condition.

The boolean logic to determine canSendMessage is quite large and may be difficult to maintain. Consider extracting it into a more descriptive function or simplifying the conditions within the component.


284-304: Avoid relying on the older "Spacebar" event key.

Modern browsers use " " or "Space" for the space key. Using "Spacebar" might not work consistently.

-if (e.key === ' ' || e.key === 'Spacebar') {
+if (e.key === ' ') {
  e.preventDefault();
  ...
}

471-472: Add trailing comma in JSX return elements.

ESLint flagged a missing trailing comma here. Including the trailing comma in multi-line JSX can help maintain consistency and cleaner diffs.

-          </IconButtonMui>
-        </PathNode>
+          </IconButtonMui>,
+        </PathNode>,
🧰 Tools
🪛 ESLint

[error] 471-472: Missing trailing comma.

(comma-dangle)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ebf42fd and b305f41.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • src/components/Modal/node/OpenSessionModal.tsx (1 hunks)
🧰 Additional context used
🪛 ESLint
src/components/Modal/node/OpenSessionModal.tsx

[error] 23-24: Missing trailing comma.

(comma-dangle)


[error] 471-472: Missing trailing comma.

(comma-dangle)

🔇 Additional comments (2)
src/components/Modal/node/OpenSessionModal.tsx (2)

169-174: Repeat of previous advice: add event listener conditionally and fix dependencies.

The component is adding a global keydown listener for the Enter key, potentially conflicting with other parts of the app. Also, the dependency array excludes canSendMessage, openModal, and handleSendMessage, which may cause stale closures.

Revisit the previous approach:

useEffect(() => {
+ if (openModal) {
    window.addEventListener('keydown', handleEnter as EventListener);
    return () => {
      window.removeEventListener('keydown', handleEnter as EventListener);
    };
+ }
- }, [loginData, message, selectedReceiver, sendMode]);
+ }, [loginData, message, selectedReceiver, sendMode, canSendMessage, openModal, handleSendMessage]);

388-400: Confirm usage of 'listenHost' and 'sessionTarget'.

These state variables are never referenced in handleSendMessage nor passed elsewhere. Verify whether they're needed for session initialization or can be removed.

Do you want to keep them for future expansions, or should they be integrated into the payload? Please confirm.

Copy link

@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)
src/components/Modal/node/OpenSessionModal.tsx (2)

167-168: Rename or simplify the double negative variable to improve clarity.

intermediatePathEmptyLink is set by negating conditions twice, which is confusing. Consider a clearer name and logic, such as hasNullInIntermediatePath or isPathValid, for better readability.


24-25: Add trailing commas to meet ESLint's comma-dangle requirement.

The static analysis tool flagged missing trailing commas. Insert them to conform to your linting rules.

   IconButton as IconButtonMui
-} from '@mui/material';
+}, from '@mui/material';

  ...
  
-    (elem, index)=>{
+    (elem, index)=>{

  ...

-  </PathNode>
+  </PathNode>,

Also applies to: 165-166, 477-478

🧰 Tools
🪛 ESLint

[error] 24-25: Missing trailing comma.

(comma-dangle)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b305f41 and 770a564.

📒 Files selected for processing (1)
  • src/components/Modal/node/OpenSessionModal.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/components/Modal/node/OpenSessionModal.tsx (2)
src/store/slices/node/initialState.ts (1)
  • AddressesType (53-53)
src/store/slices/node/actionsAsync.ts (1)
  • actionsAsync (1693-1729)
🪛 ESLint
src/components/Modal/node/OpenSessionModal.tsx

[error] 24-25: Missing trailing comma.

(comma-dangle)


[error] 165-166: Missing trailing comma.

(comma-dangle)


[error] 477-478: Missing trailing comma.

(comma-dangle)

🔇 Additional comments (3)
src/components/Modal/node/OpenSessionModal.tsx (3)

197-202: Conditionally attach the keydown listener only when the modal is open.

Attaching global listeners could interfere with other components. This was recommended in a previous review.


221-279: Verify usage of 'listenHost' and 'sessionTarget' in session creation.

Although you check both fields to enable the "Open session" button, these values are never forwarded to the sendMessageThunk payload. Verify whether you intended to include them in the request body or needed them for a different step.


324-330: Avoid capturing Enter key when the modal is closed.

handleEnter triggers sending even when openModal is false, potentially frustrating other parts of the UI. This was also mentioned in a prior review.

Copy link

@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 (8)
src/pages/node/aliases.tsx (1)

94-103: Logic improvement for alias uniqueness, but remove debugging code.

The logic to remove existing aliases before creating new ones prevents duplicate mappings for the same peerId, which is a good enhancement. However, there's an unnecessary console.log statement that should be removed.

-        if (peerIdsWithAliases.includes(data.peerId)) {
-          console.log(peerIdToAliasLink, data.peerId, peerIdToAliasLink[data.peerId]);
+        if (peerIdsWithAliases.includes(data.peerId)) {
           await dispatch(
             actionsAsync.removeAliasThunk({
               alias: peerIdToAliasLink[data.peerId],
src/components/Modal/node/OpenSessionModal.tsx (7)

173-175: Remove debugging console log.

This console.log statement appears to be leftover debugging code and should be removed.

-  useEffect(()=>{
-    console.log(intermediatePathError)
-  }, [intermediatePathError]);

198-198: Remove commented-out code.

There's a commented-out line that should be removed.

-    //const validatedReceiver = validatePeerId(destination);

214-214: Use strict equality check.

Use strict equality (===) instead of loose equality (==) for type safety.

-    if (sendMode == 'path') {
+    if (sendMode === 'path') {

232-232: Remove console log statements.

These console.log statements appear to be leftover debugging code and should be removed.

-        console.log('@message: ', res?.challenge);
         handleCloseModal();
       })
       .catch((e) => {
-        console.log('@message err:', e);
         let errMsg = `Sending message failed`;

And in the handleEnter function:

   if (canOpenSession && (event as KeyboardEvent)?.key === 'Enter') {
-     console.log('OpenSessionModal event');
      handleOpenSession();
    }

Also applies to: 236-236, 286-286


344-350: Remove commented-out code.

There's a chunk of commented-out code that should be removed.

-          // renderOption={(option)=>{
-          //   return (
-          //     <span>
-          //       {JSON.stringify(option)}
-          //     </span>
-          //   )
-          // }}

405-407: Remove commented-out code.

There's a commented-out line that should be removed.

                    <Autocomplete
-                    //  key={`path-node-${pathIndex}-Autocomplete`}
                      value={pathNode}

24-25: Fix style issues flagged by ESLint.

There are several style issues flagged by ESLint that should be fixed:

  1. Add missing trailing commas:
  IconButton as IconButtonMui
- } from '@mui/material';
+ } from '@mui/material';

  const SFormGroup = styled(FormGroup)`
    flex-direction: row;
- `
+ `;

  const intermediatePathError = fullPath.findIndex(
    (elem, index)=>{
      return elem === fullPath[index+1]
-   }
+   },
  ) !== -1;

                  </PathNode>
-
+                ,
                )

Also applies to: 88-88, 156-157, 437-438

🧰 Tools
🪛 ESLint

[error] 24-25: Missing trailing comma.

(comma-dangle)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 770a564 and 2a17499.

📒 Files selected for processing (5)
  • src/components/Modal/node/OpenSessionModal.tsx (1 hunks)
  • src/pages/node/aliases.tsx (3 hunks)
  • src/pages/node/channelsIncoming.tsx (4 hunks)
  • src/pages/node/channelsOutgoing.tsx (3 hunks)
  • src/pages/node/peers.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/node/channelsOutgoing.tsx
🧰 Additional context used
🧬 Code Definitions (4)
src/pages/node/peers.tsx (1)
src/components/Modal/node/OpenSessionModal.tsx (1)
  • OpenSessionModal (125-491)
src/pages/node/aliases.tsx (2)
src/store/slices/node/actionsAsync.ts (1)
  • actionsAsync (1693-1729)
src/components/Modal/node/OpenSessionModal.tsx (1)
  • OpenSessionModal (125-491)
src/pages/node/channelsIncoming.tsx (1)
src/components/Modal/node/OpenSessionModal.tsx (1)
  • OpenSessionModal (125-491)
src/components/Modal/node/OpenSessionModal.tsx (2)
src/store/slices/node/initialState.ts (1)
  • AddressesType (53-53)
src/store/slices/node/actionsAsync.ts (1)
  • actionsAsync (1693-1729)
🪛 ESLint
src/components/Modal/node/OpenSessionModal.tsx

[error] 24-25: Missing trailing comma.

(comma-dangle)


[error] 156-157: Missing trailing comma.

(comma-dangle)


[error] 437-438: Missing trailing comma.

(comma-dangle)

🔇 Additional comments (7)
src/pages/node/peers.tsx (2)

20-20: Good addition of the OpenSessionModal component.

The OpenSessionModal import enhances the peer interaction functionality by allowing users to initiate sessions directly from the peers list.


189-191: Implementation looks correct.

The OpenSessionModal component is correctly implemented with the peerId prop, providing a consistent UX alongside other peer actions like ping, message sending, and channel management.

src/pages/node/channelsIncoming.tsx (3)

26-26: Good addition of the OpenSessionModal component.

The OpenSessionModal import enhances the channel interaction functionality by allowing users to initiate sessions directly from the channels list.


142-142: Appropriate UI adjustments for new action button.

The column width adjustments are necessary to accommodate the new OpenSessionModal button in the actions column, ensuring proper layout and spacing.

Also applies to: 157-158


315-317: Implementation looks correct.

The OpenSessionModal component is correctly implemented with the peerId prop, maintaining consistent UX with other components that use this modal.

src/pages/node/aliases.tsx (2)

30-30: Good state management improvements.

The addition of the peerId selector and alias links enhances the component's functionality by providing access to necessary state for alias management and session operations.

Also applies to: 38-39


185-187: Implementation looks correct.

The OpenSessionModal component is correctly implemented with the peerId prop, providing consistent UX alongside other peer actions.

Comment on lines +177 to +182
useEffect(() => {
window.addEventListener('keydown', handleEnter as EventListener);
return () => {
window.removeEventListener('keydown', handleEnter as EventListener);
};
}, [loginData, destination, sendMode]);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve keydown event listener management.

The current implementation adds a global keydown event listener without checking if the modal is open, which could interfere with other components. Additionally, the dependencies array is incomplete.

  useEffect(() => {
-   window.addEventListener('keydown', handleEnter as EventListener);
-   return () => {
-     window.removeEventListener('keydown', handleEnter as EventListener);
-   };
-  }, [loginData, destination, sendMode]);
+   if (openModal) {
+     window.addEventListener('keydown', handleEnter as EventListener);
+     return () => {
+       window.removeEventListener('keydown', handleEnter as EventListener);
+     };
+   }
+  }, [loginData, destination, sendMode, canOpenSession, openModal]);

Also update the handleEnter function:

  function handleEnter(event: KeyboardEvent) {
-   if (canOpenSession && (event as KeyboardEvent)?.key === 'Enter') {
+   if (openModal && canOpenSession && (event as KeyboardEvent)?.key === 'Enter') {
      console.log('OpenSessionModal event');
      handleOpenSession();
    }
  }

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.

Leave only meaningful indexing data
1 participant