8a829964be
* Add ag-grid * Add lazy loaded ag-grid component * Add theme context, move VegaWallet to separate lib * Fix trading app cypress configuration * Lazy load ag-grid theme css files * Encapsulate theme switch hook
30 lines
905 B
TypeScript
30 lines
905 B
TypeScript
import { useVegaWallet, WALLET_CONFIG } from '@vegaprotocol/wallet';
|
|
import { useEffect } from 'react';
|
|
import { LocalStorage } from '@vegaprotocol/react-helpers';
|
|
import { Connectors } from '../lib/connectors';
|
|
|
|
export function useEagerConnect() {
|
|
const { connect } = useVegaWallet();
|
|
|
|
useEffect(() => {
|
|
const cfg = LocalStorage.getItem(WALLET_CONFIG);
|
|
const cfgObj = JSON.parse(cfg);
|
|
|
|
// No stored config, user has never connected or manually cleared storage
|
|
if (!cfgObj || !cfgObj.connector) {
|
|
return;
|
|
}
|
|
|
|
// Use the connector string in local storage to find the right connector to auto
|
|
// connect to
|
|
const connector = Connectors[cfgObj.connector];
|
|
|
|
// Developer hasn't provided this connector
|
|
if (!connector) {
|
|
throw new Error(`Connector ${cfgObj?.connector} not configured`);
|
|
}
|
|
|
|
connect(Connectors[cfgObj.connector]);
|
|
}, [connect]);
|
|
}
|