How to use the arc.checkMetaMask function in arc

To help you get started, we’ve selected a few arc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
(newAddress: Address) => {
          if (newAddress && checkMetaMask()) {
            console.log(`new address: ${newAddress}`);
            this.props.setCurrentAccount(newAddress);
            this.props.cookies.set("currentAddress", newAddress, { path: "/"});
            // TODO: we reload on setting a new account,
            // but it would be more elegant if we did not need to
            window.location.reload();
          }
        });
      }
github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
console.log(`using address from web3 connection: ${currentAddress}`);
      this.props.cookies.set("currentAddress", currentAddress, { path: "/"});
      this.props.setCurrentAccount(currentAddress);
    } else {
      const currentAddressFromCookie = this.props.cookies.get("currentAddress");
      if (currentAddressFromCookie) {
        console.log(`using address from cookie: ${currentAddressFromCookie}`);
        this.props.setCurrentAccount(currentAddressFromCookie);
      } else {
        this.props.cookies.set("currentAddress", "", { path: "/"});
        this.props.setCurrentAccount(undefined);
      }
    }

    try {
      metamask = await checkMetaMask();
    } catch (err) {
      console.log("MM not available or not set correctly: using default web3 provider: ", err.message);
    }

    if (metamask) {
      pollForAccountChanges(currentAddress).subscribe(
        (newAddress: Address) => {
          if (newAddress && checkMetaMask()) {
            console.log(`new address: ${newAddress}`);
            this.props.setCurrentAccount(newAddress);
            this.props.cookies.set("currentAddress", newAddress, { path: "/"});
            // TODO: we reload on setting a new account,
            // but it would be more elegant if we did not need to
            window.location.reload();
          }
        });