2.0.0 • Published 11 months ago

@lido-sdk/web3-react v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Web3 react helpers

Web3 react helpers for Lido Finance projects. Part of Lido JS SDK

Install

yarn add @lido-sdk/web3-react

Provider

To use hooks from @lido-sdk/web3-react you need to wrap your app with ProviderWeb3. ProviderWeb3 also contains ProviderSDK from @lido-sdk/react. No need to wrap again.

import { CHAINS } from '@lido-sdk/constants';
import { ProviderWeb3 } from '@lido-sdk/web3-react';

const rpc = {
  [CHAINS.Mainnet]: '/rpc/mainnet',
  [CHAINS.Rinkeby]: '/rpc/rinkeby',
};

const supportedChainIds = [CHAINS.Mainnet, CHAINS.Rinkeby];

const Provider = () => {
  return (
    <ProviderWeb3
      defaultChainId={CHAINS.Mainnet}
      supportedChainIds={supportedChainIds}
      rpc={rpc}
    >
      {children}
    </ProviderWeb3>
  );
};

Connectors

The ProviderWeb3 creates several connectors and stores them in context. To access them directly use useConnectors hook.

Used connectors:

Auto connect

The ProviderWeb3 contains logic to automatically activate one of the connectors when the application is initialized. It checks the conditions and tries to connect in the following order:

  1. To Ledger Live Dapp Browser with LedgerHQFrameConnector.
  2. To Gnosis Safe with SafeAppConnector.
  3. To Dapp browser provider with InjectedConnector.
  4. To a connector saved in Local Storage.

Connector hooks

Hooks for manually connecting to the user's wallet:

  • useConnectorCoinbase
  • useConnectorImToken
  • useConnectorMetamask
  • useConnectorTrust
  • useConnectorWalletConnect

They return an object with a connect handler if connecting is possible. In MetaMask, Trust and ImToken hooks the connect method contains the Deep Linking logic.

import {
  useConnectorMetamask,
  useConnectorCoinbase,
} from '@lido-sdk/web3-react';

const Component = () => {
  const metamask = useConnectorMetamask();
  const coinbase = useConnectorCoinbase();

  return (
    <div>
      <button onClick={metamask.connect}>Connect to Metamask</button>;
      <button onClick={coinbase.connect}>Connect to Coinbase</button>;
    </div>
  );
};

useDisconnect

Return an object with a disconnect handler if disconnection is possible.

import { useDisconnect } from '@lido-sdk/web3-react';

const Component = () => {
  const { disconnect } = useDisconnect();

  return (
    <button onClick={disconnect} disabled={!disconnect}>
      Disconnect
    </button>
  );
};

useSupportedChains

import { useSupportedChains } from '@lido-sdk/web3-react';

const Component = () => {
  const { isUnsupported, supportedChains } = useSupportedChains();

  if (isUnsupported) {
    return (
      <div>
        Chain is not supported. Supported chains:{' '}
        {supportedChains.map(({ name }) => name)}
      </div>
    );
  }

  // ...
};
2.0.0

11 months ago

1.28.7

12 months ago

1.28.5

1 year ago

1.28.6

1 year ago

1.28.4

1 year ago

1.28.1

1 year ago

1.28.2

1 year ago

1.28.3

1 year ago

1.27.4

1 year ago

1.28.0

1 year ago

1.27.3

2 years ago

1.27.2

2 years ago

1.27.0

2 years ago

1.27.1

2 years ago

1.26.1

2 years ago

1.26.2

2 years ago

1.21.0

2 years ago

1.21.1

2 years ago

1.25.0

2 years ago

1.23.0

2 years ago

1.21.2

2 years ago

1.22.0

2 years ago

1.24.1

2 years ago

1.22.3

2 years ago

1.26.0

2 years ago

1.22.1

2 years ago

1.24.0

2 years ago

1.22.2

2 years ago

1.18.1

2 years ago

1.19.0

2 years ago

1.20.1

2 years ago

1.20.0

2 years ago

1.17.2

2 years ago

1.18.0

2 years ago

1.17.1

2 years ago

1.17.3

2 years ago

1.17.0

2 years ago

1.16.1

2 years ago

1.15.0

2 years ago

1.14.1

2 years ago

1.14.0

2 years ago

1.13.1

2 years ago

1.16.0

2 years ago

1.14.2

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.9.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.8.3

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.5

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.4

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago