vega-frontend-monorepo/libs/react-helpers/src/lib/vega-wallet/context.ts

32 lines
933 B
TypeScript
Raw Normal View History

import { VegaKey } from '@vegaprotocol/vegawallet-service-api-client';
import { createContext } from 'react';
import { VegaConnector } from './connectors';
export interface VegaKeyExtended extends VegaKey {
name: string;
}
export interface VegaWalletContextShape {
/** The current select public key */
keypair: VegaKeyExtended | null;
/** Public keys stored in users wallet */
keypairs: VegaKeyExtended[] | null;
/** Calls connect on the supplied connector, storing the returned keys */
connect: (connector: VegaConnector) => Promise<void>;
/** Disconnects from the connector and clears public key state */
disconnect: () => Promise<void>;
/** Sets the current selected public key */
selectPublicKey: (publicKey: string) => void;
/** Reference to the connector */
connector: VegaConnector | null;
}
export const VegaWalletContext = createContext<
VegaWalletContextShape | undefined
>(undefined);