Skip to content

Commit

Permalink
remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian-Bright committed Mar 19, 2022
1 parent 61229fb commit 9387284
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 85 deletions.
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
-->
<script src="/snarkjs.min.js"></script>
<script src="/circomlibjs.min.js"></script>
<script src="https://unpkg.com/@toruslabs/torus-embed"></script>
<title>Battlezips</title>
</head>
<body>
Expand Down
21 changes: 14 additions & 7 deletions src/contexts/WalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export const WalletProvider: React.FC = ({ children }) => {
// window.location.reload();
}, []);

const addMetaMaskListeners = useCallback(
(modalProvider: any) => {
modalProvider.on('accountsChanged', () => {
disconnect();
});
modalProvider.on('chainChanged', () => {
disconnect();
});
},
[disconnect]
);

const setWalletProvider = useCallback(async (prov) => {
const ethersProvider = new providers.Web3Provider(prov);

Expand Down Expand Up @@ -119,20 +131,15 @@ export const WalletProvider: React.FC = ({ children }) => {
await setWalletProvider(choosenProvider);
return choosenProvider;
})();
modalProvider.on('accountsChanged', () => {
disconnect();
});
modalProvider.on('chainChanged', () => {
disconnect();
});
if (modalProvider.isMetaMask) addMetaMaskListeners(modalProvider);
} catch (web3Error) {
// eslint-disable-next-line no-console
console.error(web3Error);
disconnect();
} finally {
setConnecting(false);
}
}, [setWalletProvider, disconnect]);
}, [addMetaMaskListeners, setWalletProvider, disconnect]);

useEffect(() => {
const load = async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/types/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export { };
declare global {
interface Window {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
snarkjs: any;
circomlibjs: any;
snarkjs: any;
Torus: any;
}
}
87 changes: 10 additions & 77 deletions src/web3/providerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,14 @@
import { IProviderOptions } from 'web3modal';

export const providerOptions: IProviderOptions = {
// walletconnect: {
// package: WalletConnectProvider,
// options: {
// rpc: {
// 1: process.env.REACT_APP_MAINNET_RPC,
// 4: process.env.REACT_APP_RINKEBY_RPC
// }
// }
// }
/*'custom-torus-rinkeby': {
display: {
logo: TorusLogo,
name: 'Torus Rinkeby',
description: 'Connect your Torus account',
},
package: Torus,
options: {
network: 'rinkeby',
},
connector: connectors.torus,
},
'custom-torus-mainnet': {
display: {
logo: TorusLogo,
name: 'Torus Mainnet',
description: 'Connect your Torus account',
},
package: Torus,
options: {
network: 'mainnet',
},
connector: connectors.torus,
},
'custom-walletlink-rinkeby': {
display: {
logo: CoinbaseLogo,
name: 'Coinbase Rinkeby',
description: 'Scan with WalletLink to connect',
},
options: {
appName: 'Rigor',
networkUrl: process.env.REACT_APP_RINKEBY_RPC,
chainId: 4,
},
package: WalletLink,
connector: async (_: unknown, options: ConnectorOptions) => {
const { appName, networkUrl, chainId } = options;
const walletLink = new WalletLink({
appName,
});
const provider = walletLink.makeWeb3Provider(networkUrl, chainId);
await provider.enable();
return provider;
},
},
'custom-walletlink-mainnet': {
display: {
logo: CoinbaseLogo,
name: 'Coinbase Mainnet',
description: 'Scan with WalletLink to connect',
},
options: {
appName: 'Rigor',
networkUrl: process.env.REACT_APP_MAINNET_RPC,
chainId: 1,
},
package: WalletLink,
connector: async (_: unknown, options: ConnectorOptions) => {
const { appName, networkUrl, chainId } = options;
const walletLink = new WalletLink({
appName,
});
const provider = walletLink.makeWeb3Provider(networkUrl, chainId);
await provider.enable();
return provider;
},
},*/
torus: {
package: window.Torus,
options: {
networkParams: {
host: 'https://matic-mumbai.chainstacklabs.com',
chainId: 80001,
networkName: 'mumbai'
},
}
}
};

0 comments on commit 9387284

Please sign in to comment.