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

Overall improvements in node admin for HOPRd 2.1.5 #640

Merged
merged 5 commits into from
Nov 12, 2024
Merged

Overall improvements in node admin for HOPRd 2.1.5 #640

merged 5 commits into from
Nov 12, 2024

Conversation

mjadach-iv
Copy link
Contributor

@mjadach-iv mjadach-iv commented Nov 12, 2024

Changelog:

  • Moved the current ticket prive to the info page
  • Add Alias modal - removed a possibility of assiging an alias to a Peer ID if that Peet ID already has an alias
  • Add Alias modal - an alias can't include a space
  • Withdraw modal - validation: amount to withdraw, presence of the recepient address
  • Withdraw modal - disabed an option to withdraw a token that is not in the nodes wallet
  • Withdraw modal - computational improvement

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced validation for peer IDs in the Add Alias modal, including duplicate checks and error messaging.
    • Improved withdrawal process with dynamic maximum amount tracking and validation for withdrawal amounts.
    • Display of current ticket price in the Network section of the node info page.
  • Bug Fixes

    • Streamlined user interface by removing the ticket price display from the Tickets page.

These updates improve user experience by providing clearer feedback and more robust functionality across the application.

Copy link

coderabbitai bot commented Nov 12, 2024

Warning

Rate limit exceeded

@mjadach-iv has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

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

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 28260fe and 5778552.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple components. The AddAliasModal now includes improved state management and validation for peer IDs, while the WithdrawModal enhances withdrawal functionality with new state variables and validation checks. The InfoPage component adds a ticket price display, and the TicketsPage removes the ticket price, streamlining its interface. Overall, these changes focus on enhancing user experience through better validation and state management.

Changes

File Path Change Summary
src/components/Modal/node/AddAliasModal.tsx Added state variable duplicatePeerId for tracking duplicate peer IDs, updated validation logic, and modified UI elements for error handling.
src/components/Modal/node/WithdrawModal.tsx Introduced state variable maxAmount, added computed properties for validation, modified UI for withdrawal amount input, and updated button conditions.
src/pages/node/info/index.tsx Added state variable ticketPrice to display current ticket price, updated fetchInfoData to include ticket statistics dispatch.
src/pages/node/tickets.tsx Removed ticketPrice state variable and associated UI elements, streamlining the component.

Possibly related PRs

  • Hoprd 2.1.5 #636: The WithdrawModal component in this PR has been modified, which is relevant as it shares the same file path (src/components/Modal/node/WithdrawModal.tsx) as the main PR's AddAliasModal.tsx. Both involve state management and validation logic within modal components, indicating potential shared functionality or design patterns.

Suggested reviewers

  • Jaguaras

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.

@mjadach-iv mjadach-iv requested a review from esterlus November 12, 2024 09:11
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

🧹 Outside diff range and nitpick comments (6)
src/components/Modal/node/AddAliasModal.tsx (2)

31-31: Consider memoizing derived arrays for better performance.

The arrays aliasesArr and aliasPeerIdsArr are derived from the aliases object on every render. Consider using useMemo to prevent unnecessary recalculations.

-  const aliasesArr = aliases ? Object.keys(aliases) : [];
-  const aliasPeerIdsArr = aliases ? Object.values(aliases) : [];
+  const aliasesArr = useMemo(() => (aliases ? Object.keys(aliases) : []), [aliases]);
+  const aliasPeerIdsArr = useMemo(() => (aliases ? Object.values(aliases) : []), [aliases]);

Also applies to: 34-35


163-165: Consider enhancing the error message with more details.

While the error feedback is good, it could be more helpful by showing which alias is already using this Peer ID.

-            helperText={duplicatePeerId ? 'This Peer Id already has an alias!' : ''}
+            helperText={duplicatePeerId ? `This Peer ID is already aliased as "${Object.keys(aliases || {}).find(key => aliases[key] === peerId)}"` : ''}
src/components/Modal/node/WithdrawModal.tsx (3)

110-110: Consider refactoring for better maintainability

The current implementation duplicates logic between HOPR and NATIVE currency handling.

Consider simplifying the code:

  const setMaxAmount = () => {
-   if (currency === 'HOPR' && hoprBalance.formatted) {
-     set_amount(hoprBalance.formatted);
-     set_maxAmount(hoprBalance.formatted);
-   } else if (currency === 'NATIVE' && nativeBalance.formatted) {
-     set_amount(nativeBalance.formatted);
-     set_maxAmount(nativeBalance.formatted);
-   }
+   const balance = currency === 'HOPR' ? hoprBalance : nativeBalance;
+   if (balance.formatted) {
+     set_amount(balance.formatted);
+     set_maxAmount(balance.formatted);
+   }
  };

Also applies to: 113-113


204-215: Consider using numeric comparison for balance checks

String comparison with "0" could be fragile. Consider using numeric comparison for better reliability.

-  disabled={!nativeBalance.value || nativeBalance.value === "0"}
+  disabled={!nativeBalance.value || BigInt(nativeBalance.value) === BigInt(0)}

-  disabled={!hoprBalance.value || hoprBalance.value === "0"}
+  disabled={!hoprBalance.value || BigInt(hoprBalance.value) === BigInt(0)}

235-235: Consider standardizing address shortening

The current implementation has hardcoded indices and inconsistent fallback format.

Consider creating a reusable utility:

const shortenAddress = (address: string) => 
  address ? `${address.slice(0, 6)}...${address.slice(-4)}` : '';

Then use it consistently:

- placeholder={ safeAddress ? `${safeAddress.substring(0,6)}...${safeAddress.substring(38)}` : "0x4f5a...1728" }
+ placeholder={ safeAddress ? shortenAddress(safeAddress) : shortenAddress("0x4f5a1728") }
src/pages/node/info/index.tsx (1)

328-338: Consider adding type safety checks for ticket price formatting

The current implementation assumes ticketPrice is always a valid string for BigInt conversion. Consider adding validation to handle potential edge cases.

-              <td>{ticketPrice ? formatEther(BigInt(ticketPrice as string)) : '-'} wxHOPR</td>
+              <td>
+                {ticketPrice ? (
+                  try {
+                    formatEther(BigInt(ticketPrice as string))
+                  } catch (e) {
+                    console.error('Invalid ticket price format:', e);
+                    return '-';
+                  }
+                ) : '-'} wxHOPR
+              </td>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fb45691 and 28260fe.

📒 Files selected for processing (4)
  • src/components/Modal/node/AddAliasModal.tsx (4 hunks)
  • src/components/Modal/node/WithdrawModal.tsx (4 hunks)
  • src/pages/node/info/index.tsx (2 hunks)
  • src/pages/node/tickets.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • src/pages/node/tickets.tsx
🔇 Additional comments (8)
src/components/Modal/node/AddAliasModal.tsx (4)

43-47: LGTM! Good addition of duplicate peer ID validation.

The validation logic correctly prevents users from creating multiple aliases for the same peer ID.


66-66: LGTM! Proper state cleanup.

Good practice to reset the validation state when closing the modal.


181-181: LGTM! Comprehensive form validation.

The button's disabled state correctly accounts for all invalid input conditions, including the new duplicate peer ID check.


Line range hint 1-194: Verify consistent validation patterns across other modal components.

Let's ensure other components that handle peer IDs implement similar validation patterns for consistency.

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

79-79: LGTM: Robust validation implementation

The new validation checks effectively prevent invalid withdrawals with proper precision handling using parseEther.

Also applies to: 86-86, 91-93


242-247: LGTM: Comprehensive button validation

The validation checks effectively prevent invalid withdrawals by ensuring all required conditions are met.


229-229: Consider adding decimal place validation

While step="any" allows flexible input, consider adding validation for maximum decimal places based on token precision.

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

68-68: LGTM: Redux selector implementation is correct

The state management follows Redux best practices with proper selector usage.

@mjadach-iv mjadach-iv merged commit 9cf6f90 into main Nov 12, 2024
4 checks passed
@mjadach-iv mjadach-iv deleted the 2.1.10 branch November 12, 2024 09:37
@coderabbitai coderabbitai bot mentioned this pull request Nov 18, 2024
This was referenced 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.

Prevent spaces in the alias Change place of the ticket price to network tabale unedr info Withdraw tokens
2 participants