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

react-dapp-requirements

v0.1.12

Published

(https://github.com/centrifuge/react-dapp-requirements)

Downloads

20

Readme

react-dapp-requirements

Checks all requirements that a user needs in order to use a DApp. All checks must pass in order for the DApp to be rendered.

  • Supported Browser
  • Metamask installation
  • Metamask connection access
  • ETH network
  • Account

The component uses a composition pattern which means that each requirement is a standalone component and can be used independently.

The component comes with default properties, child components and methods which support web3 0.2.x and 1.x in order to work out of the box but all them can be overridden.

static propTypes = {
        // array of supported networks
        supportedNetworks: PropTypes.array.isRequired,
        // Map of labels for eth network ids
        networkMap: PropTypes.object,
        // method that checks if web3 is injected on the window obj. Is Metamask installed?
        web3Provided: PropTypes.func,
        // method that checks for the web3 provider. Connection access granted?
        fetchProvider: PropTypes.func,
        // polling method for current account
        fetchAccount: PropTypes.func,
        // method that retrieves the selected ETH network
        fetchNetwork: PropTypes.func,
        // method that checks for browser(chrome, firefox, opera)
        isBrowserSupported: PropTypes.func,
        // callback for connection access
        onProviderReceived: PropTypes.func,
        // callback for network change
        onNetworkIdReceived: PropTypes.func,
        // callback for account change
        onAccountChange: PropTypes.func,
        // Render when metamsk is not installed
        Web3UnavailableComponent: PropTypes.func,
        // Render if the user does not accept connection access
        ProviderUnavailableComponent: PropTypes.func,
        // Render while waiting for user connection input
        ProviderLoadingComponent: PropTypes.func,
        // Render if the current browser is not supported
        BrowserUnsupportedComponent: PropTypes.func,
        // Render if Metamask is locked
        AccountUnavailableComponent: PropTypes.func,
        // Render while waiting for account information
        AccountLoadingComponent: PropTypes.func,
        // Render if selected ETH network is not supported
        NetworkNotSupportedComponent: PropTypes.func,
        // Render while checking the selected network
        NetworkLoadingComponent: PropTypes.func,
        // Render in case of not Eth network(No internet connect)
        NetworkNotFoundComponent: PropTypes.func,
    };

How to use



class App extends Component {

  onProviderReceived = (provider) => {
      if (provider) // is null if component failed to retrieve it, most likely is a web3/metamask issue
        // Instantiate a instance of web3
  };

  onNetworkIdReceived = (networkId) => {
    if (networkId) // is null if component failed to retrieve it, most likely is a web3/metamask issue
      // Do something with the network id(dispatch a redux action for example)
  };

  onAccountChange = (address, networkId, provider) => {
      // This will not be dispatch if component fails to get the provider or the network
      // Do something(dispatch a redux action for example)
  };

  render() {
    // Add your on rendering components that can have custom styles,internationalization ,etc
    let dappRequirementsScreens = {
      BrowserUnsupportedComponent: injectIntl(BrowserUnsupportedScreen),
      Web3UnavailableComponent: injectIntl(Web3UnavailableScreen),
      ProviderUnavailableComponent: injectIntl(ProviderUnavailableScreen),
      ProviderLoadingComponent: injectIntl(ProviderLoadingScreen),
      AccountUnavailableComponent: injectIntl(AccountUnavailableScreen),
      AccountLoadingComponent: injectIntl(AccountLoadingScreen),
      NetworkNotSupportedComponent: injectIntl(NetworkNotSupportedScreen),
      NetworkLoadingComponent: injectIntl(NetworkLoadingScreen),
      NetworkNotFoundComponent: injectIntl(NetworkNotFoundScreen),
    };

    return (
       <DappRequirements
                {...dappRequirementsScreens}
                supportedNetworks={['4','42']}
                onProviderReceived={this.onProviderReceived}
                onNetworkIdReceived={this.onNetworkIdReceived}
                onAccountChange={this.onAccountChange}
              >
              // Render if all checks pass
      </DappRequirements>
    )
  }
}

Disable component in tests

global.bypassChecks = true;

Setup

npm install or yarn install

Testing

npm test or yarn test

Building

npm run build or yarn build

Builds the component for production to the dist folder. It correctly bundles React in production mode and optimizes the build for the best performance.