Skip to content

Commit

Permalink
fix: APP-3070 - Update WC network switch flow via dAppConnect (#1330)
Browse files Browse the repository at this point in the history
* wip: show possible solution for aligning WC network with app network

* chore: add more detail to comments, default chain in WAGMI as mainnet

* chore: remove extra console.log

* chore: move global network switch to network error modal flow

* chore: remove extra console.log

* chore: refactor WC connector + switch to be more defensive

* chore: refactor to use wagmi hook directly, remove custom switchNetwork

* chore: remove console logs, unneeded connector hooks
  • Loading branch information
thekidnamedkd authored Apr 23, 2024
1 parent 1da925e commit 9275604
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 63 deletions.
1 change: 1 addition & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const App: React.FC = () => {
// further refactoring of layout (see further below).
const {pathname} = useLocation();
const {methods, status, network, address, provider} = useWallet();

useMonitoring();

// Initialize feature flags using the initial URL
Expand Down
24 changes: 12 additions & 12 deletions src/containers/networkErrorMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {useAlertContext} from 'context/alert';
import {useGlobalModalContext} from 'context/globalModals';
import {useNetwork} from 'context/network';
import useScreen from 'hooks/useScreen';
import {useSwitchNetwork} from 'hooks/useSwitchNetwork';
import {useWallet} from 'hooks/useWallet';
import WalletIcon from 'assets/images/wallet.svg';
import {CHAIN_METADATA} from 'utils/constants';
import {CHAIN_METADATA, SupportedNetworks} from 'utils/constants';
import {handleClipboardActions, shortenAddress} from 'utils/library';
import {useSwitchChain} from 'wagmi';

interface INetworkErrorMenuState {
onClose?: () => void;
Expand All @@ -26,8 +26,9 @@ export const NetworkErrorMenu = () => {
const {onClose, onSuccess} = modalState ?? {};

const {network} = useNetwork();
const {switchWalletNetwork} = useSwitchNetwork();
const {address, ensName, ensAvatarUrl, connectorName} = useWallet();
const {switchChain} = useSwitchChain();
const {address, ensName, ensAvatarUrl} = useWallet();

const {isDesktop} = useScreen();
const {t} = useTranslation();
const {alert} = useAlertContext();
Expand All @@ -38,7 +39,8 @@ export const NetworkErrorMenu = () => {
};

const handleSwitchNetwork = () => {
switchWalletNetwork();
const currentChain = CHAIN_METADATA[network as SupportedNetworks]?.id;
switchChain({chainId: currentChain});
close();
onSuccess?.();
};
Expand Down Expand Up @@ -86,13 +88,11 @@ export const NetworkErrorMenu = () => {
</Trans>
</WarningDescription>
</WarningContainer>
{connectorName === 'MetaMask' && (
<Button onClick={handleSwitchNetwork} size="lg" variant="primary">
{t('alert.wrongNetwork.buttonLabel', {
network: CHAIN_METADATA[network].name,
})}
</Button>
)}
<Button onClick={handleSwitchNetwork} size="lg" variant="primary">
{t('alert.wrongNetwork.buttonLabel', {
network: CHAIN_METADATA[network].name,
})}
</Button>
</ModalBody>
</ModalBottomSheetSwitcher>
);
Expand Down
50 changes: 0 additions & 50 deletions src/hooks/useSwitchNetwork.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {App} from './app';
import {aragonGateway} from 'utils/aragonGateway';
import {HttpTransport} from 'viem';

const chains = [base, mainnet, polygon, arbitrum, sepolia] as [
const chains = [mainnet, polygon, base, arbitrum, sepolia] as [
Chain,
...Chain[],
];
Expand Down

0 comments on commit 9275604

Please sign in to comment.