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

@dcentralab/web3-wc-modal

v2.0.32

Published

UI for wallet connector

Downloads

487

Readme

Web3 Wallet Connector

CREATE-REACT-APP

To support hardware wallets in create-react-app you need to use react-app-rewired

const NodePolyfill = require("node-polyfill-webpack-plugin");

module.exports = function override(config, env) {
  console.log("override");
  config.plugins.push(new NodePolyfill());

  return config;
};

Instalation

npm install @dcentralab/web3-wc-modal

or

yarn add @dcentralab/web3-wc-modal

If you use webpack make sure that you have react alias in resolve section (https://webpack.js.org/configuration/resolve/#resolvealias)

Component must be mounted and rendered before you can use it

Getting started

import { Web3WalletModal } from "@dcentralab/web3-wc-modal";
import evmProviders from "@dcentralab/evm-providers";
import cardanoProviders from "@dcentralab/cardano-providers";
import mmProvider from "@dcentralab/wc-mm";
import { NetworkSwitcherContextProvider } from "@dcentralab/wc-network-switcher";

<NetworkSwitcherContextProvider networks={appNetworks}>
  <Web3WalletModal
    networkId // required. netwrokId where app should connect
    rpcUrl // required. rpcUrl where app should connect
    blockchainType // required. BlockchainType where app should connect
    // array of supported connectors
    supportedWallets={evmProviders} // for ethereum based wallets only
    supportedWallets={[mmProvider]} // for explicit set of wallets
    supportedWallets={[...evmProviders, ...cardanoProviders]} // for all supported wallets
    derivationPath // derivation path for HD wallets (ledzer and trezor)
    pendingTx // count of pending transactions
    onDisconnect // method that will be called when wallet dicsonnects
    onConnectError // method that will be called at any error during wallet connection
    onConnect // method that will be called when after wallet successfully connect
    onConnectRequest // method that will be called when wallet connection started
    onClick // additional method that will be called when user click on WalletButton
    showBalance // boolean to show or hide balance of connected wallet
    intl // react-intl
    autoConnect // boolean - flag that indicate should wallet connector reconnect when one of prop (rpcUrl, networkId, blockchainType) was changed
    modalRoot // div element for modal hosting
    disableProviderFirst // to disable network switch by provider
  />
</NetworkSwitcherContextProvider>;
import { walletHelpers } from "@dcentralab/web3-wc-modals";

// example of imerative usage
await walletHelpers.connectWallet(state.accountType, {
  rpcUrl: payload?.rpcUrl,
  networkId: payload?.networkId,
  ...(state.additions || {}),
});

Methods & Getters of walletHelpers

interface IMethods { openModal: () => void closeModal: (success?: boolean) => void connectWallet: (connectingWalletType: string, options?: IConnectionOptions) => Promise<IConnectionResult | void> toggleLedgerModal: (modalState: boolean) => void toggleTrezorModal: (modalState: boolean) => void getHWWalletAccounts: (connectingWalletType: string, opts: IGetHWAccounts) => Promise<string[]> disconnectWallet: (clearDerivationPath?: boolean) => void getBalance: (address: string) => Promise mounted: boolean }

  • openModal() - show connect wallets modal
  • closeModal(success?: boolean) - close wallets modal
  • connect(connectingWalletType: string, options?: IConnectionOptions) - connect wallet and return wallet provider on success
  • toggleLedgerModal(modalState: boolean) - open/close ledger modal
  • toggleTrezorModal(modalState: boolean) - open/close trezor modal
  • getHWWalletAccounts(connectingWalletType: string, opts: IGetHWAccounts) - get list of HD wallet addresses
  • disconnectWallet(clearDerivationPath?: boolean) - disconnect currently connected wallet
  • getBalance(address: string) - getBalance for address
  • mounted - boolean that indicates if component was properly rendered

Connection types

  • inPageProvider
  • ledger
  • trezor
  • walletConnect
  • portis
  • fortmatic
  • coinbase
  • binance
  • clover
  • nami
  • eternl
  • yoroi
export type TConnect = (
  connectingWalletType: string,
  options?: IConnectionOptions
) => void;
export type TDisconnect = (clearDerivationPath?: boolean) => void;

export interface IConnectionOptions {
  rpcUrl?: string;
  networkId?: number;
  derivationPath?: string;
  blockchainType?: BLOCKCHAIN_TYPE;
  connectionType?: TWalletType;
  onConnectStart?: () => void;
  savePath?: boolean;
  removeLSKey?: boolean;
  showModalOnError?: boolean;
  showToast?: (msg: string, duration?: number) => any;
  connectWallet?: TConnect;
  disconnectWallet?: TDisconnect;
  internal?: boolean;
}

export interface IGetHWAccounts {
  derivationPath: string;
  networkId?: number;
  accountsLength?: number;
  accountsOffset: number;
}

export interface IConnectionResult {
  provider: any;
  providerName?: string;
}

Colors

if you want to change color schema define CSS variables https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

  • --wallet-button-color
  • --wallet-button__hover-color
  • --wallet-text-color
  • --loader-circle
  • --ledger-error-text-color
  • --ledger-warning-text-color
  • --ledger-button-background
  • --ledger-button-hover-background
  • --ledger-derivation-border-color
  • --ledger-derivation-background
  • --ledger-derivation-text-color
  • --ledger-derivation-active-border-color
  • --ledger-derivation-active-background
  • --ledger-derivation-active-text-color
  • --overlay-color
  • --modal-body-color
  • --close-btn-color