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/wc-network-switcher

v2.0.34

Published

## Instalation

Downloads

385

Readme

Networks icons

Instalation

npm install @dcentralab/wc-network-switcher

or

yarn add @dcentralab/wc-network-switcher

Getting started

Network switcher provides a way for handling app network switching (both evm and cardano) chains.

Exports

{
  NetworkIcon
  NetworksDropdown,
  INetworkSwitcher,
  NetworkSwitcher,
  NetworkSwitcherContext,
  NetworkSwitcherContextProvider,
}

NetworkIcon

will render the passed network object icon by prop chainInfo which is type of INetworkOption.

this code snippet will render the current selected chain icon

import {
  NetworkIcon,
  NetworkSwitcherContext,
} from "@dcentralab/wc-network-switcher";

const { networkInfo } = useContext(NetworkSwitcherContext);
<NetworkIcon chainInfo={networkInfo} />;

NetworksDropdown

will render a list of networks staked over each other and highlight on the selected one.

it's internally used in NetworkSwitcher

import {
  NetworkIcon,
  NetworkSwitcherContext,
} from "@dcentralab/wc-network-switcher";

function NetworkSwitcher({ children }: INetworkSwitcher) {
  const { networksList } = useContext(NetworkSwitcherContext);
  return(
    <InlineModal
      onToggle={setDropdownOpened}
      closeOnContentClick
      content={<NetworksDropdown />}
    >
      {children}
    </InlineModal>)

NetworkSwitcherContextProvider

App should be wrapped with NetworkSwitcherContextProvider and used networks will be passed to it.

import { NetworkSwitcherContextProvider } from "@dcentralab/wc-network-switcher";

<NetworkSwitcherContextProvider networks={appNetworks}>
  <App />
</NetworkSwitcherContextProvider>;

NetworkSwitcher

the main UI component for switching network. located in header and been added to duf header beside the wallet connect component

Note: it's hidden on mobile

import { NetworkSwitcher } from "@dcentralab/wc-network-switcher";

<div className="duf-header-wallet-container">
  <NetworkSwitcher />
  {walletComponent}
  <ContextMenu links={menuLinks} rtl profileImage={profileImage} />
</div>;

Interfaces

import { BLOCKCHAIN_TYPE, TWalletType } from "@dcentralab/common";
import { ReactNode } from "react";
import { IMessage, IValues } from "../formatMessage";

export interface IIntl {
  formatMessage: (msg: IMessage, values?: IValues) => string;
}

export interface INetwork {
  rpcUrl: string;
  networkId: number;
  derivationPath?: string;
  blockchainType: BLOCKCHAIN_TYPE;
}

export interface IWallet {
  type: TWalletType;
  blockchainType: BLOCKCHAIN_TYPE;
  mobile?: boolean;
  hwWallet?: boolean;
}
export interface INetworkOption extends INetwork {
  Icon?: JSX.Element | string;
  logo?: JSX.Element | string;
  title?: string;
  chainName?: string;
  explorerUrl?: string;
}

export interface IContextState {
  account: string;
  connectingWalletType: TWalletType | null;
  connectedWalletType: TWalletType | null;
  accountType: string;
  connectionType: string | null;
  connectingWallet: boolean;
  connectionError: string;
  isModalOpen: boolean;
  supportedWallets: IWallet[];
  lsKey?: string;
}

export interface INetworkSwitcherContextProps {
  children: ReactNode;
  networks?: INetworkOption[];
  defaultChainId?: number;
  defaultBlockchainType?: BLOCKCHAIN_TYPE;
  useStoredNetId?: boolean; // pass to store netwotkId and blockchainType in localstorage automaticly
  onNetworkChange?: (networkInfo?: INetworkOption) => void;
  enableSearch?: boolean; // enable search input
}

export interface IHDWalletProps {
  afterConnect: () => void;
}