3.2.0 • Published 5 months ago

@sei-js/react v3.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@sei-js/react

A React helper library for @sei-js/core written in Typescript.

Tutorial

For an in depth tutorial, please see our documentation.

Installation

yarn add @sei-js/react

WalletProvider

The first step is to wrap your entire application in a Sei wallet provider and pass in a chainId, rest url, and rpc url.

<SeiWalletProvider
  chainConfiguration={{
    chainId: 'atlantic-2',
    restUrl: 'https://rest.atlantic-2.seinetwork.io/',
    rpcUrl: 'https://rpc.atlantic-2.seinetwork.io'
  }}>
      <YourApp />
</SeiWalletProvider>

Unofficial wallet providers

To connect to an unofficial wallet provider such as Keplr, simply define an object of type SeiWallet and use it anywhere in this package.

const CUSTOM_WALLET: SeiWallet = {
  getAccounts: async (chainId) => {
    const offlineSigner = await window?.['keplr']?.getOfflineSignerAuto(chainId);
    return offlineSigner?.getAccounts() || [];
  },
  connect: async (chainId) => await window?.['keplr']?.enable(chainId),
  disconnect: async (chainId) => await window?.['keplr']?.disable(chainId),
  getOfflineSigner: async (chainId) => window?.['keplr']?.getOfflineSignerAuto(chainId),
  getOfflineSignerAmino: async (chainId) => window?.['keplr']?.getOfflineSignerAmino(chainId),
  signArbitrary: async (chainId, signer, message) => window?.['keplr']?.signArbitrary(chainId, signer, message),
  verifyArbitrary: async (chainId, signingAddress, data, signature) => window?.['keplr']?.verifyArbitrary(chainId, signingAddress, data, signature),
  walletInfo: {
    windowKey: 'keplr',
    name: 'Keplr',
    website: 'https://www.keplr.app/download',
    icon: 'https://assets.website-files.com/63eb7ddf41cf5b1c8fdfbc74/63edd5d1a40b9a48841ac1d2_Keplr%20Logo.svg'
  },
  isMobileSupported: false
};

// Then pass this into <SeiWalletProvider /> if using React, or use it's functions if using node or another js library
<SeiWalletProvider wallets={['fin', 'compass', CUSTOM_WALLET]} autoconnect={CUSTOM_WALLET} />

Hooks

HookParams
useWallet---
useQueryClient(rpcAddress?: string)
useSigningClient(rpcAddress?: string)
useSeiCosmWasmClient---

useWallet

A hook to connect one of our supported wallets to your application.

import { useWallet } from '@sei-js/react';

const { offlineSigner, accounts, connectedWallet } = useWallet();

Return Values

PropertyTypeDescription
connectedWalletstring?The currently connected wallet
chainIdstringSei chain id
restUrlstringThe rest url associated with the connected wallet
rpcUrlstringThe rpc url associated with the connected wallet
offlineSignerobject?The offline signer associated with the connected wallet
accountsobject[]?The accounts associated with the connected wallet

useQueryClient

import { useQueryClient } from '@sei-js/react';

const { queryClient, isLoading } = useQueryClient();
PropertyTypeDescription
queryClientStargateSigningClient?A stargate signing client.
isLoadingbooleanBoolean value for when the initial loading is happening

useSigningClient

import { useSigningClient } from '@sei-js/react';

const { signingClient, isLoading } = useSigningClient();
PropertyTypeDescription
signingClientStargateSigningClient?A stargate signing client.
isLoadingbooleanBoolean value for when the initial loading is happening

useSeiCosmWasmClient

import { useSeiCosmWasmClient } from '@sei-js/react';

const { cosmWasmClient } = useSeiCosmWasmClient();
PropertyTypeDescription
cosmWasmClientCosmWasmClient?A cosm wasm client for smart contracts.

UI Components

This package contains two helpful UI components for connecting to a wallet provider.

\

This component renders a button that will open a modal to connect to a wallet provider.

import React from "react";
import {useWallet, WalletConnectButton} from "../lib";

const Component = () => {
  const { connectedWallet } = useWallet();

  return (
     <div>
         <WalletConnectButton />
         <p>Connected wallet: {connectedWallet?.walletInfo?.name || "---"}</p>
     </div>
  );
};

export default Component;
PropertyTypeDescription
walletsSeiWallet[]?A stargate signing client.
buttonClassNamestringA css class name for styling the button
primaryColorstringA hex value of the color you want to tint the text and icons with
secondaryColorstringA secondary hex value of the color you want to tint the text and icons with
backgroundColorstringA hex value of the color you want to use as a background

If your page has a on the page it can be opened programmatically by calling the hook "useSelectWallet"

useSelectWallet()

This hook allows you to programmatically open and close the wallet modal.

import React from "react";
import { useWallet, useSelectWallet } from "../lib";

const Component = () => {
  const { connectedWallet } = useWallet();
  const { openModal, closeModal } = useSelectWallet();

  return (
     <div>
         <button onClick={openModal}>Open Modal</button>
         <p>Connected wallet: {connectedWallet?.walletInfo?.name || "---"}</p>
      </div>
  );
};

export default Component;

Styling

This package uses Styled Components and allows you to override the theme with a primaryColor, secondaryColor, and backgroundColor to tint the text and icons.

import { ThemeProvider } from "styled-components";

// Define theme
export const theme = {
  primaryColor: '#121212',
  secondaryColor: '#8C8C8C',
  backgroundColor: '#F1F1F1'
};

// Wrap your app in the theme provider
<ThemeProvider theme={theme}>
  <YOUR_APP/>
</ThemeProvider>

Other helpful packages

  • @sei-js/core - TypeScript library containing helper functions for wallet connection, transaction sig ning, and RPC querying.
  • @sei-js/proto - TypeScript library for Sei protobufs generated using Telescope
2.0.3

10 months ago

2.0.2

10 months ago

2.0.5

10 months ago

2.0.4

10 months ago

3.2.0

5 months ago

3.1.1

7 months ago

3.1.0

7 months ago

3.0.4

8 months ago

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

9 months ago

3.0.5

7 months ago

3.0.0

9 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.3.3

12 months ago

1.3.2

12 months ago

1.3.1

12 months ago

1.2.0

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.3.0

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.3

1 year ago

1.0.49

1 year ago

1.0.52

1 year ago

1.0.19

2 years ago

1.0.39

2 years ago

1.0.17

2 years ago

1.0.38

2 years ago

1.0.16

2 years ago

1.0.44

1 year ago

1.0.22

2 years ago

1.0.43

1 year ago

1.0.21

2 years ago

1.0.42

2 years ago

1.0.20

2 years ago

1.0.41

2 years ago

1.0.48

1 year ago

1.0.26

2 years ago

1.0.47

1 year ago

1.0.25

2 years ago

1.0.46

1 year ago

1.0.24

2 years ago

1.0.45

1 year ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.15

2 years ago

1.0.36

2 years ago

1.0.14

2 years ago

1.0.35

2 years ago

1.0.13

2 years ago

1.0.34

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago