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

Ziga/gateway metamask connect button #1579

Merged
merged 9 commits into from
Oct 16, 2023

Conversation

zkokelj
Copy link
Contributor

@zkokelj zkokelj commented Oct 4, 2023

Why this change is needed

For the users to select which accounts they want to connect from metamask

What changes were made as part of this PR

  • new connect button and functionality
  • small code refactoring
  • added different testnet names

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

@zkokelj zkokelj requested a review from otherview October 4, 2023 12:56
@zkokelj zkokelj marked this pull request as ready for review October 4, 2023 12:56
return accounts.length > 0;

} catch (error) {
console.log("Unable to get accounts")
Copy link
Contributor

Choose a reason for hiding this comment

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

should this return false ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already returning false (after catch statement is executed)

Copy link
Contributor

@otherview otherview left a comment

Choose a reason for hiding this comment

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

minor thing, non-blocker lgtm 👍

Copy link
Contributor

@otherview otherview left a comment

Choose a reason for hiding this comment

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

Would had some info to the user or console if the join fails - but not a blocker imo, lgtm

headers: jsonHeaders,
});
if (!joinResp.ok) {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Should something be logged to the console and/or user here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added console log and message to user to try again later.

@coderabbitai
Copy link

coderabbitai bot commented Oct 16, 2023

Walkthrough

The changes primarily focus on enhancing the interaction with the Obscuro network in the wallet extension. The modifications include the removal of certain UI elements, addition of new functions to handle network-related tasks, and updates to existing functions to improve their functionality and efficiency. The changes aim to streamline the user experience and ensure the extension works seamlessly with the Obscuro network.

Changes

File Path Summary
.../api/staticOG/index.html Removed UI elements "addAccount", "addAllAccounts", and "status".
.../api/staticOG/javascript.js Added constants and functions to handle network-related tasks. Updated existing functions for improved functionality. Removed event listeners for removed UI elements. Added event listener for account changes.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

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

Commits Files that changed from the base of the PR and between 1dea9e9 and 40d43bc.
Files ignored due to filter (2)
  • tools/walletextension/api/staticOG/MetaMaskIcon.png
  • tools/walletextension/api/staticOG/favicon-32x32.png
Files selected for processing (2)
  • tools/walletextension/api/staticOG/index.html (1 hunks)
  • tools/walletextension/api/staticOG/javascript.js (8 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/api/staticOG/index.html
Additional comments (Suppressed): 9
tools/walletextension/api/staticOG/javascript.js (9)
  • 24-25: The obscuroChainIDHex is now a constant and no longer passed as a parameter to the addNetworkToMetaMask function. Ensure that this change does not affect other parts of the code that might be using the addNetworkToMetaMask function.

  • 56-64: The getNetworkName function is a new addition and it returns the network name based on the gatewayAddress. This is a good practice as it makes the code more maintainable and easier to update in the future if more networks are added.

  • 67-78: The addNetworkToMetaMask function has been updated to use the getNetworkName function and the obscuroChainIDHex constant. This is a good practice as it makes the code more maintainable and easier to update in the future if more networks are added.

  • 151-162: The getUserID function has been updated to check if the current chain is Obscuro before attempting to retrieve the user ID. This is a good practice as it prevents unnecessary requests from being made if the current chain is not Obscuro.

  • 164-167: The connectAccount function has been renamed to connectAccounts and no longer takes any parameters. Ensure that this change does not affect other parts of the code that might be using the connectAccount function.

  • 174-184: The isMetamaskConnected function is a new addition and it checks if any accounts are connected to MetaMask. This is a good practice as it allows the code to handle different scenarios based on whether or not MetaMask is connected.

  • 239-255: The isObscuroChain and switchToObscuroNetwork functions are new additions and they check if the current chain is Obscuro and switch to the Obscuro network if necessary. These are good practices as they allow the code to handle different scenarios based on the current chain.

  • 257-360: The initialize function has been significantly updated to handle different scenarios based on the current chain and user ID. This is a good practice as it makes the code more flexible and easier to maintain. However, ensure that these changes do not affect other parts of the code that might be using the initialize function.

  • 364-371: The revokeUserIDButton event listener has been updated to call the displayOnlyJoin function if the user ID is successfully revoked. This is a good practice as it provides immediate feedback to the user.

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

Commits Files that changed from the base of the PR and between 40d43bc and 7f5de17.
Files selected for processing (1)
  • tools/walletextension/api/staticOG/javascript.js (9 hunks)
Additional comments (Suppressed): 10
tools/walletextension/api/staticOG/javascript.js (10)
  • 8-9: New constants idAccountsTable and idTableBody are introduced. Ensure these IDs are correctly assigned in the HTML file.

  • 24-25: The obscuroChainIDHex constant is introduced. Ensure that the obscuroChainIDDecimal variable is defined and correctly set before this line.

  • 57-66: The getNetworkName function is introduced. This function returns the network name based on the gatewayAddress. Ensure that all possible gatewayAddress values are covered in the switch statement.

  • 85-96: The addNetworkToMetaMask function is modified. The chainId and chainName are now set using the new constants and functions. Ensure that these changes do not affect the function's behavior.

  • 169-180: The getUserID function is modified. It now checks if the current chain is Obscuro before attempting to get the user ID. This is a good practice as it prevents unnecessary requests on non-Obscuro chains.

  • 182-185: The connectAccount function is renamed to connectAccounts. Ensure that all calls to this function throughout the codebase have been updated to match the new name.

  • 192-202: The isMetamaskConnected function is introduced. This function checks if MetaMask is connected by checking if there are any accounts. This is a good practice as it allows the application to handle scenarios where MetaMask is not connected.

  • 257-273: The isObscuroChain and switchToObscuroNetwork functions are introduced. These functions check if the current chain is Obscuro and switch to the Obscuro network, respectively. These are good practices as they allow the application to handle scenarios where the user is on a different chain.

  • 275-378: The initialize function is significantly modified. It now handles different scenarios based on the current chain and user ID. This is a good practice as it allows the application to adapt to different user states. However, this function has become quite complex. Consider breaking it down into smaller, more manageable functions.

  • 382-389: The revokeUserIDButton event listener is modified. It now calls the displayOnlyJoin function if the user ID is successfully revoked. This is a good practice as it updates the UI to reflect the user's new state.

@zkokelj zkokelj merged commit a58288f into main Oct 16, 2023
3 checks passed
@zkokelj zkokelj deleted the ziga/gateway_metamask_connect_button branch October 16, 2023 09:24
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