npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lido-sdk/web3-react

v2.0.0

Published

Web3 react helpers for Lido Finance projects. Part of [Lido JS SDK](https://github.com/lidofinance/lido-js-sdk/#readme)

Downloads

165

Readme

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>
    );
  }

  // ...
};