1.0.1 • Published 5 months ago

@manifoldxyz/frontend-provider-utils v1.0.1

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

frontend-provider-utils

A tiny utility for detecting the Manifold Ethereum provider, an injected window.ManifoldEthereumProvider object

Installation

Install this package using npm:

npm install @manifoldxyz/frontend-provider-utils

Or using yarn:

yarn add @manifoldxyz/frontend-provider-utils

Usage

Node.js

import detectManifoldEthereumProvider from '@manifoldxyz/frontend-provider-utils'

const manifoldProvider = await detectManifoldEthereumProvider()

if (provider) {

  console.log('Manifold Ethereum successfully detected!')

  // From now on, this should always be true:
  // provider === window.ManifoldEthereumProvider

  const oAuthToken = await manifoldProvider.getOAuth({
    appName,
    clientId,
    grantType,
    strictAuth
  });
} else {
  // if the provider is not detected, detectManifoldEthereumProvider resolves to null
}

Options

The exported function takes an optional options object. If invalid options are provided, an error will be thrown. All options have default values.

options.silent Type: boolean

Default: false

Whether error messages should be logged to the console. Does not affect errors thrown due to invalid options.

options.timeout Type: number

Default: 3000

How many milliseconds to wait for asynchronously injected manifold provider.

Advanced Topics

The Manifold Ethereum Provider is synchronously injected.

To notify sites of the injection, Manifold Ethereum Provider dispatches the 'manifold-ethereum-initialized' event on window immediately after the provider has been set as window.ManifoldEthereumProvider. This package relies on that event to detect the injection.

Overwriting or Modifying window.ManifoldEthereumProvider.

The detected provider object returned by this package will strictly equal (===) window.ManifoldEthereumProvider for the entire page lifecycle, unless window.ManifoldEthereumProvider is overwritten. Consumers should never overwrite window.ManifoldEthereumProvider or attempt to modify the provider object.

Contributing

Contributions are welcome. Please open an issue or submit a pull request on our GitHub repository.

1.1.0

5 months ago

1.0.1

9 months ago

1.0.1-beta.1

11 months ago

1.0.0

12 months ago

1.0.0-beta.3

12 months ago

1.0.0-beta.2

12 months ago

1.0.0-beta.1

12 months ago