hdwallet
hdwallet copied to clipboard
Patch a provider-narrowed `detectEthereumProvider`
Overview
Currently, we detect ethereum providers with @metamask/detect-provider package.
However, there are two issues with this:
- 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
- The logic of the detection is basically "is metamask / is any other provider" with the
mustBeMetamaskoption. 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
-
detectEthereumProvideris patched with the latest source changes -
detectEthereumProviderdetects, returns and narrows down the types of MetaMask, XDEFI and Tally providers -
detectTallyProviderand its calls are removed and the patcheddetectEthereumProvideris used instead -
(globalThis as any).xfi?.ethereum;is replaced by a call to the patcheddetectEthereumProvider
Need By Date
No response
Screenshots/Mockups
No response
Estimated effort
3 hours
:)