# @voltz-protocol/react-web3-wallet

> Library that takes care of connecting to different web3 wallets.

Latest version **2.15.1** (published 2024-03-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @voltz-protocol/react-web3-wallet
pnpm add @voltz-protocol/react-web3-wallet
yarn add @voltz-protocol/react-web3-wallet
bun add @voltz-protocol/react-web3-wallet
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.15.1 |
| Published | 2024-03-12 |
| First published | 2023-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16.17.0 |
| Dependencies | 0 |
| Unpacked size | 74.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ssbarbee |
| Maintainers | ioanaroceanu, aniculae, 0xzenus, filip-voltz, voltzprotocol |

## Links

- npm: https://www.npmjs.com/package/@voltz-protocol/react-web3-wallet
- Repository: https://github.com/Voltz-Protocol/react-web3-wallet
- Homepage: https://github.com/Voltz-Protocol/react-web3-wallet#readme
- Issues: https://github.com/Voltz-Protocol/react-web3-wallet/issues
- npm.io page: https://npm.io/package/@voltz-protocol/react-web3-wallet

## Recent versions

- 2.15.1 (latest) — 2024-03-12
- 2.15.0 — 2024-03-11
- 2.14.0 — 2024-03-10
- 2.13.0 — 2024-03-09
- 2.12.1 — 2024-03-08
- 2.12.0 — 2024-03-07
- 2.11.0 — 2024-02-26
- 2.10.0 — 2024-02-22
- 2.9.0 — 2024-02-22
- 2.8.0 — 2024-02-18
- 2.7.2 — 2024-02-15
- 2.7.1 — 2024-02-15
- 2.7.0 — 2024-02-08
- 2.6.0 — 2024-02-02
- 2.5.0 — 2024-02-01
- … 18 more at https://npm.io/package/@voltz-protocol/react-web3-wallet/versions

## README

# react-web3-wallet

<p align="center">
  <a href="https://app.voltz.xyz/">
    <picture>
      <img src="./docs/logo.png" alt="Voltz" width="128" />
    </picture>
  </a>
</p>

<p align="center">Powering Voltz UI and beyond!!!</p>

<p align="center">
  <img src="https://badgen.net/github/tag/Voltz-Protocol/react-web3-wallet" alt="Tag" />
  <img src="https://badgen.net/github/checks/Voltz-Protocol/react-web3-wallet/main" alt="Checks" />
  <img src="https://badgen.net/github/last-commit/Voltz-Protocol/react-web3-wallet/main" alt="Checks" />
</p>

<p align="center">
Library that takes care of connecting to different web3 wallets.
</p>

<br />

| Statements                  | Branches                | Functions                 | Lines             |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](https://img.shields.io/badge/statements-40.56%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-51.16%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-41.37%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-39%25-red.svg?style=flat) |

# Installation

1. Run `yarn`

# Run

1. Run `yarn storybook`

# Contributing

## Branching model

In the UI world you should branch off `main` when building a feature.
So just go on `main`, pull latest and then branch out of it.
Create your PR against `main`.

Branch naming is quite standard, we tried to duplicate what we have done for
the committing messages, following standard commit message format: [https://www.conventionalcommits.org/en/v1.0.0/].

Branch names can start with the prefixes found in the regex under '.husky/pre-commit'.

### Short summary:

**DEVELOPING**
* create a branch from `main`, follow the naming convention for a branch
* wait for approval, resolve comments and make sure you have a green build
* merge to `main` using **Rebase and merge**

## Tools

Helpful tools to install to improve your development life!

* [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)

# How to Connect
## Prerequisites

Make sure the package and peerDependencies are installed:

```shell
yarn add @voltz-protocol/react-web3-wallet viem wagmi
```

## Step 1: Configuring Connectors

First, we create a new config set up with the Injected (i.e. MetaMask), WalletConnect, and Coinbase Wallet connectors.

```tsx
import { setup, WalletConfig } from '@voltz-protocol/react-web3-wallet';

// Set up wagmi config
const config = setup({
    supportedChains: ['mainnet', 'goerli'],
    supportedWallets: [{
        type: 'metamask',
    }, {
        type: 'wallet-connect',
        projectId: process.env.WALLET_CONNECT_PROJECT_ID,
    }, {
        type: 'coinbase',
        appName: process.env.COINBASE_APP_NAME,
    },],
});

// Pass config to React Context Provider
function App() {
    return (
        <WalletConfig config={config}>
            <Profile />
        </WalletConfig>
    )
}
```


## Step 2: Connect account and show it

Let's create the needed `Profile` component. Note this component uses `brokoli-ui` components so make sure you have a `ThemeProvider` 
wrapping the `brokoli-ui` components

```tsx
import { Button, ThemeProvider, Typography } from 'brokoli-ui';
import React, { useMemo } from 'react';
import { useWalletAccount, useWalletConnect } from '@voltz-protocol/react-web3-wallet';

// Pass config to React Context Provider
function Profile() {
    const { connect, connectors, error } = useWalletConnect();
    const { disconnect, ensName, ensAvatar, address, connector, isConnected } = useWalletAccount();
    if (isConnected) {
        return (
            <div>
                <img alt="ENS Avatar" src={ensAvatar!} />
                <Typography colorToken="white100" typographyToken="primaryBodyMediumRegular">
                    {ensName ? `${ensName} (${address!})` : address}
                </Typography>
                <Typography colorToken="white100" typographyToken="primaryBodySmallRegular">
                    Connected to {connector?.name}{' '}
                </Typography>
                <Button variant="secondary" onClick={disconnect}>
                    Disconnect
                </Button>
            </div>
        );
    }

    return (
        <div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
            {connectors.map((c) => (
                <Button
                    key={c.id}
                    bottomLeftText={error ? error.message : ''}
                    bottomLeftTextColorToken="error100"
                    disabled={c.disabled}
                    variant="primary"
                    onClick={() => connect(c.id)}
                >
                    {c.name}
                    {c.connecting && ' (connecting)'}
                </Button>
            ))}
        </div>
    );
}
```

---
_Source: https://npm.io/package/@voltz-protocol/react-web3-wallet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
