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

Hoprd 2.1.5 #636

Merged
merged 6 commits into from
Oct 31, 2024
Merged

Hoprd 2.1.5 #636

merged 6 commits into from
Oct 31, 2024

Conversation

mjadach-iv
Copy link
Contributor

@mjadach-iv mjadach-iv commented Oct 31, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced ticket price fetching functionality, enhancing node management and user experience.
    • Added a new row in the TicketsPage to display ticket prices with contextual tooltips.
  • Improvements

    • Enhanced the DeleteAliasButton with dynamic tooltips and logic to prevent users from deleting their own aliases.
    • Improved error handling in CSV uploads and withdrawal processes for clearer user notifications.
  • Bug Fixes

    • Simplified error messages in the SendMessageModal for better clarity.
  • Version Updates

    • Project version updated to 2.1.9; dependency @hoprnet/hopr-sdk updated to version 2.1.9.

Copy link

coderabbitai bot commented Oct 31, 2024

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The pull request includes updates to the package.json file for versioning and dependency management, specifically incrementing the project version and updating the @hoprnet/hopr-sdk dependency. Additionally, several components related to node management, including ConnectNodeModal, SendMessageModal, WithdrawModal, and others, have been modified to enhance functionality, such as adding ticket price retrieval and improving error handling. Changes also involve state management updates in the Redux store to accommodate new features like ticket price fetching.

Changes

File Change Summary
package.json - Project version updated from 2.1.8 to 2.1.9.
- Dependency @hoprnet/hopr-sdk updated from 2.1.6 to 2.1.9.
src/components/ConnectNode/modal.tsx - Added asynchronous action nodeActionsAsync.getTicketPriceThunk in useNode function for fetching ticket price.
src/components/Modal/node/SendMessageModal.tsx - Renamed parameter peerIdToAliasLink to aliases in sortAddresses function.
- Simplified error message in handleSendMessage function.
- Updated getOptionLabel to use peerIdToAliasLink directly.
src/components/Modal/node/WithdrawModal.tsx - Reset transactionHash state at the start of withdrawal.
- Renamed parameter ethereumAddress to address in withdrawThunk dispatch.
- Added new parameter timeout with value 240,000 milliseconds.
- Updated button to include pending prop for loading state.
src/router.tsx - Added dispatch call to nodeActionsAsync.getTicketPriceThunk in useEffect of LayoutEnhanced component.
- Commented out console log statements.
src/store/slices/node/actionsAsync.ts - Introduced GetTicketPricePayloadType and GetTicketPriceResponseType types.
- Added getTicketPriceThunk for fetching ticket prices with state management updates.
src/store/slices/node/actionsFetching.ts - Added action creator setTicketPriceFetching to manage fetching state of ticket prices.
- Updated reducer to handle new fetching state.
src/store/slices/node/initialState.ts - Removed peerIdToAlias and added aliasToPeerId in InitialState.
- Introduced ticketPrice property in InitialState with default values.
src/pages/node/aliases.tsx - Updated DeleteAliasButton to include optional tooltip prop and adjusted logic for disabling the button.
src/pages/node/tickets.tsx - Added ticketPrice state variable fetched from Redux store to display ticket price in TableExtended component.

Possibly related PRs

  • Refactor workflows #629: The changes in the main PR involve updates to the package.json file, specifically versioning and dependency updates, which are relevant to the workflows that utilize the package.json for versioning in the CI/CD processes outlined in the refactor workflows PR.

Suggested reviewers

  • esterlus

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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link

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

🧹 Outside diff range and nitpick comments (7)
src/pages/node/channelsOutgoing.tsx (2)

Line range hint 91-134: Consider improving error handling and constants management

A few suggestions to enhance the error handling:

  1. Consider using template literals instead of string concatenation for error messages
  2. The timeout value (5 * 60_000) should be extracted as a named constant
  3. The error handling structure could be flattened using early returns

Here's a suggested refactoring:

+ const CHANNEL_CLOSE_TIMEOUT_MS = 5 * 60_000; // 5 minutes

  const handleCloseChannels = (channelId: string) => {
    dispatch(
      actionsAsync.closeChannelThunk({
        apiEndpoint: loginData.apiEndpoint!,
        apiToken: loginData.apiToken ? loginData.apiToken : '',
        channelId: channelId,
-       timeout: 5 * 60_000,
+       timeout: CHANNEL_CLOSE_TIMEOUT_MS,
      }),
    )
      .unwrap()
      .then(() => {
        handleRefresh();
      })
      .catch(async (e) => {
        const isCurrentApiEndpointTheSame = await dispatch(
          actionsAsync.isCurrentApiEndpointTheSame(loginData.apiEndpoint!),
        ).unwrap();
        if (!isCurrentApiEndpointTheSame) return;

        if (
          e instanceof sdkApiError &&
          e.hoprdErrorPayload?.error?.includes('channel closure time has not elapsed yet, remaining')
        ) {
-         let errMsg = `Closing of outgoing channel ${channelId} halted. C${e.hoprdErrorPayload?.error.substring(1)}`;
+         const errMsg = `Closing of outgoing channel ${channelId} halted. ${e.hoprdErrorPayload?.error}`;
          sendNotification({
            notificationPayload: {
              source: 'node',
              name: errMsg,
              url: null,
              timeout: null,
            },
            toastPayload: { message: errMsg },
            dispatch,
          });
          return;
        }

-       let errMsg = `Closing of outgoing channel ${channelId} failed`;
-       if (e instanceof sdkApiError && e.hoprdErrorPayload?.status)
-         errMsg = errMsg + `.\n${e.hoprdErrorPayload.status}`;
-       if (e instanceof sdkApiError && e.hoprdErrorPayload?.error) errMsg = errMsg + `.\n${e.hoprdErrorPayload.error}`;
+       const errMsg = [
+         `Closing of outgoing channel ${channelId} failed`,
+         e instanceof sdkApiError && e.hoprdErrorPayload?.status ? e.hoprdErrorPayload.status : null,
+         e instanceof sdkApiError && e.hoprdErrorPayload?.error ? e.hoprdErrorPayload.error : null,
+       ].filter(Boolean).join('\n');

Line range hint 1-285: Consider architectural improvements for better maintainability

The component handles multiple responsibilities and could benefit from some architectural improvements:

  1. The table data transformation logic in parsedTableData could be extracted to a separate utility function
  2. Error handling could be moved to a custom hook (e.g., useChannelOperations)
  3. Consider adding proper TypeScript types for the channel and error payload structures

Example structure:

// types.ts
interface Channel {
  id: string;
  peerAddress: string;
  balance: string;
  status: 'Open' | 'PendingToClose' | 'Closed';
  isClosing?: boolean;
}

// hooks/useChannelOperations.ts
const useChannelOperations = () => {
  const dispatch = useAppDispatch();
  
  const closeChannel = async (channelId: string) => {
    // Error handling logic here
  };
  
  return { closeChannel };
};

// utils/tableTransformations.ts
const transformChannelsToTableData = (
  channels: Record<string, Channel>,
  getAliasByPeerAddress: (address: string) => string
) => {
  // Table data transformation logic here
};
src/pages/node/channelsIncoming.tsx (2)

Line range hint 155-156: Consider moving the timeout value to configuration

The hardcoded timeout value of 120,000ms should be moved to a configuration constant, as indicated by the TODO comment.

+ // In a config file
+ export const CHANNEL_CLOSE_TIMEOUT = 120_000; // 2 minutes - average closing time is 50s

- timeout: 120_000, //TODO: put those values as default to HOPRd SDK, average is 50s
+ timeout: CHANNEL_CLOSE_TIMEOUT,

Line range hint 183-246: Consider memoizing table data transformation

The table data transformation is complex and runs on every render. Consider using useMemo to cache the results and improve performance:

- const parsedTableData = Object.keys(channelsIncomingObject)
+ const parsedTableData = useMemo(() => Object.keys(channelsIncomingObject)
    .map((id, index) => {
      // ... existing transformation logic ...
    })
-    .filter((elem) => elem !== undefined) as {
+    .filter((elem) => elem !== undefined), [
+      channelsIncomingObject,
+      nodeAddressToOutgoingChannelLink,
+      tickets,
+      aliases
+    ]) as {
    id: string;
    key: string;
    // ... rest of the type definition ...
  }[];
src/router.tsx (1)

319-324: LGTM! Consider optimizing dispatch sequence.

The ticket price fetch is correctly implemented and properly integrated with the existing authentication flow.

Consider using Promise.all to parallelize the independent data fetches for better performance:

await Promise.all([
  dispatch(nodeActionsAsync.getInfoThunk({ apiEndpoint, apiToken })),
  dispatch(nodeActionsAsync.getAddressesThunk({ apiEndpoint, apiToken })),
  dispatch(nodeActionsAsync.getAliasesThunk({ apiEndpoint, apiToken })),
  // ... other independent fetches
  dispatch(nodeActionsAsync.getTicketPriceThunk({ apiEndpoint, apiToken }))
]);
src/components/Modal/node/SendMessageModal.tsx (1)

268-268: Consider using optional chaining for safer property access.

While the simplified alias handling is good, consider using optional chaining to make the code more defensive against potential runtime errors.

-      return Object.keys(aliases).includes(peerId);
+      return Object.keys(aliases ?? {}).includes(peerId);

-      if (aliases[peerId]) {
-        return aliases[peerId];
+      if (aliases?.[peerId]) {
+        return aliases?.[peerId];

Also applies to: 274-275

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

896-918: LGTM with a suggestion for improved error handling.

The thunk implementation follows the established patterns and includes proper state management. Consider improving the error handling to be more specific about error types.

Consider updating the error handling to be more specific:

-    } catch (e) {
+    } catch (e: unknown) {
       if (e instanceof sdkApiError) {
         return rejectWithValue(e);
       }
-      return rejectWithValue({ status: JSON.stringify(e) });
+      return rejectWithValue({ 
+        status: e instanceof Error ? e.message : JSON.stringify(e) 
+      });
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b54b945 and 2165101.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • package.json (1 hunks)
  • src/components/ConnectNode/modal.tsx (1 hunks)
  • src/components/Modal/node/SendMessageModal.tsx (4 hunks)
  • src/components/Modal/node/WithdrawModal.tsx (2 hunks)
  • src/pages/node/channelsIncoming.tsx (1 hunks)
  • src/pages/node/channelsOutgoing.tsx (1 hunks)
  • src/pages/node/peers.tsx (1 hunks)
  • src/router.tsx (1 hunks)
  • src/store/slices/node/actionsAsync.ts (6 hunks)
  • src/store/slices/node/actionsFetching.ts (3 hunks)
  • src/store/slices/node/initialState.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (19)
src/store/slices/node/actionsFetching.ts (3)

20-20: LGTM: Action creator follows established patterns

The new setTicketPriceFetching action creator is correctly implemented and maintains consistency with existing patterns.


39-39: LGTM: Export follows established patterns

The new action is correctly exported and maintains the alphabetical ordering in the nodeActionsFetching object.


84-86: Verify ticketPrice state structure exists

The reducer case implementation is correct and follows established patterns. However, let's verify that the ticketPrice state structure is properly initialized.

✅ Verification successful

Initial state structure verified successfully

The ticketPrice state structure is properly defined in the initial state with the required isFetching property initialized to false. The implementation is safe to use.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ticketPrice state structure in initial state
# Expected: Should find ticketPrice object with isFetching property in initialState

# Search for ticketPrice definition in initialState
rg -A 5 "ticketPrice.*[:=]" src/store/slices/node/initialState.ts

Length of output: 299

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

54-54: LGTM! Simplified alias handling looks good.

The direct access to the aliases state object is a cleaner approach compared to using a selector. The implementation correctly handles the case when an alias exists by combining it with the peerId.

Let's verify that this is the only place where aliases are being accessed in this component:

✅ Verification successful

Let me gather more information to ensure there are no other alias-related patterns we should check:

This will help us verify if there are any other alias-related patterns or state management code that we should consider.


Alias handling implementation is consistent throughout the component

The verification confirms that the alias handling is consistent in the component:

  • Direct access to aliases state is used only in the getAliasByPeerId function
  • The component correctly fetches aliases data through the Redux store
  • No legacy peerIdToAliasLink selector references remain
  • All alias-related patterns follow the new simplified approach
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to peerIdToAliasLink or other alias-related patterns
# in this component to ensure consistent usage of the new approach

# Test 1: Search for any remaining references to peerIdToAliasLink
rg "peerIdToAliasLink" "src/pages/node/peers.tsx"

# Test 2: Search for other potential alias-related patterns to ensure consistency
ast-grep --pattern 'aliases[$_]' "src/pages/node/peers.tsx"

Length of output: 222


Script:

#!/bin/bash
# Search for any other alias-related patterns in the component
rg -A 2 "alias" "src/pages/node/peers.tsx"

# Search for any state or selector imports related to aliases
rg "import.*alias" "src/pages/node/peers.tsx"

# Look for any Redux-related alias patterns
ast-grep --pattern 'useSelector($$$alias$$$)'

Length of output: 607

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

205-208: LGTM: Well-structured ticket price state.

The new ticketPrice property follows Redux best practices for managing async data with proper typing and loading state.


347-350: LGTM: Proper initialization of new state properties.

The initial values for ticketPrice and aliasToPeerId are correctly initialized with safe default values, maintaining consistency with their type definitions.

Also applies to: 357-357


134-135: Verify the migration strategy for the links.aliasToPeerId change.

The inversion of the mapping direction from peerIdToAlias to aliasToPeerId is a breaking change. While this change makes the data structure more intuitive, we should ensure all components are updated and existing data is properly migrated.

Let's verify the components using this mapping:

✅ Verification successful

Migration of peerIdToAlias to aliasToPeerId appears complete and consistent

Based on the codebase analysis:

  1. The change is only referenced in initialState.ts and actionsAsync.ts
  2. The migration is properly handled in actionsAsync.ts where the new mapping is populated correctly from the aliases data
  3. No other components or selectors are directly accessing this state property, suggesting the mapping is encapsulated within the node slice
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of the old peerIdToAlias property
rg -l 'peerIdToAlias'

# Search for components already updated to use aliasToPeerId
rg -l 'aliasToPeerId'

Length of output: 119


Script:

#!/bin/bash
# Let's examine the actual usage in actionsAsync.ts to understand the migration
rg -A 5 -B 5 'aliasToPeerId|peerIdToAlias' src/store/slices/node/actionsAsync.ts

# Also check for any selectors or reducers that might be handling this state
fd -e ts -e js selector reducer --exec rg -l 'aliasToPeerId|peerIdToAlias' {}

Length of output: 620


Script:

#!/bin/bash
# Let's search for selector and reducer files in a more robust way
fd -e ts -e js . | grep -E '(selector|reducer)' | xargs rg -l 'aliasToPeerId|peerIdToAlias'

# Also check for any components or hooks that might be using this state
rg -C 5 'useSelector.*links' 

Length of output: 200

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

112-112: LGTM: Good practice to reset transaction state

Resetting the transaction hash before starting a new withdrawal ensures a clean state and prevents confusion if the new transaction fails.


Line range hint 127-146: LGTM: Robust error handling implementation

The error handling implementation is thorough and well-structured:

  • Validates current API endpoint before showing errors
  • Constructs clear error messages with status and details
  • Properly handles SDK API errors
🧰 Tools
🪛 eslint

[error] 120-121: Missing trailing comma.

(comma-dangle)


221-226: Verify Button component's pending state implementation

The loading state has been simplified by using the Button component's pending prop. Let's verify the implementation:

#!/bin/bash
# Check Button component implementation
echo "Checking Button component implementation:"
fd "Button.(tsx|js)" src/future-hopr-lib-components -x cat {}

# Check for other usages of pending prop
echo "Checking other usages of pending prop:"
rg "pending={.*}" -A 2 -B 2

117-120: Verify API changes across the codebase

The parameter rename from 'ethereumAddress' to 'address' and addition of a 4-minute timeout warrant verification:

  1. Ensure all other components using the withdraw functionality are updated
  2. Verify if 4-minute timeout aligns with typical transaction completion times
src/pages/node/channelsOutgoing.tsx (1)

72-72: LGTM: Simplified alias lookup logic

The direct access to the aliases object is a cleaner approach that reduces complexity while maintaining the same functionality.

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

80-82: LGTM: Simplified alias lookup logic

The direct access to aliases[peerId] simplifies the code while maintaining proper null checks. The format alias (nodeAddress) provides good user context.


Line range hint 155-182: LGTM: Robust error handling implementation

The error handling is well-implemented with:

  • Type checking using sdkApiError
  • Detailed error messages including status and error details
  • API endpoint verification to prevent stale errors
src/components/Modal/node/SendMessageModal.tsx (1)

Line range hint 190-194: LGTM! Error handling improvements.

The error message construction is now more concise and properly handles SDK API errors with their payloads.

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

303-308: Consider potential race conditions with parallel dispatches.

The new getTicketPriceThunk dispatch is correctly placed within the authentication flow. However, since it's dispatched in parallel with other initialization calls, consider:

  1. Whether the ticket price calculation depends on data from other dispatches (e.g., configuration, metrics)
  2. If dependencies exist, consider chaining the calls or using Promise.all for better control

Let's verify the dependencies and implementation of the ticket price thunk:

✅ Verification successful

Based on the shell script results, I can now generate the final response since I have clear visibility into the thunk implementation. The results show that:

  1. The thunk is a simple, independent operation that only requires apiToken and apiEndpoint
  2. It has proper error handling and state management
  3. There are no dependencies on other state data
  4. It maintains its own fetching state and data storage

The parallel dispatch implementation is correct and safe.

The getTicketPriceThunk implementation shows it's completely independent of other state data and only requires the authentication parameters. The thunk:

  • Has its own fetching state management
  • Properly handles API errors
  • Validates the API endpoint matches before updating state
  • Stores data in an isolated state slice

No changes needed as there are no race conditions or dependencies to be concerned about.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the thunk implementation and its dependencies
echo "Searching for getTicketPriceThunk implementation..."
rg "getTicketPriceThunk.*=" -A 10

echo "Checking for ticket price state usage..."
rg "ticketPrice.*state" -A 5

echo "Checking for dependencies between ticket price and other state..."
ast-grep --pattern 'getTicketPriceThunk($$$)'

Length of output: 2397

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

42-43: LGTM: Type imports are properly structured.

The new ticket price types are correctly imported from the SDK, following the established pattern.


70-70: LGTM: API import follows conventions.

The getTicketPrice API is correctly imported and follows the alphabetical ordering pattern.


1583-1583: LGTM: Export follows conventions.

The getTicketPriceThunk is correctly exported and follows the alphabetical ordering pattern.

src/components/Modal/node/SendMessageModal.tsx Outdated Show resolved Hide resolved
src/components/Modal/node/SendMessageModal.tsx Outdated Show resolved Hide resolved
src/store/slices/node/actionsAsync.ts Show resolved Hide resolved
@mjadach-iv mjadach-iv requested a review from Jaguaras October 31, 2024 14:18
@mjadach-iv mjadach-iv merged commit 9ac987d into main Oct 31, 2024
3 of 4 checks passed
@mjadach-iv mjadach-iv deleted the hoprd-2.1.5 branch October 31, 2024 14:18
@coderabbitai coderabbitai bot mentioned this pull request Dec 2, 2024
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.

1 participant