In a project built with React, Next.js, RainbowKit, and Wagmi, when BSC (Binance Smart Chain) is designated as the initial chain on H5 mobile terminals, the Ethereum Mainnet is consistently displayed upon connecting to the MetaMask wallet app, and the switch to the BSC chain cannot be completed successfully. #4916
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The following is the code for a project using React, Next.js, RainbowKit, and Wagmi.
`
import { getDefaultConfig, Chain } from '@rainbow-me/rainbowkit';
import {
metaMaskWallet,
okxWallet,
tokenPocketWallet,
trustWallet,
coinbaseWallet
} from '@rainbow-me/rainbowkit/wallets';
import { bsc, mainnet, bscTestnet, sepolia } from "viem/chains"
export const createWagmiConfig = getDefaultConfig({
appName: 'nffffeeee',
projectId: process.env.NEXT_PUBLIC_PRFDFDF || "" as string,
chains: [
bscTestnet,
sepolia,
],
wallets: [
{
groupName: 'Recommended',
wallets: [tokenPocketWallet, okxWallet, metaMaskWallet, trustWallet, coinbaseWallet],
},
],
multiInjectedProviderDiscovery: false,
ssr: true,
});
export const defaultChainId: number = bscTestnet.id;
export const defaultChain: Chain = bscTestnet as Chain; `
`function MyApp({ Component, pageProps }: AppPropsWithLayout) {
useSetViewportHeightCSS();
const router = useRouter();
const locale = router.locale || router.defaultLocale || 'zh';
const isZh = locale.startsWith('zh') && !locale.includes('Hant');
const isZhHant = locale.includes('Hant');
const langClass = isZh ? 'lang-zh' : (isZhHant ? 'lang-zh-Hant' : 'lang-en');
useEffect(() => {
if (typeof document !== 'undefined') {
const root = document.documentElement;
root.classList.remove('lang-zh', 'lang-en', 'lang-zh-Hant');
root.classList.add(langClass);
}
}, [langClass]);
useEffect(() => {
const designWidth = 640;
const maxWidth = 768;
const pcBaseFontSize = 16;
let rafId: number | null = null;
function refreshRem() {
const html = document.documentElement;
let width = html.clientWidth;
if (width >= 1024) {
html.style.fontSize = pcBaseFontSize + 'px';
return;
}
}, []);
const getLayout = Component.getLayout ?? ((page) => page);
return (
<>
);
}
export default MyApp;`
Beta Was this translation helpful? Give feedback.
All reactions