28b4593a1d
Co-authored-by: bwallacee <ben@vega.xyz>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import {
|
|
InjectedConnector,
|
|
JsonRpcConnector,
|
|
SnapConnector,
|
|
ViewPartyConnector,
|
|
createConfig,
|
|
fairground,
|
|
mainnet,
|
|
stagnet,
|
|
} from '@vegaprotocol/wallet';
|
|
import { CHAIN_IDS, useEnvironment } from '@vegaprotocol/environment';
|
|
import { useMemo } from 'react';
|
|
|
|
/**
|
|
* Hook for memoizing the vega wallet config, since we can't be certain of the
|
|
* node address for snap connection we need to re-new once its set or changes
|
|
*/
|
|
export const useVegaWalletConfig = () => {
|
|
const { VEGA_ENV, VEGA_URL, VEGA_WALLET_URL } = useEnvironment();
|
|
|
|
return useMemo(() => {
|
|
if (!VEGA_URL || !VEGA_WALLET_URL) return;
|
|
|
|
const injected = new InjectedConnector();
|
|
|
|
const jsonRpc = new JsonRpcConnector({
|
|
url: VEGA_WALLET_URL,
|
|
});
|
|
|
|
const snap = new SnapConnector({
|
|
node: new URL(VEGA_URL).origin,
|
|
snapId: 'npm:@vegaprotocol/snap',
|
|
version: '1.0.1',
|
|
});
|
|
|
|
const viewParty = new ViewPartyConnector();
|
|
|
|
const config = createConfig({
|
|
chains: [mainnet, fairground, stagnet],
|
|
defaultChainId: CHAIN_IDS[VEGA_ENV],
|
|
connectors: [injected, snap, jsonRpc, viewParty],
|
|
});
|
|
|
|
return config;
|
|
}, [VEGA_ENV, VEGA_URL, VEGA_WALLET_URL]);
|
|
};
|