vega-frontend-monorepo/apps/trading/lib/web3-connectors.ts
Matthew Russell 1d8de701c9
Use types from web3-react library
export connectors to avoid needless data manipulation, use built in types from web3-react (#310)
2022-05-02 13:16:57 -04:00

31 lines
906 B
TypeScript

import type { Web3ReactHooks } from '@web3-react/core';
import { initializeConnector } from '@web3-react/core';
import { MetaMask } from '@web3-react/metamask';
import { WalletConnect } from '@web3-react/walletconnect';
const [metamask, metamaskHooks] = initializeConnector<MetaMask>(
(actions) => new MetaMask(actions)
);
const CHAIN_ID = Number(process.env['NX_ETHEREUM_CHAIN_ID']);
const PROVIDER_URL = process.env['NX_ETHEREUM_PROVIDER_URL'] as string;
if (isNaN(CHAIN_ID)) {
throw new Error('Invalid Ethereum chain ID for environment');
}
const [walletconnect, walletconnectHooks] = initializeConnector<WalletConnect>(
(actions) =>
new WalletConnect(actions, {
rpc: {
[CHAIN_ID]: PROVIDER_URL,
},
}),
[CHAIN_ID]
);
export const Connectors: [MetaMask | WalletConnect, Web3ReactHooks][] = [
[metamask, metamaskHooks],
[walletconnect, walletconnectHooks],
];