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

[chore] ♻️ Refactor onConnect listener creation to a util function #19

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

QuintonC
Copy link
Collaborator

@QuintonC QuintonC commented Feb 14, 2023

What is the context for these changes?

Refactors and simplifies the onConnect listener logic. This allows for easier middleware creation for onConnect events by removing the possibility to missed actions (if the actions for onConnect logic are to ever change) and DRYs up the creation of listeners.

The inspiration behind this was not only to DRY up the code a bit, but also because in #4 I am going to re-use this logic (it could likely be reused in #13 as well) for looking up ENS names when a wallet connects.

Note: I was going to add tests for useMiddleware.ts as well, however I noticed that we need to create some form of app context in order to render hooks with the state provider. I'd prefer for that to be done the right way, and I believe that doing so will make this PR larger than it should be.

How can this be tophatted?

Primarily green CI (I've added tests for the functionality). However, I will also run /snapit and link a CodeSandbox with the snapshot version for testing.

Test CodeSandbox

🎩 Checklist

  • Tested on mobile
  • Tested on multiple browsers
  • Includes unit tests (see note in the context for the PR)
  • Tested for accessibility N/A
  • Updated relevant documentation for the changes (if necessary) N/A

@QuintonC
Copy link
Collaborator Author

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @QuintonC! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/[email protected]
yarn add @shopify/[email protected]

@QuintonC
Copy link
Collaborator Author

You can test this PR using this CodeSandbox

Copy link
Contributor

@jamiely jamiely left a comment

Choose a reason for hiding this comment

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

Great cleanup, thanks! I tophatted only on MetaMask Desktop


return unsubscribeToOnConnectListener;
return dispatch(listener);
}, [dispatch, onConnect, requireSignature]);
Copy link
Contributor

Choose a reason for hiding this comment

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

is requireSignature still a dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is requireSignature still a dependency?

Nope! Good eye. That also removes some other lines from the hook. Thanks!

@QuintonC QuintonC force-pushed the chore/listener-simplification branch from b6ad1ca to 2068be3 Compare February 16, 2023 03:26
@QuintonC QuintonC merged commit ffb097d into main Feb 16, 2023
@QuintonC QuintonC deleted the chore/listener-simplification branch February 16, 2023 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Testing 🧪 Improvements or additions to unit tests Package: connect-wallet 🤖Skip Changelog Type: Enhancement 📈 Enhancement to our codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants