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

[Gateway] - FE Fixes for non-MM users #1690

Conversation

Jennievon
Copy link
Contributor

Why this change is needed

Please provide a description and a link to the underlying ticket

https://github.com/ten-protocol/ten-internal/issues/2584

What changes were made as part of this PR

Please provide a high level list of the changes made

  • proper error handling for non-MM users
  • prompt user to install MM

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

- proper error handling for non-MM users
- prompt user to install MM
@Jennievon Jennievon requested a review from zkokelj December 11, 2023 13:10
@Jennievon Jennievon self-assigned this Dec 11, 2023
Copy link

coderabbitai bot commented Dec 11, 2023

Warning

Rate Limit Exceeded

@Jennievon has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 8 minutes and 24 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. 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 Files that changed from the base of the PR and between 318d088 and d042e6f.

Walkthrough

The recent updates to the wallet extension's frontend involve enhancing error handling by changing thrown errors from Error objects to string messages, improving user interaction by conditionally handling click events based on the presence of ethereum, and refining user feedback with additional showToast messages. A new utility function downloadMetaMask has been introduced, and its usage is integrated into components to guide users without MetaMask installed. These changes aim to streamline user experience and error reporting within the extension.

Changes

File Path Change Summary
.../frontend/src/api/ethRequests.ts
.../frontend/src/services/ethService.ts
Replaced throwing Error objects with string messages; modified error handling.
.../frontend/src/components/.../connect-wallet.tsx
.../frontend/src/components/.../disconnected.tsx
.../frontend/src/lib/utils.ts
Conditionally handled click events based on ethereum presence; added downloadMetaMask and ethereum imports; added null check for ethereum and introduced downloadMetaMask function.
.../frontend/src/services/useGatewayService.ts Modified showToast to pass error directly.
.../frontend/next.config.js Updated comments and changed string quotations.

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Copy link
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

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

It does not solve the problem for me.

Both for static files and npm run dev it shows me same error:

image

To reproduce it just visit it in the incognito window.

Base automatically changed from jennifer/2583-gateway-switching-to-another-account-in-mm-it-reports-an-error-fetching-the-accounts to main December 11, 2023 15:20
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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b428c62 and 903d2a0.
Files selected for processing (6)
  • tools/walletextension/frontend/src/api/ethRequests.ts (5 hunks)
  • tools/walletextension/frontend/src/components/modules/common/connect-wallet.tsx (3 hunks)
  • tools/walletextension/frontend/src/components/modules/home/disconnected.tsx (3 hunks)
  • tools/walletextension/frontend/src/lib/utils.ts (2 hunks)
  • tools/walletextension/frontend/src/services/ethService.ts (2 hunks)
  • tools/walletextension/frontend/src/services/useGatewayService.ts (1 hunks)
Additional comments: 13
tools/walletextension/frontend/src/api/ethRequests.ts (1)
  • 39-45: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [39-116]

The PR description mentions that one of the objectives is to prompt users to install MetaMask if it's not present. However, the provided hunks do not show this functionality. Please verify if these changes are included elsewhere in the PR.

tools/walletextension/frontend/src/components/modules/common/connect-wallet.tsx (3)
  • 6-6: The import of downloadMetaMask and ethereum aligns with the PR's objective to handle non-MetaMask users by prompting them to install MetaMask if necessary.

  • 15-21: The conditional logic in the onClick event handler is well-implemented to handle user interactions based on the presence of ethereum. It ensures that the correct function is called depending on whether the user has MetaMask installed and whether the wallet is connected.

  • 32-32: The button text dynamically changes to prompt the user to either "Connect" or "Install" MetaMask, which is a good user experience practice, making the interface intuitive for both MetaMask users and non-users.

tools/walletextension/frontend/src/components/modules/home/disconnected.tsx (3)
  • 19-19: The addition of the downloadMetaMask and ethereum imports aligns with the PR's objective to handle non-MetaMask users.

  • 107-114: The conditional logic in the onClick handler to either connect to the Ten Testnet or prompt the installation of MetaMask is a good implementation of the PR's objectives.

  • 104-117: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [16-117]

Overall, the changes in disconnected.tsx are consistent with the PR's objectives and do not introduce any apparent issues.

tools/walletextension/frontend/src/lib/utils.ts (3)
  • 42-48: The null check for ethereum in isTenChain is a good addition to prevent runtime errors in non-MetaMask environments.

  • 55-57: The downloadMetaMask function is correctly implemented to open the MetaMask download page in a new tab, with a check for window to ensure SSR compatibility.

  • 52-53: Verify that the newly exported ethereum object from utils.ts is used consistently and does not cause any side effects in the application.


The usage of the newly exported ethereum object from utils.ts has been verified across several files without any apparent side effects. The changes appear to be consistent with the PR's objectives.

tools/walletextension/frontend/src/services/ethService.ts (3)
  • 50-56: The change to return the showToast call in the handleEthereum function is consistent with the PR objectives. Ensure that the callers of handleEthereum are updated to handle the returned value if they expect a void return type.

The verification process did not find any calls to handleEthereum, indicating that there are no issues with how the returned value is handled in the current codebase.

  • 96-101: The addition of a showToast call in the formatAccounts function to indicate the success of updating account authentication status aligns with the PR objectives. Ensure that this message is appropriate and does not introduce any side effects, such as being called multiple times in a loop or in rapid succession.

  • 50-56: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-102]

Overall, the changes in ethService.ts are consistent with the PR objectives and the AI-generated summary. No further issues are identified in the provided hunk.

Comment on lines 60 to 62
} catch (error: any) {
showToast(ToastType.DESTRUCTIVE, `${error.message}`);
showToast(ToastType.DESTRUCTIVE, `${error}`);
throw error;
Copy link

Choose a reason for hiding this comment

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

The showToast function is being passed the entire error object, which may not result in a user-friendly message. Consider using error.message to ensure that the toast displays a meaningful error message to the user.

- showToast(ToastType.DESTRUCTIVE, `${error}`);
+ showToast(ToastType.DESTRUCTIVE, error.message || 'An unknown error occurred');

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.

Suggested change
} catch (error: any) {
showToast(ToastType.DESTRUCTIVE, `${error.message}`);
showToast(ToastType.DESTRUCTIVE, `${error}`);
throw error;
} catch (error: any) {
showToast(ToastType.DESTRUCTIVE, error.message || 'An unknown error occurred');
throw error;

@@ -39,7 +39,7 @@ const typedData = {

export const switchToTenNetwork = async () => {
if (!ethereum) {
throw new Error("No ethereum object found");
throw "No ethereum object found";
Copy link

Choose a reason for hiding this comment

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

The change from throwing an Error object to a string literal may impact error handling logic downstream that relies on properties of Error objects. Consider throwing a new Error with a message instead to maintain consistency with error object properties.

- throw "No ethereum object found";
+ throw new Error("No ethereum object found");

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.

Suggested change
throw "No ethereum object found";
throw new Error("No ethereum object found");

@@ -55,7 +55,7 @@

export const connectAccounts = async () => {
if (!ethereum) {
throw new Error("No ethereum object found");
throw "No ethereum object found";
Copy link

Choose a reason for hiding this comment

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

This comment is the same as the previous one. Ensure that the error handling logic is consistent across the application by throwing Error objects instead of string literals.

- throw "No ethereum object found";
+ throw new Error("No ethereum object found");

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.

Suggested change
throw "No ethereum object found";
throw new Error("No ethereum object found");

@@ -69,7 +69,7 @@

export const getSignature = async (account: string, data: any) => {
if (!ethereum) {
throw new Error("No ethereum object found");
throw "No ethereum object found";
Copy link

Choose a reason for hiding this comment

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

As with the previous instances, throwing a string literal here can lead to issues with error handling that expects an Error object.

- throw "No ethereum object found";
+ throw new Error("No ethereum object found");

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.

Suggested change
throw "No ethereum object found";
throw new Error("No ethereum object found");

@@ -78,7 +78,7 @@
});
} catch (error) {
console.error(error);
throw new Error("Failed to get signature");
throw "Failed to get signature";
Copy link

Choose a reason for hiding this comment

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

The thrown string literal here should be replaced with an Error object to ensure that any error handling expecting an Error object can function correctly.

- throw "Failed to get signature";
+ throw new Error("Failed to get signature");

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.

Suggested change
throw "Failed to get signature";
throw new Error("Failed to get signature");

@@ -110,7 +110,7 @@

export async function addNetworkToMetaMask(rpcUrls: string[]) {
if (!ethereum) {
throw new Error("No ethereum object found");
throw "No ethereum object found";
Copy link

Choose a reason for hiding this comment

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

Again, it's important to throw Error objects to maintain consistency in error handling throughout the application.

- throw "No ethereum object found";
+ throw new Error("No ethereum object found");

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.

Suggested change
throw "No ethereum object found";
throw new Error("No ethereum object found");

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 903d2a0 and 318d088.
Files ignored due to filter (1)
  • tools/walletextension/api/static/favicon.ico
Files selected for processing (1)
  • tools/walletextension/frontend/next.config.js (1 hunks)
Additional comments: 2
tools/walletextension/frontend/next.config.js (2)
  • 4-8: The distDir configuration has been commented out. This change could have significant implications on where the static files are generated during the build process. If the distDir was intentionally removed, ensure that this change is reflected in the build and deployment scripts and that all team members are aware of the new build directory. If this was unintentional, the distDir should be uncommented or the rationale for its removal should be documented.

  • 4-4: The change from single quotes to double quotes for the output value is a stylistic preference and does not affect functionality.

Copy link
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

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

LGMT 👍

@Jennievon Jennievon merged commit b2651ab into main Dec 11, 2023
0 of 2 checks passed
@Jennievon Jennievon deleted the jennifer/2584-gateway-frontend-improvement-before-testnet-release branch December 11, 2023 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants