Skip to content

Commit fe61397

Browse files
committed
feat: add hoc to dipslay switch chain warning when connected to mainnet
1 parent 45b1d56 commit fe61397

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { Spin } from '~/adapters/antd';
3+
import { NETWORKS } from '~/consts/supportedChains';
4+
5+
import { useWeb3 } from '~/hooks/useWeb3';
6+
7+
export const withRedirectFromMainnet = WrappedComponent => {
8+
const WithRedirectFromMainnet = props => {
9+
const { chainId } = useWeb3();
10+
const isOnMainnet = chainId === NETWORKS.ethereum;
11+
12+
return isOnMainnet ? (
13+
<Spin $centered spinning={isOnMainnet} tip="Waiting for network redirection" />
14+
) : (
15+
<WrappedComponent {...props} />
16+
);
17+
};
18+
WithRedirectFromMainnet.displayName = `withRedirectFromMainnet(${
19+
WrappedComponent.displayName || WrappedComponent.name || 'Component'
20+
})`;
21+
22+
return WithRedirectFromMainnet;
23+
};

0 commit comments

Comments
 (0)