aepp-sdk-js icon indicating copy to clipboard operation
aepp-sdk-js copied to clipboard

AccountMetamaskFactory not compatible with Superhero Wallet

Open davidyuk opened this issue 9 months ago • 1 comments

I am having a problem connecting with MM snap.

When the Superhero wallet is present, new AccountMetamaskFactory() does not return the MetaMask provider. Therefore, the .installSnap() method does nothing, and the app hangs.

I previously reported to the SH wallet team about SH conflicting with MM. They made some changes to resolve the issue, but now Snap is not working. I think they are overriding MM provider.. Is it possible to make sure AccountMetamaskFactory returns MM provider?

Image

Originally posted by @yusufseyrek in #2037

davidyuk avatar Mar 09 '25 09:03 davidyuk

related bug on Superhero Wallet side: https://github.com/superhero-com/superhero-wallet/issues/3509

another necessary fix: https://github.com/aeternity/aepp-sdk-js/pull/2050

After resolving the above, I expect this will work out of the box. Meanwhile, you need to manually detect MetaMask provider and give it to AccountMetamaskFactory.

setTimeout(() => window.dispatchEvent(new Event('eip6963:requestProvider')));
const provider = await new Promise((resolve) => {
  const handler = (event) => {
    if (event.detail.info.rdns !== 'io.metamask') return;
    window.removeEventListener('eip6963:announceProvider', handler);
    resolve(event.detail.provider);
  };
  window.addEventListener('eip6963:announceProvider', handler);
  setTimeout(() => {
    window.removeEventListener('eip6963:announceProvider', handler);
    resolve(undefined);
  }, 500);
});
if (provider == null) throw new Error('MetaMask not found');
const factory = new AccountMetamaskFactory(provider);

based on guide: https://docs.metamask.io/snaps/how-to/connect-to-a-snap/

related issue: https://github.com/superhero-com/superhero-wallet/issues/3451

davidyuk avatar Mar 09 '25 09:03 davidyuk