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 Fixes #1633

Merged
merged 6 commits into from
Nov 7, 2023
Merged

Gateway Fixes #1633

merged 6 commits into from
Nov 7, 2023

Conversation

Jennievon
Copy link
Contributor

@Jennievon Jennievon commented Nov 2, 2023

Why this change is needed

Please provide a description and a link to the underlying ticket

https://github.com/obscuronet/obscuro-internal/issues/2330

What changes were made as part of this PR

Please provide a high level list of the changes made

  • Add an icon for users to copy the address
  • Setup Google Analytics
  • Connect button for unauthenticated accounts
  • Link accounts to Obscuroscan - open when account is clicked

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

Copy link

coderabbitai bot commented Nov 2, 2023

Walkthrough

The changes made to the wallet extension's code aim to enhance the user interface and optimize the JavaScript functions. The HTML structure was reorganized, a new section with instructions and information was added, and Google Analytics was integrated for tracking. The JavaScript file underwent updates to include the userID in various URLs and handle cases when MetaMask is not installed. Additionally, the CSS file saw formatting adjustments for improved readability.

Changes

File Path Summary
tools/walletextension/api/staticOG/index.html Reorganized HTML structure, added new section with instructions and information, integrated Google Analytics for tracking, minor changes to class names and IDs, fixed typos and formatting.
tools/walletextension/api/staticOG/javascript.js Updated gatewayaddress and obscuroscanLink variables, updated various URLs to include gatewayaddress, updated functions to include userID in URLs, modified fetchAndDisplayVersion function, updated event listeners and click handlers, controlled visibility of elements, handled modal display, adopted arrow function syntax in some functions.
tools/walletextension/api/staticOG/style.css Various changes to CSS styles for improved readability, including indentation, spacing, and formatting adjustments.

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 help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

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

@Jennievon Jennievon changed the title Copy Address and Setup Google Analytics Gateway Fixes Nov 3, 2023
@Jennievon Jennievon marked this pull request as ready for review November 3, 2023 22:13
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 aae2f5f and 350a18b.
Files ignored due to filter (2)
  • tools/walletextension/api/staticOG/check.svg
  • tools/walletextension/api/staticOG/copy.svg
Files selected for processing (3)
  • tools/walletextension/api/staticOG/index.html (1 hunks)
  • tools/walletextension/api/staticOG/javascript.js (2 hunks)
  • tools/walletextension/api/staticOG/style.css (2 hunks)
Files skipped from review due to trivial changes (2)
  • tools/walletextension/api/staticOG/index.html
  • tools/walletextension/api/staticOG/style.css
Additional comments: 24
tools/walletextension/api/staticOG/javascript.js (24)
  • 1-5: The constants gatewayaddress, obscuroscanLink, eventClick, eventDomLoaded, and idJoin are defined correctly.

  • 15-30: The constants idBegin, idSpinner, obscuroGatewayVersion, pathJoin, pathAuthenticate, pathQuery, pathRevoke, pathVersion, obscuroChainIDDecimal, methodPost, methodGet, and jsonHeaders are defined correctly.

  • 35-37: The isValidUserIDFormat function is correctly checking if the value is a string and has a length of 64.

  • 45-61: The fetchAndDisplayVersion function is correctly fetching the version from the pathVersion and displaying it in the versionDisplay element. Error handling is also correctly implemented.

  • 64-73: The getNetworkName function is correctly returning the network name based on the gatewayAddress.

  • 75-89: The getRPCFromUrl function is correctly returning the RPC endpoint based on the gatewayAddress.

  • 91-121: The addNetworkToMetaMask function is correctly adding the network to MetaMask and including the userID in the RPC URL. Error handling is also correctly implemented.

  • 123-154: The authenticateAccountWithObscuroGateway function is correctly authenticating the account with the Obscuro Gateway and including the userID in the authentication URL.

  • 156-165: The accountIsAuthenticated function is correctly checking if the account is authenticated and including the userID in the query URL.

  • 167-174: The revokeUserID function is correctly revoking the userID and including it in the revoke URL.

  • 176-181: The getRandomIntAsString function is correctly generating a random integer as a string.

  • 183-198: The getUserID function is correctly getting the user ID using the getRandomIntAsString function.

  • 200-208: The connectAccounts function is correctly connecting the accounts and using the await keyword when requesting accounts. Error handling is also correctly implemented.

  • 210-219: The isMetamaskConnected function is correctly checking if MetaMask is connected and using the await keyword when listing accounts.

  • 222-239: The checkIfMetamaskIsLoaded function is correctly checking if MetaMask is loaded and handling the case when MetaMask is not installed.

  • 241-250: The handleEthereum function is correctly handling the case when MetaMask is not installed.

  • 252-310: The populateAccountsTable function is correctly populating the accounts table and including a link to the account in the table.

  • 312-315: The isObscuroChain function is correctly checking if the current chain is Obscuro and using the await keyword when requesting the current chain.

  • 317-328: The switchToObscuroNetwork function is correctly switching to the Obscuro network and using the await keyword when switching the network.

  • 330-483: The initialize function is correctly handling the new logic and displaying the correct screens based on MetaMask and userID.

  • 485-495: The moreInfo and modal-container elements are correctly handling the modal display.

  • 500-501: The randomChar and randomString functions are correctly generating random characters and strings using arrow function syntax.

  • 503-519: The handleOnMove function is correctly handling mouse and touch events. The card.onmousemove and card.ontouchmove event handlers are correctly using arrow function syntax.

  • 521-521: The checkIfMetamaskIsLoaded function is correctly being called when the DOM is loaded.

@Jennievon Jennievon requested review from CaisManai and 0xjba November 6, 2023 09:41
Copy link
Contributor

@CaisManai CaisManai left a comment

Choose a reason for hiding this comment

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

Looks good! You need to revert some of the javascript variable changes that were added to make it work locally and then we can release.

For example:
const pathJoin = gatewayaddress + "/" + obscuroGatewayVersion + "/join/";

Needs to revert back to the below to work remotely:

const pathJoin = obscuroGatewayVersion + "/join/";

@Jennievon
Copy link
Contributor Author

Looks good! You need to revert some of the javascript variable changes that were added to make it work locally and then we can release.

For example: const pathJoin = gatewayaddress + "/" + obscuroGatewayVersion + "/join/";

Needs to revert back to the below to work remotely:

const pathJoin = obscuroGatewayVersion + "/join/";

Thanks @CaisManai! The variables have been reverted to the default.

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: 21

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 350a18b and f4cdf9f.
Files selected for processing (1)
  • tools/walletextension/api/staticOG/javascript.js (1 hunks)

tools/walletextension/api/staticOG/javascript.js Outdated Show resolved Hide resolved
Comment on lines +484 to +487
$("#moreInfo").click(function () {
var buttonId = "four";
$("#modal-container").removeAttr("class").addClass(buttonId);
$("body").addClass("modal-active");
});
Copy link

Choose a reason for hiding this comment

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

The jQuery click event handler does not handle the case when the #moreInfo element is not available. Consider adding error handling for this case.

Comment on lines +490 to +493
$("#modal-container").click(function () {
$(this).addClass("out");
$(this).addClass("disappear");
$("body").removeClass("modal-active");
});
Copy link

Choose a reason for hiding this comment

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

The jQuery click event handler does not handle the case when the #modal-container element is not available. Consider adding error handling for this case.

@Jennievon Jennievon force-pushed the jennifer/feat/copy_and_google_analytics branch from f4cdf9f to 1512867 Compare November 6, 2023 12:27
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 350a18b and 1512867.
Files selected for processing (1)
  • tools/walletextension/api/staticOG/javascript.js (1 hunks)
Additional comments: 20
tools/walletextension/api/staticOG/javascript.js (20)
  • 36-37: The obscuroGatewayAddress is still being set to the current window's location. However, it seems to be overridden by the hardcoded gatewayaddress on line 39. If obscuroGatewayAddress is not used elsewhere, consider removing it to avoid confusion.

  • 43-59: The fetchAndDisplayVersion function now handles the case when the response is not a valid text. This is a good improvement.

  • 62-70: The getNetworkName function still uses hardcoded URLs. Consider using a configuration or mapping object to make this more maintainable.

  • 73-86: The getRPCFromUrl function still uses hardcoded URLs. Consider using a configuration or mapping object to make this more maintainable.

  • 89-119: The addNetworkToMetaMask function now handles the case when the ethereum.request call fails. This is a good improvement.

  • 121-152: The authenticateAccountWithObscuroGateway function now handles the case when the fetch call fails. This is a good improvement.

  • 154-163: The accountIsAuthenticated function now handles the case when the fetch call fails. This is a good improvement.

  • 165-172: The revokeUserID function now handles the case when the fetch call fails. This is a good improvement.

  • 181-195: The getUserID function now handles the case when the provider.send call fails. This is a good improvement.

  • 198-205: The connectAccounts function now handles the case when the window.ethereum.request call fails. This is a good improvement.

  • 208-217: The isMetamaskConnected function now handles the case when the provider.listAccounts call fails. This is a good improvement.

  • 221-236: The checkIfMetamaskIsLoaded function now handles the case when the window.ethereum object is not available. This is a good improvement.

  • 239-247: The handleEthereum function now handles the case when the window.ethereum object is not available. This is a good improvement.

  • 250-308: The populateAccountsTable function now handles the case when the provider.listAccounts call fails. This is a good improvement.

  • 310-313: The isObscuroChain function now handles the case when the ethereum.request call fails. This is a good improvement.

  • 315-326: The switchToObscuroNetwork function now handles the case when the ethereum.request call fails. This is a good improvement.

  • 328-481: The initialize function is still quite large and does a lot of different things. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.

  • 483-487: The jQuery click event handler now handles the case when the #moreInfo element is not available. This is a good improvement.

  • 489-493: The jQuery click event handler now handles the case when the #modal-container element is not available. This is a good improvement.

  • 515-517: The onmousemove and ontouchmove event handlers now handle the case when the .card element is not available. This is a good improvement.

@Jennievon Jennievon merged commit e7ab386 into main Nov 7, 2023
@Jennievon Jennievon deleted the jennifer/feat/copy_and_google_analytics branch November 7, 2023 13:21
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