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

@xlabs-libs/wallet-aggregator-react

v0.0.1-alpha.16

Published

A library to help integrate the sdk to a react project.

Downloads

266

Readme

Wallet Aggregator - React

A library to help integrate the sdk to a react project.

Usage

The library supplies a WaletContextProvider which will hold information related to the available wallets and selected wallets, as well as the hooks needed to access and configure. While the context holds a "main" or "default" wallet which belongs to a single chain, it allows to keep track of wallets from multiple chains at the same time.

Wrap the application in the WalletContextProvider component. The provider expects a prop wallets which is either a map of Wallet arrays indexed by chain id or a function which builds such map.

Using a map:

import {
  CHAIN_ID_ALGORAND,
  CHAIN_ID_ETH,
  CHAIN_ID_SOME_CHAIN,
} from "@xlabs/wallet-aggregator-core";
import { MyAlgoWallet } from "@xlabs/wallet-aggregator-algorand";
import {
  MetamaskWallet,
  WalletConnectWallet,
} from "@xlabs/wallet-aggregator-algorand";
import { SomeWallet } from "@xlabs/wallet-aggregator-some-chain";
import { WalletContextProvider } from "@xlabs/wallet-aggregator-react";

type AvailableWalletsMap = Partial<Record<ChainId, Wallet[]>>;

const Main = () => {
  const wallets: AvailableWalletsMap = {
    [CHAIN_ID_ALGORAND]: [new MyAlgoWallet()],
    [CHAIN_ID_ETH]: [new MetamaskWallet(), new WalletConnectWallet()],
  };

  return (
    <WalletContextProvider wallets={wallets}>
      <App />
    </WalletContextProvider>
  );
};

Using a function:

import {
  CHAIN_ID_ALGORAND,
  CHAIN_ID_ETH,
  CHAIN_ID_SOME_CHAIN,
} from "@xlabs/wallet-aggregator-core";
import { MyAlgoWallet } from "@xlabs/wallet-aggregator-algorand";
import {
  MetamaskWallet,
  WalletConnectWallet,
} from "@xlabs/wallet-aggregator-algorand";
import { SomeWallet } from "@xlabs/wallet-aggregator-some-chain";
import { WalletContextProvider } from "@xlabs/wallet-aggregator-react";

type AvailableWalletsMap = Partial<Record<ChainId, Wallet[]>>;

const Main = () => {
  const walletsBuilder = (): Promise<AvailableWalletsMap> => {
    const someChainParams = await fetchSomeChainParams();

    return {
      [CHAIN_ID_ALGORAND]: [new MyAlgoWallet()],
      [CHAIN_ID_ETH]: [new MetamaskWallet(), new WalletConnectWallet()],
      [CHAIN_ID_SOME_CHAIN]: [new SomeWallet(someChainParams)],
    };
  };

  return (
    <WalletContextProvider wallets={walletsBuilder}>
      <App />
    </WalletContextProvider>
  );
};

Hooks

A set of react hooks are supplied. These are:

// Retrieve the current wallet, returns undefined if not set
const wallet: Wallet | undefined = useWallet();

// Retrieve the wallet from a given chain, returns undefined if not set
const walletFromChain: Wallet | undefined = useWalletFromChain(chainId);
// Retrieve all available wallets for a given chain
const walletsForChain = useWalletsForChain(chainId);

// Retrieve all available Wallets
const allWallets: AvailableWalletsMap = useAvailableWallets();

// Retrieve all available chains
const chains: ChainId[] = useAvailableChains();

// Returns a function used to set the current wallet
const changeWallet = useChangeWallet();
const wallet: Wallet = new MyWallet();
changeWallet(wallet);

// Returns a function used to unset the wallet from a given chain
// If the removed wallet is the "default" or "current" wallet, it
// selects the next available wallet to be the new default
const unsetWalletFromChain = useUnsetWalletFromChain();
unsetWalletFromChain(chainId);