# @talisman-connect/wallets

> This package provides the building blocks for wallet connection UIs.

Latest version **1.1.3** (published 2022-03-15) · GPL-3.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @talisman-connect/wallets
pnpm add @talisman-connect/wallets
yarn add @talisman-connect/wallets
bun add @talisman-connect/wallets
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2022-03-15 |
| First published | 2022-02-03 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 129.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | juliuscarvajal |

## Links

- npm: https://www.npmjs.com/package/@talisman-connect/wallets
- Homepage: https://github.com/TalismanSociety/talisman-connect/tree/master/libs/wallets#talisman-connectwallets
- npm.io page: https://npm.io/package/@talisman-connect/wallets

## Dependencies (3)

- [@polkadot/api](https://npm.io/package/@polkadot/api.md) ^7.9.1
- [@polkadot/extension-dapp](https://npm.io/package/@polkadot/extension-dapp.md) ^0.42.7
- [@polkadot/extension-inject](https://npm.io/package/@polkadot/extension-inject.md) ^0.42.9

## Recent versions

- 1.1.3 (latest) — 2022-03-15
- 1.1.2 — 2022-02-27
- 1.1.1 — 2022-02-21
- 1.1.0 — 2022-02-16
- 1.0.0 — 2022-02-15
- 0.0.13 — 2022-02-10
- 0.0.12 — 2022-02-09
- 0.0.11 — 2022-02-07
- 0.0.10 — 2022-02-07
- 0.0.8 — 2022-02-07
- 0.0.7 — 2022-02-07
- 0.0.6 — 2022-02-07
- 0.0.5 — 2022-02-06
- 0.0.4 — 2022-02-04
- 0.0.3 — 2022-02-04
- … 2 more at https://npm.io/package/@talisman-connect/wallets/versions

## README

# @talisman-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.

`@talisman-connect/wallets` aims to solve this issue.

## Setup:

```
npm i --save @talisman-connect/wallets
```

## Quick Start:

### Wallet Selector UI

```tsx
import { getWallets } from '@talisman-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 `libs/wallets/src/lib/errors`
            }
          }}
        >
          Connect to {wallet.title}
        </button>
      })}
    <div>
  );
}
```

### Example: Signing a message

```tsx
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.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 `libs/wallets/src/types.ts`.

## Contributing new wallets

1. Add wallet under `/src/lib`. (i.e. `/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 `libs/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.

## Running unit tests

Run `nx test wallets` to execute the unit tests via [Jest](https://jestjs.io).

---
_Source: https://npm.io/package/@talisman-connect/wallets · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
