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

fix: properly check if metamask is installed #517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chalabi2
Copy link
Contributor

ISSUE

The cosmos-extension-metamask wallet does not properly check if metamask is installed or not.

SUMMARY

In the Leap metamask snap extension we properly check for the metamask window with

interface MetamaskWindow {
  ethereum?: {
    isMetaMask?: boolean;
  };
}

export const isMetamaskInstalled: () => Promise<boolean> = async () => {
  if (typeof window === 'undefined') {
    return false;
  }

  const ethereum = (window as MetamaskWindow).ethereum;

  if (ethereum?.isMetaMask) {
    return true;
  }

  if (document.readyState === 'complete') {
    if (ethereum?.isMetaMask) {
      return true;
    } else {
      throw ClientNotExistError;
    }
  }

But in the cosmos-extension we do not

interface SnapWindow {
cosmos?: CosmosSnap;
}

export const getSnapProviderFromExtension: () => Promise<
CosmosSnap | undefined
> = async () => {
if (typeof window === 'undefined') {
  return void 0;
}

const cosmos = (window as SnapWindow).cosmos;

if (cosmos) {
  return cosmos;
}

if (document.readyState === 'complete') {
  if (cosmos) {
    return cosmos;
  } else {
    throw ClientNotExistError;
  }
}

@fmorency
Copy link

cc @pyramation

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

Successfully merging this pull request may close these issues.

2 participants