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

Fix event used for accessing provider #163

Merged
merged 2 commits into from
Apr 6, 2022
Merged

Fix event used for accessing provider #163

merged 2 commits into from
Apr 6, 2022

Conversation

jpuri
Copy link
Contributor

@jpuri jpuri commented Apr 6, 2022

Using load event ensures that window.ethereum is always available in global scope when we access provider.

@jpuri jpuri requested a review from a team as a code owner April 6, 2022 16:31
@Gudahtt
Copy link
Member

Gudahtt commented Apr 6, 2022

The load event is not enough to guarantee that the provider is present on mobile. It gets injected asynchronously. We have a library for blocking on the provider being injected (@metamask/detect-provider). Maybe that would be better here instead?

The reason the initialization was triggered by DOMContentLoaded is that the initialization uses the DOM. It assumes all of the elements are on the page. Nothing happens on load that is directly tied to initialization.

@Gudahtt
Copy link
Member

Gudahtt commented Apr 6, 2022

Oh I see, but we do use window.ethereum right away during initialization. Hmm.

OK this seems like an improvement that we could further improve later by using @metamask/detect-provider, for better mobile compatibility.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jpuri jpuri merged commit bc8e3f9 into main Apr 6, 2022
@jpuri jpuri deleted the event_fix branch April 6, 2022 17:39
@brad-decker brad-decker mentioned this pull request Jun 14, 2022
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.

3 participants