2022-05-02 17:16:57 +00:00
|
|
|
import type { Web3ReactHooks } from '@web3-react/core';
|
2022-03-25 07:44:10 +00:00
|
|
|
import { initializeConnector } from '@web3-react/core';
|
|
|
|
import { MetaMask } from '@web3-react/metamask';
|
|
|
|
import { WalletConnect } from '@web3-react/walletconnect';
|
|
|
|
|
2022-05-02 17:16:57 +00:00
|
|
|
const [metamask, metamaskHooks] = initializeConnector<MetaMask>(
|
2022-03-25 07:44:10 +00:00
|
|
|
(actions) => new MetaMask(actions)
|
|
|
|
);
|
|
|
|
|
2022-06-13 14:39:17 +00:00
|
|
|
export const createConnectors = (providerUrl: string, chainId: number) => {
|
|
|
|
if (isNaN(chainId)) {
|
|
|
|
throw new Error('Invalid Ethereum chain ID for environment');
|
|
|
|
}
|
|
|
|
const [walletconnect, walletconnectHooks] =
|
|
|
|
initializeConnector<WalletConnect>(
|
|
|
|
(actions) =>
|
|
|
|
new WalletConnect(actions, {
|
|
|
|
rpc: {
|
|
|
|
[chainId]: providerUrl,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
[chainId]
|
|
|
|
);
|
|
|
|
return [
|
|
|
|
[metamask, metamaskHooks],
|
|
|
|
[walletconnect, walletconnectHooks],
|
|
|
|
] as [MetaMask | WalletConnect, Web3ReactHooks][];
|
|
|
|
};
|