vega-frontend-monorepo/libs/wallet/src/context.ts
2023-01-19 11:16:21 +00:00

39 lines
1.1 KiB
TypeScript

import { createContext } from 'react';
import type {
PubKey,
Transaction,
TransactionResponse,
VegaConnector,
} from './connectors';
export interface VegaWalletContextShape {
/** If the current connector does not support signing transactions */
isReadOnly: boolean;
/** The current select public key */
pubKey: string | null;
/** Public keys stored in users wallet */
pubKeys: PubKey[] | null;
/** Calls connect on the supplied connector, storing the returned keys */
connect: (connector: VegaConnector) => Promise<PubKey[] | null>;
/** Disconnects from the connector and clears public key state */
disconnect: () => Promise<void>;
/** Sets the current selected public key */
selectPubKey: (pubKey: string) => void;
/** Sign and send a transaction to the network */
sendTx: (
/** Public key to use in connected wallet */
pubKey: string,
/** Transaction payload */
transaction: Transaction
) => Promise<TransactionResponse | null>;
}
export const VegaWalletContext = createContext<
VegaWalletContextShape | undefined
>(undefined);