Skip to content

Patch a provider-narrowed detectEthereumProvider  #545

@gomesalexandre

Description

@gomesalexandre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions