@web3-react/types#ConnectorUpdate TypeScript Examples

The following examples show how to use @web3-react/types#ConnectorUpdate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Arkane.ts    From interface-v2 with GNU General Public License v3.0 6 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    const options = {
      clientId: this.clientID,
      secretType: SecretType.MATIC,
      signMethod: 'POPUP',
      skipAuthentication: false,
    };
    const arkaneProvider = await Arkane.createArkaneProviderEngine(options);
    if (!this.arkane) {
      this.arkane = new ArkaneConnect(this.clientID);
    }

    const web3 = new Web3(arkaneProvider as any);
    const accounts = await web3.eth.getAccounts();

    return {
      provider: arkaneProvider,
      chainId: this.chainId,
      account: accounts[0],
    };
  }
Example #2
Source File: Portis.ts    From interface-v2 with GNU General Public License v3.0 6 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    if (!this.portis) {
      const Portis = await import('@portis/web3').then((m) => m?.default ?? m);
      this.portis = new Portis(this.dAppId, this.config);
    }

    this.portis.onLogout(this.handleOnLogout);
    this.portis.onActiveWalletChanged(this.handleOnActiveWalletChanged);
    this.portis.onError(this.handleOnError);

    const account = await this.portis.provider
      .enable()
      .then((accounts: string[]): string => accounts[0]);

    return { provider: this.portis.provider, account };
  }
Example #3
Source File: WalletLink.ts    From interface-v2 with GNU General Public License v3.0 6 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    const ethereum = window.ethereum as any;
    if (ethereum && ethereum.isCoinbaseWallet === true) {
      // user is in the dapp browser on Coinbase Wallet
      this.provider = (window as any).ethereum;
    } else if (!this.walletLink) {
      const WalletLink = await import('walletlink').then(
        (m) => m?.default ?? m,
      );
      this.walletLink = new WalletLink({
        appName: this.appName,
        darkMode: this.darkMode,
        ...(this.appLogoUrl ? { appLogoUrl: this.appLogoUrl } : {}),
      });
      this.provider = this.walletLink.makeWeb3Provider(this.url, CHAIN_ID);
    }

    const accounts = await this.provider.request({
      method: 'eth_requestAccounts',
    });
    const account = accounts[0];

    this.provider.on('chainChanged', this.handleChainChanged);
    this.provider.on('accountsChanged', this.handleAccountsChanged);

    return { provider: this.provider, account: account };
  }
Example #4
Source File: bscConnector.ts    From cheeseswap-interface with GNU General Public License v3.0 6 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    if (!window.BinanceChain) {
      throw new NoBscProviderError()
    }

    if (window.BinanceChain.on) {
      window.BinanceChain.on('chainChanged', this.handleChainChanged)
      window.BinanceChain.on('accountsChanged', this.handleAccountsChanged)
      window.BinanceChain.on('close', this.handleClose)
      window.BinanceChain.on('networkChanged', this.handleNetworkChanged)
    }

    if ((window.BinanceChain as any).isMetaMask) {
      (window.BinanceChain as any).autoRefreshOnNetworkChange = false
    }

    // try to activate + get account via eth_requestAccounts
    let account
    try {
      account = await (window.BinanceChain.send as Send)('eth_requestAccounts').then(
        (sendReturn) => parseSendReturn(sendReturn)[0]
      )
    } catch (error) {
      if ((error as any).code === 4001) {
        throw new UserRejectedRequestError()
      }
      warning(false, 'eth_requestAccounts was unsuccessful, falling back to enable')
    }

    // if unsuccessful, try enable
    if (!account) {
      // if enable is successful but doesn't return accounts, fall back to getAccount (not happy i have to do this...)
      account = await window.BinanceChain.enable().then((sendReturn) => sendReturn && parseSendReturn(sendReturn)[0])
    }

    return { provider: window.BinanceChain, ...(account ? { account } : {}) }
  }
Example #5
Source File: NetworkConnector.ts    From cuiswap with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #6
Source File: ledgerConnector.ts    From index-ui with MIT License 5 votes vote down vote up
async activate(): Promise<ConnectorUpdate<string | number>> {
    // Only start the provider on activation. The engine will start
    // polling the blockchain.
    this.provider.start()
    return { provider: this.provider, chainId: this.chainId }
  }
Example #7
Source File: NetworkConnector.ts    From interface-v2 with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return {
      provider: this.providers[this.currentChainId],
      chainId: this.currentChainId,
      account: null,
    };
  }
Example #8
Source File: NetworkConnector.ts    From sybil-interface with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #9
Source File: NetworkConnector.ts    From cheeseswap-interface with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #10
Source File: NetworkConnector.ts    From dyp with Do What The F*ck You Want To Public License 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #11
Source File: NetworkConnector.ts    From mozartfinance-swap-interface with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #12
Source File: NetworkConnector.ts    From pancake-swap-exchange-testnet with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #13
Source File: NetworkConnector.ts    From pancake-swap-testnet with MIT License 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }
Example #14
Source File: connector.d.ts    From safe-apps-sdk with MIT License 5 votes vote down vote up
activate(): Promise<ConnectorUpdate>;
Example #15
Source File: connector.ts    From safe-apps-sdk with MIT License 5 votes vote down vote up
async activate(): Promise<ConnectorUpdate> {
    const runningAsSafeApp = await this.isSafeApp();
    if (!runningAsSafeApp) {
      throw new Error('The app is loaded outside safe context');
    }

    return { provider: await this.getProvider(), chainId: await this.getChainId(), account: await this.getAccount() };
  }
Example #16
Source File: NetworkConnector.ts    From forward.swaps with GNU General Public License v3.0 5 votes vote down vote up
public async activate(): Promise<ConnectorUpdate> {
    return { provider: this.providers[this.currentChainId], chainId: this.currentChainId, account: null }
  }