Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: APP-3070 - Update WC network switch flow via dAppConnect #1330

Merged
merged 10 commits into from
Apr 23, 2024
Merged
7 changes: 7 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -38,12 +38,19 @@ import {GatingMenu} from 'containers/gatingMenu';
import {DelegationGatingMenu} from 'containers/delegationGatingMenu';
import UpdateBanner from 'containers/navbar/updateBanner';
import {ActionsProvider} from './context/actions';
import {useConnectors} from 'wagmi';

export const App: React.FC = () => {
// TODO this needs to be inside a Routes component. Will be moved there with
// further refactoring of layout (see further below).
const {pathname} = useLocation();
const {methods, status, network, address, provider} = useWallet();
const connectors = useConnectors();

console.log(connectors);
const wcConnector = connectors.filter(c => c.name === 'WalletConnect');

console.log('wcConnector', wcConnector);
useMonitoring();

// Initialize feature flags using the initial URL
24 changes: 12 additions & 12 deletions src/containers/networkErrorMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
@@ -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();
@@ -38,7 +39,8 @@ export const NetworkErrorMenu = () => {
};

const handleSwitchNetwork = () => {
switchWalletNetwork();
const currentChain = CHAIN_METADATA[network as SupportedNetworks]?.id;
switchChain({chainId: currentChain});
close();
onSuccess?.();
};
@@ -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>
);
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
@@ -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[],
];