2.5.2 • Published 2 years ago

@terra-dev/walletconnect v2.5.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

@terra-dev/walletconnect

API

types.ts

import { IClientMeta } from '@walletconnect/types';

// ---------------------------------------------
// session
// ---------------------------------------------
export enum WalletConnectSessionStatus {
  REQUESTED = 'REQUESTED',
  CONNECTED = 'CONNECTED',
  DISCONNECTED = 'DISCONNECTED',
}

export interface WalletConnectSessionRequested {
  status: WalletConnectSessionStatus.REQUESTED;
}

export interface WalletConnectSessionConnected {
  status: WalletConnectSessionStatus.CONNECTED;
  chainId: number;
  terraAddress: string;
  peerMeta: IClientMeta;
}

export interface WalletConnectSessionDisconnected {
  status: WalletConnectSessionStatus.DISCONNECTED;
}

export type WalletConnectSession =
  | WalletConnectSessionRequested
  | WalletConnectSessionConnected
  | WalletConnectSessionDisconnected;

// ---------------------------------------------
// tx
// ---------------------------------------------
export interface WalletConnectTxResult {
  height: number;
  raw_log: string;
  txhash: string;
}

connect.ts

export interface WalletConnectControllerOptions {
  /**
   * Configuration parameter that `new WalletConnect(connectorOpts)`
   *
   * @default
   * ```js
   * {
   *   bridge: 'https://bridge.walletconnect.org',
   *   qrcodeModal: new TerraWalletconnectQrcodeModal(),
   * }
   * ```
   */
  connectorOpts?: IWalletConnectOptions;
  /**
   * Configuration parameter that `new WalletConnect(_, pushServerOpts)`
   *
   * @default undefined
   */
  pushServerOpts?: IPushServerOptions;
}

export interface WalletConnectController {
  session: () => Observable<WalletConnectSession>;
  getLatestSession: () => WalletConnectSession;
  post: (tx: CreateTxOptions) => Promise<WalletConnectTxResult>;
  disconnect: () => void;
}

Usage

Connect

import {
  connectWallet,
  connectWalletIfSessionExists,
  WalletConnectController,
} from '@terra-money/terra-walletconnect';

// restore the session if the session is exists in the localStorage (e.g. browser reload...)
const controller: WalletConnectController | null =
  connectWalletIfSessionExists();

if (!controller) {
  // connect with interaction
  document.querySelector('button').addEventListener('click', () => {
    const controller: WalletConnectController = connectWallet();
  });
}

Functions

import {
  connectWallet,
  Session,
  WalletConnectController,
} from '@terra-money/terra-walletconnect';

const controller: WalletConnectController = connectWallet();

// watch session status
controller.session().subscribe((session: Session) => {
  // the session is one of SessionRequested | SessionConnected | SessionDisconnected
});

// get latest session status
controller.getLatestSession();

// transaction
const { txhash, height } =
  await controller.post(/* CreateTxOptions of terra.js */);

// disconnect session
controller.disconnect();
2.5.1-alpha.1

2 years ago

2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.3

2 years ago

2.5.0-alpha.1

2 years ago

2.4.0-alpha.3

3 years ago

2.4.0-alpha.2

3 years ago

2.4.0-alpha.1

3 years ago

2.3.0-alpha.1

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.1.0-alpha.4

3 years ago

2.1.0-alpha.3

3 years ago

2.1.0-alpha.2

3 years ago

2.1.0-alpha.1

3 years ago

2.0.0

3 years ago

2.0.0-alpha.2

3 years ago

1.4.0-alpha.3

3 years ago

2.0.0-alpha.1

3 years ago

1.4.0-alpha.1

3 years ago

1.2.4-alpha.1

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2-alpha.1

3 years ago

1.2.3-alpha.1

3 years ago

1.2.2

3 years ago

1.3.0-alpha.1

3 years ago

1.2.1

3 years ago

1.2.1-alpha.1

3 years ago

1.2.0

3 years ago

1.2.0-alpha.1

3 years ago

1.1.0

3 years ago

1.1.0-alpha.1

3 years ago

1.1.0-alpha.2

3 years ago

1.0.0

3 years ago

1.0.0-alpha.3

3 years ago

1.0.0-alpha.1

3 years ago

0.16.0-alpha.7

3 years ago

0.16.0-alpha.6

3 years ago

0.16.0-alpha.4

3 years ago

0.16.0-alpha.1

3 years ago

0.16.0-alpha.3

3 years ago

0.16.0-alpha.2

3 years ago

0.14.0

3 years ago

0.15.0

3 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.12.2

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.10.1

3 years ago

0.12.0

3 years ago

0.10.2

3 years ago

0.8.0

3 years ago

0.12.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago