Reconnect

The provider comes with a reconnect action that establishes a new connection to WalletConnect (with an existing or stored session).

// Some where within your codebase...

const { actions } = useProvider();

const response = await actions.reconnect(session)

Input

This action requires the session to reconnect.

session: SessionTypes.Struct // WalletConnect Session

Return Type

The method will resolve if a connection is re-established by the user.

Promise<void>

Example usage:

// File: ./src/app/component.tsx
'use client';

import * as React from 'react';
import { useProvider } from './page';

export default function Component() {
  const { actions, session, accounts } = useProvider();

  const handleReconnect = async () => {
    const response = await actions.reconnect(session);
    if (response.error) throw response.error;
    // You have been connected using wallet connect.
    // Now you can start interacting with the XRP Ledger.
    // ...
  };

  return (
    <div>
      <button type="button" onClick={handleReconnect}>
        Reconnect
      </button>
      {session && (
        <div>
           <span>Successfully connected!</span>
              {accounts && accounts.map((account,index) => (
		<div key={index}>{account}</div>
	      )
            )}
        </div>
      )}
    </div>
  );
}

Last updated