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

@whitelabel-solutions/wallet-connector

v2.1.6

Published

A Web3 Ethereum provider solution for multiple Wallets

Downloads

23

Readme

Commitizen friendly semantic-release: angular

Introduction

@whitelabel-solutions/wallet-connector is an easy-to-use library to support integration of the most common providers for wallet connection to your dApp. Following features are currently available:

  • Connect and Disconnect to a multitude of providers
  • Handle error, loading and connect states
  • Specify a limited number of allowed chains
  • Specify a desired chain and trigger a switch/add chain request
  • Switch Chain
  • Add Chain
  • Store the current provider in local storage to facilitate sign-in for returning users
  • Usage of peer dependencies gives the opportunity to use the latest version of a provider package

The library is framework-agnostic, meaning it is developed entirely in Typescript without any reliance on frameworks like React or Vue. However, it may of course be used in React or Vue.

Available connectors

More to come soon!

| Connector | Docs | |-------------------------------------------------|-------------------------------------------------------------------------------------------------| | MetaMask | www.docs.metamask.io/guide/ | | Coinbase Wallet | www.docs.cloud.coinbase.com/wallet-sdk/docs | | Wallet Connect | www.docs.walletconnect.com |

Usage

  1. Install @whitelabel-solutions/wallet-connector npm package
npm install --save @whitelabel-solutions/wallet-connector

# OR

yarn add @whitelabel-solutions/wallet-connector
  1. Install only the necessary provider dependencies
# E.g. for MetaMask:
npm install --save @metamask/detect-provider

# OR

yarn add @metamask/detect-provider

# For all your providers. 
# Documentation on which dependencies to install for which provider will soon be added. In the meantime, please refer to the specific provider documentation.
  1. Setup Connectors
import {
    MetaMask,
    WalletConnect,
    WalletLink,
} from "@whitelabel-solutions/wallet-connector"
import detectProvider from "@metamask/detect-provider"
import WalletConnectProvider from '@walletconnect/web3-provider';
import {CoinbaseWalletSDK} from "@coinbase/wallet-sdk";

const appName = "appName"
const infuraId = "infuraId"
const chainId = 1

const connectors = [
    MetaMask({detectProvider}),
    WalletConnect({WalletConnectProvider, options: {infuraId}}),
    CoinbaseWallet({
        CoinbaseWalletSDK,
        options: {
            appName,
            rpcUrl: "https://mainnet.infura.io/v3/" + infuraId,
            chainId
        },
    })
]
  1. Initialize Connection
import { Connection } from "@whitelabel-solutions/wallet-connector"

const options = {
    allowedChainIds: [1, 3],
    desiredChainOrChainId: 1,
}

const connection = new Connection(options, connectors) // connectors from step 2

connection.loadFromCache() // use this to load the provider from local storage
  1. Then you can add @whitelabel-solutions/wallet-connector as follows (e.g. in Vue)
<template>
    <ul>
        <li v-for="connector of connection.connectors" :key="connector.id">
            <button @click.prevent="connector.connect">
                {{ connector.name }}
            </button>
        </li>
    </ul>
</template>

You can find working examples in the example folder.

Options

The individual connectors are configured according to their respective package documentation. To configure the connection instance, the following options are available:

type ConnectionOptions = {
    allowedChainIds?: number[] | null // default: null
    desiredChainOrChainId?: number | AddEthereumChainParameter | null // default: null
    cache?: {
        enabled?: boolean // default: true
        key?: string // default: 'cached-connector'
    }
}
  • If allowedChainIds option is set, the connector will validate if the user is connected to a matching chain.
  • If desiredChainOrChainId option is set, the connector will validate if the user is connected to the matching chain and instantiate a chain switch if not. If a chain switch fails because it's unknown to the provider and the option is passed as an object, the connector will try to add the chain to the wallet.

Connection properties

interface IConnection {
    options: ConnectionOptions
    connectors: Record<string, IConnectorWrapper>
    activeConnectors: Record<string, IConnectorWrapper>
    activeConnector: IConnectorWrapper | undefined
    loadFromCache: () => Promise<IConnectorWrapper>
}

Connector properties

interface IConnectorWrapper {
    id: string
    name: string
    logo: string
    provider: IExternalProvider | undefined
    accounts: string[] | undefined
    chainId: number | undefined
    selectedAccount: string | undefined
    error: Error | undefined
    loading: boolean
    connected: boolean
    connect: () => Promise<IConnectorWrapper>
    disconnect: () => void
}

License

Distributed under the MIT License. See LICENSE.txt for more information.