New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@xlabs-libs/wallet-aggregator-react

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xlabs-libs/wallet-aggregator-react

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

  • 0.0.1-alpha.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31
decreased by-39.22%
Maintainers
4
Weekly downloads
 
Created
Source

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);

FAQs

Package last updated on 24 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc