Skip to content

useExtensions

A hook that interacts with extensions and exposes their status.

source

Usage

Extensions data can be accessed with the useExtensions hook in any component wrapped with ExtensionsProvider:

import { useExtensions } from '@w3ux/react-connect-kit';
 
const extensions = useExtensions();

Syncing Extensions

Web3 extensions are injected into the window.injectedWeb3 object, which is an asynchronous process that happens when the window loads. For this reason, ExtensionsProvider also provides a gettingExtensions boolean value, that signals whether the initial check for injectedWeb3 is underway.

gettingExtensions will initially be true, and updated to false once window.injectedWeb3 is present, or if injectedWeb3 is not found after a 5 second timeout.

Interface

gettingExtensions

boolean

Returns a boolean reflecting whether window.injectedWeb3 is being checked.

extensionsStatus

Record<string, Extens`ionStatus>

A key value record of each extension and their status. Empty object by default until setExtensionStatus is called.

setExtensionStatus

(id: string, status: ExtensionStatus): void

A function that takes an extension id and status, and updates the extensionsStatus record. Accepts values of installed, not_authenticated and connected.

removeExtensionStatus

(id: string): void

Removes an extension from the extensionsStatus record. This should be called when the extension is not found / not installed.

extensionInstalled

(id: string): boolean

A function that takes an extension id checks whether the extension is installed.

extensionCanConnect

(id: string): boolean

Checks if the provided extension id can be connected to. Returns false if the extension is not installed or is not connected.