Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
remove logging and left '@todo' comments to place events
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Colon committed Jun 23, 2022
1 parent 1d93640 commit 52d03fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/Web3Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getWeb3modalOptions } from './helpers/web3ModalConfig';
import { getLocalProvider, getFallbackProvider, getInjectedProvider } from './helpers';
import { useProviderListeners } from './hooks/useProviderListeners';
import { Web3ProviderContext } from './hooks/useWeb3Provider';
import { logging } from './logging';

const initialState: InitialState = {
account: null,
Expand Down Expand Up @@ -105,7 +104,7 @@ export function Web3Provider({
}, [connectDefaultProvider, config, web3Modal]);

const disconnect: DisconnectFn = useCallback(() => {
logging('info', 'Wallet Action', 'Account Disconnected');
// @todo add 'account disconnected' event
// switch to a default provider
connectDefaultProvider();
}, [connectDefaultProvider]);
Expand Down
25 changes: 7 additions & 18 deletions src/hooks/useProviderListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { useState, useEffect } from 'react';
import { ethers } from 'ethers';
import Web3Modal from 'web3modal';

import { logging } from '../logging';

export const useProviderListeners = (
web3Modal: Web3Modal,
connectDefaultProvider: () => void,
Expand All @@ -19,16 +17,12 @@ export const useProviderListeners = (
web3Modal.on('connect', _modalProvider => {
// check that connected chain is supported
if (!config.supportedChains.includes(parseInt(_modalProvider.chainId))) {
logging(
'error',
'Provider Error',
`Switch to a supported chain: ${config.supportedChains.join(', ')}`
);
// @todo add 'unsupported network' event
// switch to a default provider
connectDefaultProvider();
} else {
setModalProvider(_modalProvider);
logging('info', 'Wallet Action', `Account connected: ${_modalProvider.selectedAddress}`);
// @todo add 'connect' event
}
});
return () => {
Expand All @@ -39,34 +33,29 @@ export const useProviderListeners = (
useEffect(() => {
const chainChangedCallback = (chainId: string) => {
if (!config.supportedChains.includes(parseInt(chainId))) {
// check that connected chain is supported
logging(
'error',
'Provider Error',
`Switch to a supported chain: ${config.supportedChains.join(', ')}`
);
// @todo add 'unsupported network' event
// switch to a default provider
connectDefaultProvider();
} else {
logging('info', 'Wallet Action', `Chain id updated: ${chainId}`);
// @todo add 'network changed' event
connect();
}
};

const accountsChangedCallback = (accounts: string[]) => {
if (!accounts.length) {
logging('error', 'Wallet Action', 'Account access revoked');
// @todo add 'access revoked' event
// switch to a default provider
connectDefaultProvider();
// remove listeners
setModalProvider(null);
} else {
logging('info', 'Wallet Action', 'Account changed');
// @todo add 'account changed event' event
connect();
}
};
const disconnectCallback = () => {
logging('error', 'Wallet Action', 'Account access revoked');
// @todo add 'access revoked' event
// switch to a default provider
connectDefaultProvider();
// remove listeners
Expand Down
4 changes: 0 additions & 4 deletions src/logging/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
export function logging(type: string, actionType: string, message: string) {
console[type](actionType);
console[type](message);
}

0 comments on commit 52d03fb

Please sign in to comment.