import { Network, WalletConnection, WalletConnectionDelegate, WalletConnector } from '@concordium/wallet-connectors'; import { Component } from 'react'; /** * Activation/deactivation controller of a given connector type. */ export interface ConnectorType { /** * Called when the connection type is being activated. * The connector instance returned by this method becomes the new {@link State.activeConnector activeConnector}. * @param component The component in which the instance is being activated. * This object doubles as the delegate to pass to new connector instances. * @param network The network to pass to new connector instances. */ activate(component: WithWalletConnector, network: Network): Promise; /** * Called from {@link WithWalletConnector} when the connection type is being deactivated, * i.e. right after {@link State.activeConnector activeConnector} has been unset from this value. * @param component The component in which the instance is being deactivated. * @param connector The connector to deactivate. */ deactivate(component: WithWalletConnector, connector: WalletConnector): Promise; } /** * Produce a {@link ConnectorType} that creates a new connector instance on activation * and disconnects the existing one on deactivation. * This is the simplest connection type and should be used unless there's a reason not to. * @param create Factory function for creating new connector instances. */ export declare function ephemeralConnectorType(create: (c: WithWalletConnector, n: Network) => Promise): { activate: (c: WithWalletConnector, n: Network) => Promise; deactivate: (w: WithWalletConnector, c: WalletConnector) => Promise; }; /** * Produce a {@link ConnectorType} that reuse connectors between activation cycles. * That is, once a connector is created, it's never automatically disconnected. * Note that only the connector is permanent. Individual connections may still be disconnected by the application. * @param create Factory function for creating new connector instances. */ export declare function persistentConnectorType(create: (c: WithWalletConnector, n: Network) => Promise): { activate: (component: WithWalletConnector, network: Network) => Promise; deactivate: () => Promise; }; /** * The internal state of the component. */ interface State { /** * The active connector type. This value is updated using {@link WalletConnectionProps.setActiveConnectorType}. * Changes to this value trigger activation of a connector managed by the connector type. * This will cause {@link activeConnector} or {@link activeConnectorError} to change depending on the outcome. */ activeConnectorType: ConnectorType | undefined; /** * The active connector. Connector instances get (de)activated appropriately when {@link activeConnectorType} changes. * * It's up to the {@link ConnectorType} in {@link activeConnectorType} to implement any synchronization between * the active connector and {@link activeConnector}: * In general, it is perfectly possible for the active connection to not originate from the active connector. * * If the application disconnects the active connector manually, they must also call * {@link WalletConnectionProps.setActiveConnectorType} to */ activeConnector: WalletConnector | undefined; /** * Any of the following kinds of errors: * - Error activating a connector with {@link activeConnectorType}. * In this case {@link activeConnector} is undefined. * - Error deactivating the previous connector. * In this case {@link activeConnectorType} and {@link activeConnector} are undefined. */ activeConnectorError: string; /** * A map from open connections to their selected accounts or the empty string * if the connection doesn't have an associated account. */ connectedAccounts: Map; /** * A map from open connections to the hash of the genesis block for the chain that the selected accounts * of the connections live on. * Connections without a selected account (or the account's chain is unknown) will not have an entry in this map. * * TODO The reported hash values are not too reliable as they're updated only when the `onChainChanged` event fires. * And this doesn't happen when the connection is initiated. * For WalletConnect we could do that manually as we control what chain we connect to. * For BrowserWallet we don't have that option (see also https://concordium.atlassian.net/browse/CBW-633). */ genesisHashes: Map; } interface Props { /** * The network on which the connected accounts are expected to live on. * * Changes to this value will cause all connections managed by {@link State.activeConnector} to get disconnected. */ network: Network; /** * Function for generating the child component based on the props derived from the state of this component. * * JSX automatically supplies the nested expression as this prop field, so callers usually don't set it explicitly. * * @param props Connection state and management functions. * @return Child component. */ children: (props: WalletConnectionProps) => JSX.Element; } /** * The props to be passed to the child component. */ export interface WalletConnectionProps extends State { /** * The network provided to {@link WithWalletConnector} via its props. * * This is only passed for convenience as the value is always available to the child component anyway. */ network: Network; /** * Function for setting or resetting {@link State.activeConnectorType activeConnectorType}. * * Any existing connector type value is deactivated and any new one is activated. * * @param type The new connector type or undefined to reset the value. */ setActiveConnectorType: (type: ConnectorType | undefined) => void; } /** * React component that helps managing wallet connections * by introducing a notion of "active" {@link WalletConnector} and {@link WalletConnection}, * and maintaining their states as part of its own component state. * This allows child components to access all relevant information in a reactive manner * and provides methods for managing the active connection. * * The component implements {@link WalletConnectionDelegate} and passes itself to all {@link WalletConnector}s * that it initializes. * This allows it to receive events from the underlying clients. * Once it receives an event for the active {@link WalletConnection}, * it performs the relevant updates to its component state which then bubble down to child components. * * This component significantly reduces the complexity of integrating with wallets, * even if one only needs to support a single protocol and network. */ export declare class WithWalletConnector extends Component implements WalletConnectionDelegate { constructor(props: Props); /** * @see WalletConnectionProps.setActiveConnectorType */ setActiveConnectorType: (type: ConnectorType | undefined) => void; onAccountChanged: (connection: WalletConnection, address: string | undefined) => void; onChainChanged: (connection: WalletConnection, genesisHash: string) => void; onConnected: (connection: WalletConnection, address: string | undefined) => void; onDisconnected: (connection: WalletConnection) => void; render(): JSX.Element; componentDidUpdate(prevProps: Props): void; componentWillUnmount(): void; } export {}; //# sourceMappingURL=WithWalletConnector.d.ts.map