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

Patch a provider-narrowed detectEthereumProvider #545

Open
gomesalexandre opened this issue Jun 28, 2022 · 1 comment
Open

Patch a provider-narrowed detectEthereumProvider #545

gomesalexandre opened this issue Jun 28, 2022 · 1 comment

Comments

@gomesalexandre
Copy link
Contributor

Overview

Currently, we detect ethereum providers with @metamask/detect-provider package.

However, there are two issues with this:

  1. The published npm package isn't up-to-date with the latest source, see npm package is not up to date MetaMask/detect-provider#49. This forces us to use a hacky cast to type things correctly:
    // TODO: remove casting, @metamask/detect-provider npm package hasn't been published with latest typings
    // https://github.com/MetaMask/detect-provider/blame/5ce916fc24779c4b36741531a41d9c8b3cbb0a17/src/index.ts#L37
  2. The logic of the detection is basically "is metamask / is any other provider" with the mustBeMetamask option. While this works perfectly in the context of detecting exactly metamask, this doesn't narrow down other providers, not gives us guarantees that the provider we get is really the provider we want. Which again, makes us use some copypasta detection utils to detect and narrow down the specific provider

We should patch detectEthereumProvider so that it correctly detects MM/XDEFI/Tally, and narrows down the returned provider type.

References and additional details

private async detectTallyProvider(): Promise<TallyHoEthereumProvider | null> {

const provider: any = await detectEthereumProvider({ mustBeMetaMask: true, silent: false, timeout: 3000 });

const provider: any = (globalThis as any).xfi?.ethereum;

Acceptance Criteria

  • detectEthereumProvider is patched with the latest source changes
  • detectEthereumProvider detects, returns and narrows down the types of MetaMask, XDEFI and Tally providers
  • detectTallyProvider and its calls are removed and the patched detectEthereumProvider is used instead
  • (globalThis as any).xfi?.ethereum; is replaced by a call to the patched detectEthereumProvider

Need By Date

No response

Screenshots/Mockups

No response

Estimated effort

3 hours

@chidubemOkafor
Copy link

:)

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

No branches or pull requests

2 participants