hdwallet icon indicating copy to clipboard operation
hdwallet copied to clipboard

Patch a provider-narrowed `detectEthereumProvider`

Open gomesalexandre opened this issue 3 years ago • 1 comments

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 https://github.com/MetaMask/detect-provider/issues/49. This forces us to use a hacky cast to type things correctly: https://github.com/shapeshift/hdwallet/blob/fe0312061a0d7fb68ef4ab2e8eb82d97bce56f5f/packages/hdwallet-metamask/src/adapter.ts#L24-L25
  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

https://github.com/shapeshift/hdwallet/blob/a7cdf766b74cca220142882db0f6d78ea28bc0c3/packages/hdwallet-tallyho/src/adapter.ts#L61

https://github.com/shapeshift/hdwallet/blob/a7cdf766b74cca220142882db0f6d78ea28bc0c3/packages/hdwallet-metamask/src/adapter.ts#L23

https://github.com/shapeshift/hdwallet/blob/a7cdf766b74cca220142882db0f6d78ea28bc0c3/packages/hdwallet-xdefi/src/adapter.ts#L24

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

gomesalexandre avatar Jun 28 '22 16:06 gomesalexandre

:)

chidubemOkafor avatar Jul 10 '22 04:07 chidubemOkafor