Skip to content

Commit

Permalink
fix: EIP1193 provider not found
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed May 27, 2022
1 parent 5a6fddf commit 68d3829
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions packages/wallet-management/LiFiWalletManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const useLifiWalletManagement = () => {

const connect = useCallback(
async (wallet?: Wallet) => {
const currentlySelectedUserAddress = (window as any).ethereum
.selectedAddress;
const currentlySelectedUserAddress = (window as any)?.ethereum
?.selectedAddress;
try {
if (!wallet) {
await priorityConnector.activate();
Expand All @@ -37,7 +37,7 @@ export const useLifiWalletManagement = () => {
const disconnect = useCallback(
async (wallet?: Wallet) => {
const currentlySelectedUserAddress = (window as any).ethereum
.selectedAddress;
?.selectedAddress;

removeFromActiveWallets(currentlySelectedUserAddress);
addToDeactivatedWallets(currentlySelectedUserAddress);
Expand All @@ -56,7 +56,7 @@ export const useLifiWalletManagement = () => {

useEffect(() => {
const currentlySelectedUserAddress = (window as any).ethereum
.selectedAddress;
?.selectedAddress;

if (!isWalletDeactivated(currentlySelectedUserAddress)) {
priorityConnector?.connectEagerly!();
Expand All @@ -78,9 +78,9 @@ export const useLifiWalletManagement = () => {
ethereum?.on('chainChanged', handleChainChanged);

return () => {
if (ethereum.removeListener) {
ethereum?.removeListener('connect', handleConnect);
ethereum?.removeListener('chainChanged', handleChainChanged);
if (ethereum?.removeListener) {
ethereum.removeListener('connect', handleConnect);
ethereum.removeListener('chainChanged', handleChainChanged);
}
};
}, [priorityConnector]);
Expand Down
21 changes: 11 additions & 10 deletions packages/wallet-management/connectors/eip1193.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Eip1193Bridge } from '@ethersproject/experimental';
import { supportedChains } from '@lifinance/sdk';
import { initializeConnector } from '@web3-react/core';
import { EIP1193 } from '@web3-react/eip1193';
import { Empty, EMPTY } from '@web3-react/empty';
import { providers } from 'ethers';

class Eip1193BridgeWithoutAccounts extends Eip1193Bridge {
Expand All @@ -17,17 +18,17 @@ class Eip1193BridgeWithoutAccounts extends Eip1193Bridge {
}
}
const { ethereum } = window as any;
const currentProvider = new providers.Web3Provider(ethereum);
const currentProvider = ethereum ? new providers.Web3Provider(ethereum) : null;

// const chainId = (await currentProvider.getNetwork()).chainId;
// const currentChain;
const eip1193Provider = currentProvider
? new Eip1193BridgeWithoutAccounts(
currentProvider?.getSigner(),
currentProvider,
)
: null;

const eip1193Provider = new Eip1193BridgeWithoutAccounts(
currentProvider.getSigner(),
currentProvider,
);

export const [eip1193, hooks] = initializeConnector<EIP1193>(
(actions) => new EIP1193(actions, eip1193Provider, false),
export const [eip1193, hooks] = initializeConnector<EIP1193 | Empty>(
(actions) =>
eip1193Provider ? new EIP1193(actions, eip1193Provider, false) : EMPTY,
supportedChains.map((chain) => chain.id),
);

0 comments on commit 68d3829

Please sign in to comment.