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

@talismn/connect-wallets

v1.2.8

Published

This package provides the building blocks for wallet connection UIs.

Downloads

2,363

Readme

@talismn/connect-wallets

This package provides the building blocks for wallet connection UIs.

Dapps currently use the @polkadot/extension-dapp package with web3Enable.

While it is a great way to enable all wallets at once, it does cause multiple unnecessary wallet extension popups.

This is not a problem when it was just Polkadot.js extension. But now with Talisman and possibly some other wallet extensions coming in, the multiple popups is not desirable.

Furthermore, most use cases, one wallet is selected (and enabled) at one time.

@talismn/connect-wallets aims to solve this issue.

Setup:

# Using npm
npm install --save @talismn/connect-wallets
# Using bun
bun add @talismn/connect-wallets
# Using pnpm
pnpm add @talismn/connect-wallets
# Using yarn
yarn add @talismn/connect-wallets

Quick Start:

Wallet Selector UI

import { getWallets } from '@talismn/connect-wallets';

const DAPP_NAME = /* Get Dapp name */

// ...

const MyWalletSelector = () => {
  const supportedWallets: Wallet[] = getWallets();
  return (
    <div>
      {supportedWallets.map((wallet: Wallet) => {
        <button
          key={wallet.extensionName}
          onClick={async () => {
            try {
              await wallet.enable(DAPP_NAME);
              const unsubscribe = await wallet.subscribeAccounts((accounts: WalletAccount[]) => {
                // Save accounts...
                // Also save the selected wallet name as well...
              });
            } catch (err) {
              // Handle error. Refer to `packages/connect-wallets/src/lib/errors`
            }
          }}
        >
          Connect to {wallet.title}
        </button>
      })}
    <div>
  );
}

Example: Signing a message

try {
  // NOTE: If `account` object is not handy, then use `getWalletBySource` to get the wallet then the signer.
  const signer = account.wallet.signer

  // NOTE: This line will trigger the extension popup
  const { signature } = await signer.signRaw({
    type: 'payload',
    data: 'Some data to sign...',
    address: account.address,
  })
} catch (err) {
  // Handle error...
}

Functions

getWallets(): Wallet[]

Retrieves all the supported wallets.

getWalletBySource(source: string): Wallet

Retrieves the wallet by extension name (source). Useful if account: WalletAccount object is not available.

wallet.enable(dappName)

Needs to be called first before subscribeAccounts. Connects to the wallet extension.

This will trigger the extension to popup if it's the first time being enabled.

wallet.getAccounts(anyType?: boolean): Promise<WalletAccount[]>

Get wallet's accounts.

wallet.subscribeAccounts(callback): UnsubscribeFn

Subscribe to the wallet's accounts.

NOTE: Call the returned unsubscribe function on unmount.

wallet.extension

This is the main object that Dapp developers will need to interface.

Refer to the appropriate documentation on what the object has to offer.

Example in BaseDotsamaWallet.extension().

wallet.signer

This is for convenience and is derived from the wallet.extension.

Interfaces

Refer to packages/connect-wallets/src/types.ts.

Contributing new wallets

  1. Add wallet under packages/connect-wallets/src/lib/. (i.e. packages/connect-wallets/src/lib/foo-wallet/index.ts)
  2. Add a class which implements Wallet. (i.e. export class FooWallet implements Wallet)
  3. Add the wallet instance in supportedWallets array in packages/connect-wallets/src/lib/wallets.ts.
  4. IMPORTANT: The logo should not exceed 10KB (will be inlined)

NOTE: There may be 2 or more wallets that share a common wallet interface. It is recommended to create a base class in this case.

Refer to BaseDotsamaWallet for an example base class and its derived classes.