1.0.2 • Published 4 days ago

@civic/solana-gateway-react v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
4 days ago

Gateway React Component

Overview

This purpose of this library is to provide an easy way to request a Gateway Token from a decentralised Application (dApp).

Getting started

1. Install the component

npm i @civic/solana-gateway-react

or

yarn add @civic/solana-gateway-react

2. Include the gateway context

Surround any code that needs access to the gateway token with:

import { GatewayProvider } from "@civic/solana-gateway-react";

<GatewayProvider
  wallet={wallet}
  gatekeeperNetwork={gatekeeperNetwork}>
</GatewayProvider>

where:

  • wallet contains publicKey and signTransaction (see below)
  • gatekeeperNetwork is a Solana PublicKey provided by the dApp, orderbook or market instance on-chain.

3. Accessing or requesting the gateway token

The component will automatically look for a gateway token on chain. To access it once created:

import { useGateway } from "@civic/solana-gateway-react";

const { gatewayToken } = useGateway()

If the wallet does not have a gateway token, request it using requestGatewayToken:

const { requestGatewayToken } = useGateway()

For example, by connecting it to a button component:

<button onclick={requestGatewayToken}>Validate your wallet</button> 

Advanced Usage

The example below shows an example GatewayStatus component that will update, and show the token address, once present.

import React from 'react';
import logo from './logo.png';
import {GatewayProvider, useGateway, GatewayStatus} from "@civic/solana-gateway-react";

function GatewayStatus() {
  const { wallet } = useWallet(); // provided by your dApp
  const { status, requestGatewayToken, gatewayToken } = useGateway();

  return (
    <div>
      <h3>Request Status: { GatewayStatus[status] }</h3>
      { gatewayToken && <h4>GatewayToken: {gatewayToken.publicKey.toBase58()}</h4>}
      <button onClick={requestGatewayToken}>Request Gateway Token</button>
    </div>
  );
}

// use it in your app
function MyGatewayAwareUI() {
  const { wallet } = useWallet(); // provided by your dApp
  const { market } = useMarket(); // provided by your dApp

  return (
    <GatewayProvider wallet={wallet} gatekeeperNetwork={market.gatekeeperNetwork}>
      <GatewayStatus/>
    </GatewayProvider>
  )
}

API Documentation

GatewayProvider

The GatewayProvider is a React component that gives children access to the GatewayContext through the useGateway function.

This component holds the state for a given gateway token or gateway token request.

export type GatewayProviderProps = {
  wallet: WalletAdapter | undefined | null, // the wallet connected to the dApp, can be null initially pre-user wallet connection
  gatekeeperNetwork: PublicKey | undefined, // the gatekeeper network public key address
  stage?: string, // optionally set Civic gatekeeper stage (testing only), defaults to 'prod'
  clusterUrl?: string // optionally pass a Solana cluster URL, defaults to solana mainnet
  wrapper?: React.FC<WrapperProps>; // a react element that the dApp can wrap the iframe in to allow custom dApp styling
  logo?: string, // optional url of your logo that will be shown, if set, during verification
  statusPollingFrequencyMS?: number // how often the component should poll the gatekeeper for status
}

GatewayStatus

The GatewayStatus is an enum that reveals the state of the requested Gateway Token.

export enum GatewayStatus {
  UNKNOWN,       // the wallet or gatekeeper network is not set
  CHECKING,      // the blockchain is being queried to find an existing gateway token
  NOT_REQUESTED, // then token has not been requested
  COLLECTING_USER_INFORMATION,   // the token request is in progress (the wallet owner is undergoing KYC)
  IN_REVIEW,     // the token has been requested and civic gatekeeper is reviewing the request
  FAILED,        // an error occurred on issuance of the token
  REJECTED,       // the token issuance request was rejected
  REVOKED,        // the token has been revoked
  FROZEN,         // the token has been frozen
  EXPIRED,        // the token expiry has passed - refresh is needed (will happen automatically)
  ACTIVE,         // the token has been issued successfully and is in an active state
  ERROR,          // something went wrong
}

WalletAdapter

The wallet passed to the GatewayProvider must implement the WalletAdapter interface by providing a publicKey (this will be linked with the GatewayToken), and a 'sign' function to prove wallet ownership:

export interface WalletAdapter {
  publicKey: PublicKey;
  signTransaction: (transaction: Transaction) => Promise<Transaction>;
}

useGateway

Any component wrapped by GatewayProvider can access the state and useful functions of the GatewayProvider through this function.

Returns the current context values for the GatewayContext by exposing the following properties.

export type GatewayProps = {
  requestGatewayToken: () => Promise<void>, // starts off gateway token process
  gatewayStatus: GatewayStatus, // normally a value from a React hook state, defaults to GatewayStatus.UNKNOWN
  gatewayToken?: GatewayToken, // the current GatewayToken used in the dApp
  stage?: string, // optionally set Civic gatekeeper stage (testing only), defaults to 'prod'
  clusterUrl?: string, // optionally pass a Solana cluster URL, defaults to solana mainnet
  statusPollingFrequencyMS?: number // how often the component should poll the gatekeeper for status
  complianceSrcUrl?: string // the compliance URL in use - set internally via stage
}

const gatewayProps: GatewayProps = useGateway();

Wrapper

You can customize how the verification flow is displayed by providing a custom wrapper.

...
const customWrapperStyle: CSS.Properties = {
  backgroundColor: 'rgba(0,0,0,1)',
  position: 'fixed',
  zIndex: 999,
  width: '100%',
  height: '100%',
  overflow: 'auto',
  paddingTop: '5%'
}

const customWrapperContentStyle: CSS.Properties = {
  backgroundColor: '#fefefe',
  margin: 'auto',
  width: '90%', 
  position: 'relative',
}

export const CustomWrapper: React.FC = ({ children = null }) => {
  return (
    <div style={customWrapperStyle}>
      <div style={customWrapperContentStyle}>
        <img style={{ maxWidth: '20%' }} src={logo} className="app-logo" alt="logo"/>
        {children}
      </div>
    </div>
  )
}

Contributing

Building the project and running the sample app:

yarn start

Runs the app in the development mode.\ Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.\ You will also see any lint errors in the console.

yarn test

Launches the test runner in the interactive watch mode.\ See the section about running tests for more information.

yarn build

Builds the app for production to the build folder.\ It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\ Your app is ready to be deployed!

1.0.3-beta.2

4 days ago

1.0.3-beta.1

8 days ago

1.0.3-beta.0

10 days ago

1.0.3-alpha.1

11 days ago

1.0.3-alpha.0

22 days ago

1.0.2

29 days ago

1.0.1-beta.0

30 days ago

1.0.1

30 days ago

1.0.0

1 month ago

1.0.0-beta.2

1 month ago

1.0.0-beta.0

1 month ago

1.0.0-beta.1

1 month ago

1.0.0-alpha.2

1 month ago

1.0.0-alpha.1

1 month ago

1.0.0-alpha.0

1 month ago

0.17.0-beta.0

1 month ago

0.17.0

1 month ago

0.16.13-beta.0

1 month ago

0.16.13

1 month ago

0.16.12

1 month ago

0.16.12-beta.0

1 month ago

0.16.11

2 months ago

0.16.11-alpha.0

2 months ago

0.16.10-beta.2

3 months ago

0.16.10-beta.1

3 months ago

0.16.10

3 months ago

0.16.10-beta.0

3 months ago

0.16.9

3 months ago

0.16.9-beta.4

3 months ago

0.16.9-beta.3

3 months ago

0.16.9-beta.2

3 months ago

0.16.9-beta.1

4 months ago

0.16.9-beta.0

4 months ago

0.16.6

5 months ago

0.16.7

5 months ago

0.16.8

4 months ago

0.16.8-beta.0

4 months ago

0.16.7-beta.0

5 months ago

0.16.6-beta.0

5 months ago

0.14.0-beta.1

11 months ago

0.14.0-beta.2

10 months ago

0.14.0-react18

11 months ago

0.16.0-beta.1

9 months ago

0.16.0-beta.3

9 months ago

0.15.0

10 months ago

0.16.0-beta.2

9 months ago

0.16.0-beta.5

9 months ago

0.16.0-beta.4

9 months ago

0.16.3

8 months ago

0.16.4

7 months ago

0.16.5

6 months ago

0.16.0

9 months ago

0.16.2

8 months ago

0.16.2-beta.4

8 months ago

0.16.4-beta.3

7 months ago

0.16.2-beta.3

8 months ago

0.16.4-beta.2

7 months ago

0.16.2-beta.2

8 months ago

0.16.2-beta.1

8 months ago

0.16.4-beta.4

7 months ago

0.16.2-beta.0

9 months ago

0.16.4-beta.1

7 months ago

0.16.4-beta.0

7 months ago

0.13.0-alpha.1

11 months ago

0.13.0

11 months ago

0.15.0-beta.0

10 months ago

0.15.0-beta.2

10 months ago

0.15.0-beta.1

10 months ago

0.14.0

10 months ago

0.16.1-beta.0

9 months ago

0.16.3-beta.1

8 months ago

0.16.3-beta.0

8 months ago

0.16.5-beta.2

6 months ago

0.16.5-beta.1

6 months ago

0.16.5-beta.0

6 months ago

0.12.4-beta.0

11 months ago

0.12.4-beta.1

11 months ago

0.12.4-beta.4

11 months ago

0.12.4-beta.5

11 months ago

0.12.4-beta.2

11 months ago

0.12.4-beta.3

11 months ago

0.12.3-alpha.0

12 months ago

0.12.3-alpha.1

12 months ago

0.12.1-beta.0

1 year ago

0.12.0-beta.1

1 year ago

0.12.0-beta.0

1 year ago

0.12.2-beta.1

1 year ago

0.12.2-beta.0

1 year ago

0.12.2-beta.2

12 months ago

0.12.0

1 year ago

0.12.1

1 year ago

0.12.2

12 months ago

0.12.3

12 months ago

0.11.9

1 year ago

0.11.9-beta.0

1 year ago

0.11.9-beta.1

1 year ago

0.11.4-beta.1

1 year ago

0.11.4-beta.2

1 year ago

0.11.4-beta.0

1 year ago

0.11.8-beta.1

1 year ago

0.11.5-alpha.0

1 year ago

0.11.8

1 year ago

0.11.4

1 year ago

0.11.5

1 year ago

0.11.6

1 year ago

0.11.7

1 year ago

0.11.7-beta.0

1 year ago

0.11.5-beta.1

1 year ago

0.11.7-beta.1

1 year ago

0.11.5-beta.0

1 year ago

0.11.7-beta.2

1 year ago

0.11.7-beta.3

1 year ago

0.11.7-beta.4

1 year ago

0.11.3

1 year ago

0.11.3-beta.3

1 year ago

0.11.2

1 year ago

0.11.3-beta.1

1 year ago

0.11.3-beta.2

1 year ago

0.11.2-alpha.0

1 year ago

0.11.2-alpha.1

1 year ago

0.11.2-beta.1

1 year ago

0.11.2-beta.2

1 year ago

0.11.0-alpha.0

1 year ago

0.11.0-alpha.2

1 year ago

0.11.0-alpha.1

1 year ago

0.11.0-alpha.3

1 year ago

0.11.2-beta.0

1 year ago

0.11.0

1 year ago

0.11.1

1 year ago

0.11.1-beta.0

1 year ago

0.10.0

2 years ago

0.10.0-beta.0

2 years ago

0.9.3-beta.0

2 years ago

0.9.1-beta.1

2 years ago

0.9.1-beta.2

2 years ago

0.9.1-beta.3

2 years ago

0.9.1-beta.5

2 years ago

0.9.1-beta.6

2 years ago

0.9.1-beta.7

2 years ago

0.9.1-beta.8

2 years ago

0.7.5-beta2

2 years ago

0.7.5-beta1

2 years ago

0.7.5-beta3

2 years ago

0.7.6-alpha.1

2 years ago

0.7.6-beta3

2 years ago

0.7.6-beta2

2 years ago

0.7.6-beta1

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.9.2-beta.1

2 years ago

0.9.2-beta.0

2 years ago

0.7.5-alpha1

2 years ago

0.7.5-alpha2

2 years ago

0.8.0

2 years ago

0.7.6-alpha2

2 years ago

0.10.0-alpha.1

2 years ago

0.10.0-alpha.0

2 years ago

0.9.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0-beta.1

2 years ago

0.9.0-beta.3

2 years ago

0.7.6

2 years ago

0.9.0-beta.2

2 years ago

0.7.5

2 years ago

0.9.0-beta.4

2 years ago

0.9.0-alpha.1

2 years ago

0.8.0-beta.3

2 years ago

0.7.4-beta1

2 years ago

0.8.0-beta.1

2 years ago

0.8.0-beta.2

2 years ago

0.7.0-beta.10

2 years ago

0.7.0-beta.12

2 years ago

0.7.0-beta.11

2 years ago

0.7.0-beta.14

2 years ago

0.7.0-beta.13

2 years ago

0.7.0

2 years ago

0.7.0-beta.1

2 years ago

0.7.0-beta.2

2 years ago

0.7.0-beta.3

2 years ago

0.7.0-beta.8

2 years ago

0.7.0-beta.9

2 years ago

0.7.0-beta.4

2 years ago

0.7.0-beta.5

2 years ago

0.7.0-beta.6

2 years ago

0.7.0-beta.7

2 years ago

0.5.0

2 years ago

0.6.0

2 years ago

0.4.14-beta.1

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.10-beta.1

2 years ago

0.4.8-beta.2

2 years ago

0.4.8-beta.1

2 years ago

0.4.10

2 years ago

0.4.13

2 years ago

0.4.11

2 years ago

0.4.12

2 years ago

0.4.5

2 years ago

0.4.9-beta.1

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.3-beta.1

2 years ago

0.4.7-beta.1

2 years ago

0.4.7-beta.2

2 years ago

0.4.7-beta.3

2 years ago

0.4.7-beta.4

2 years ago

0.4.7-beta.5

2 years ago

0.4.12-beta.8

2 years ago

0.4.12-beta.7

2 years ago

0.4.12-beta.6

2 years ago

0.4.12-beta.5

2 years ago

0.4.12-beta.4

2 years ago

0.4.1-2.beta-1

2 years ago

0.4.13-beta.3

2 years ago

0.4.12-beta.3

2 years ago

0.4.12-beta.2

2 years ago

0.4.13-beta.1

2 years ago

0.4.12-beta.1

2 years ago

0.4.13-beta.2

2 years ago

0.4.1-beta.1

2 years ago

0.4.2-beta.1

2 years ago

0.3.1-9.beta-1

3 years ago

0.3.1-9.beta-2

3 years ago

0.4.0-beta1

2 years ago

0.4.1

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.20

3 years ago

0.3.19

3 years ago

0.3.18

3 years ago

0.3.17

3 years ago

0.3.17-alpha.9

3 years ago

0.3.17-alpha.9.2

3 years ago

0.3.17-alpha.9.1

3 years ago

0.3.17-alpha.6

3 years ago

0.3.17-alpha.7

3 years ago

0.3.17-alpha.8

3 years ago

0.3.17-alpha.1

3 years ago

0.3.17-alpha.2

3 years ago

0.3.17-alpha.3

3 years ago

0.3.17-alpha.4

3 years ago

0.3.17-alpha.5

3 years ago

0.3.17-beta.2

3 years ago

0.3.17-beta.3

3 years ago

0.3.17-beta.1

3 years ago

0.3.16

3 years ago

0.3.16-beta.1

3 years ago

0.3.14-beta.1

3 years ago

0.3.15

3 years ago

0.3.14

3 years ago

0.3.15-beta.1

3 years ago

0.3.13

3 years ago

0.3.1-3.beta.1

3 years ago

0.3.13-beta.2

3 years ago

0.3.13-beta.1

3 years ago

0.3.12-beta.1

3 years ago

0.3.12

3 years ago

0.3.11

3 years ago

0.3.11-beta.5

3 years ago

0.3.11-beta.1

3 years ago

0.3.11-beta.3

3 years ago

0.3.11-beta.2

3 years ago

0.3.11-beta.4

3 years ago

0.3.10-beta.3

3 years ago

0.3.10-beta.4

3 years ago

0.3.10-beta.1

3 years ago

0.3.10-beta.2

3 years ago

0.3.10

3 years ago

0.3.8

3 years ago

0.3.9

3 years ago

0.3.8-beta.3

3 years ago

0.3.8-beta.4

3 years ago

0.3.8-beta.5

3 years ago

0.3.8-beta-1

3 years ago

0.3.8-beta.1

3 years ago

0.3.8-beta.2

3 years ago

0.3.7-beta.2

3 years ago

0.3.7-beta.1

3 years ago

0.3.7-beta.4

3 years ago

0.3.7-beta.3

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.5-beta-2

3 years ago

0.3.5-beta-3

3 years ago

0.3.5-beta-1

3 years ago

0.3.4-beta-2

3 years ago

0.3.4-beta-1

3 years ago

0.3.4

3 years ago

0.3.3-beta.2

3 years ago

0.3.3

3 years ago

0.3.3-beta.1

3 years ago

0.3.2-beta.1

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0-beta.2

3 years ago

0.3.0-beta.3

3 years ago

0.3.0

3 years ago

0.3.0-beta.1

3 years ago

0.1.15

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.2-rc5

3 years ago

0.1.2-rc6

3 years ago

0.1.2-rc3

3 years ago

0.1.2-rc4

3 years ago

0.1.2-rc1

3 years ago

0.1.13

3 years ago

0.1.2-rc2

3 years ago

0.1.14

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.1.2-rc7

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.1

3 years ago