Empty Modal with React

While setting up web3auth with React, I am getting an empty modal. Any idea why?

  • SDK Version: 5.1.0

My codebase:

import React, { useState, useEffect, useRef, Fragment } from "react";
import { Link, useLocation } from 'react-router-dom'
import { useNavigate } from 'react-router-dom';
import LoginCss from "../../css/Login.module.css"
import '../../css/forgot-password.css'
//import "../../css/web3auth.css"
import { URLS } from '../app-url'
import { errorPopup, successPopup, warningPopup } from '../../utils/PopUpMessage';
import axios from 'axios'
import { ethers } from "ethers";
import Web3 from 'web3';

//Web3Auth
import { Web3Auth } from "@web3auth/modal";
import { CHAIN_NAMESPACES, SafeEventEmitterProvider } from "@web3auth/base";
import { OpenloginAdapter } from "@web3auth/openlogin-adapter";
//import { WalletConnectV2Adapter, getWalletConnectV2Settings } from "@web3auth/wallet-connect-v2-adapter";
import { MetamaskAdapter } from "@web3auth/metamask-adapter";

const clientId = process.env.REACT_APP_CLIENT_ID

export default function Login({ setUserNameUrl ,  setAccount , setFooterAccount ,changeIsLogin}) {
    const navigator = useNavigate();
    const username = localStorage.getItem('username')
    const [popup, setPopup] = useState("")
    const [user, setUser] = useState({
        username: '',
        password: ''
    })

    //web3Auth
    const [web3auth, setWeb3auth] = useState(null)
    const [provider, setProvider] = useState(null)

    useEffect(() => {
        setAccount("Login")
        setFooterAccount("forgotFooter")

        if(username){
            navigator(`/debug/`)
            warningPopup("Please try logging out and in again")
        }else{
            navigator("/loginBETA")
        }

        const init = async () => {
            try {
              const web3auth = new Web3Auth({
                clientId,
                chainConfig: {
                    chainNamespace: CHAIN_NAMESPACES.EIP155,
                    chainId: "0x1",
                },
                uiConfig: {
                    theme: "dark",
                    loginMethodsOrder: ["github", "google"],
                    defaultLanguage: "en",
                    appLogo: "https://web3auth.io/community/images/w3a-L-Favicon-1.svg", // Your App Logo Here
                  },
                  web3AuthNetwork: "cyan",
              });
      
              const openloginAdapter = new OpenloginAdapter({
                loginSettings: {
                  mfaLevel: "default",
                },
                adapterSettings: {
                  whiteLabel: {
                    name: "Buckets",
                    logoLight: "https://web3auth.io/community/images/w3a-L-Favicon-1.svg",
                    logoDark: "https://web3auth.io/community/images/w3a-D-Favicon-1.svg",
                    defaultLanguage: "en",
                    dark: true, // whether to enable dark mode. defaultValue: false
                  },
                },
              });
              web3auth.configureAdapter(openloginAdapter);
      

              // adding metamask adapter
              const metamaskAdapter = new MetamaskAdapter({
                  clientId,
                  sessionTime: 3600, // 1 hour in seconds
                  web3AuthNetwork: "cyan",
                  chainConfig: {
                  chainNamespace: CHAIN_NAMESPACES.EIP155,
                  chainId: "0x1",
                  rpcTarget: "https://rpc.ankr.com/eth", // This is the public RPC we have added, please pass on your own endpoint while creating an app
                  },
              });
              // we can change the above settings using this function
              metamaskAdapter.setAdapterSettings({
                  sessionTime: 86400, // 1 day in seconds
                  chainConfig: {
                  chainNamespace: CHAIN_NAMESPACES.EIP155,
                  chainId: "0x1",
                  rpcTarget: "https://rpc.ankr.com/eth", // This is the public RPC we have added, please pass on your own endpoint while creating an app
                  },
                  web3AuthNetwork: "cyan",
              });
    
              // it will add/update  the metamask adapter in to web3auth class
              web3auth.configureAdapter(metamaskAdapter);
  
              setWeb3auth(web3auth)
      
              await web3auth.initModal()
              if (web3auth.provider) {
                setProvider(web3auth.provider)
              }
            } catch (error) {
              console.error(error)
            }
          };
      
          init();
    }, []);

    const loginWeb3Auth = async () => {
        if (!web3auth) {
            errorPopup("web3auth not initialized yet");
            return;
          }
          const web3authProvider = await web3auth.connect();
          setProvider(web3authProvider);
          successPopup("Logged in Successfully!");
        };
    
    
        const authenticateUser = async () => {
            if (!web3auth) {
            errorPopup("web3auth not initialized yet");
            return;
            }
            const idToken = await web3auth.authenticateUser();
            errorPopup(idToken);
        };
      
        const getUserInfo = async () => {
            if (!web3auth) {
              errorPopup("web3auth not initialized yet");
              return;
            }
            const user = await web3auth.getUserInfo();
            errorPopup(user);
          };
        
          const logout2 = async () => {
            if (!web3auth) {
              errorPopup("web3auth not initialized yet");
              return;
            }
            await web3auth.logout();
            setProvider(null);
          };

    function web3Login() {
        return(
            <div className="mb-4 mt-4">
                <p className="text-center" align="justify"><i>That's the way.</i></p>
                <p className="text-center" align="justify"><i>Web2 logins are no longer available. 
                    Login with your wallet provider or create a new wallet below.</i></p>
                <button type="button" id="btn-login" className="btn btn-orange shadow-sm" onClick={loginWeb3Auth} >
                    Connect to Buckets
                </button>
            </div>          
        )
    }

    

    return (
        <>
        <div className="bucket-background"> 
            <div className="container">
                <div className="row justify-content-center">
                    <div className="col-xl-10 col-lg-12 col-md-9">
                        <div className="card o-hidden border-0 shadow-lg my-5">
                            <div className="card-body p-0">
                                {/* <!-- Nested Row within Card Body --> */}
                                <div className="row">
                                    <div className="col-lg-6 d-none d-lg-block bg-password-image"></div>
                                    <div className="col-lg-6">
                                        <div className="p-5">
                                            <div className="text-center">
                                                    {web3Login()}                            
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </>
    )
}

I tried changing the above for:

              web3AuthNetwork: "mainnet",

based on this discussion: Whitelist Domain on Dashboard · Web3Auth · Discussion #1143 · GitHub
But without success.

Hey @clement.fel

Please share the full browser console.

Also, Are you getting the Cannot convert a BigInt value to a number error?
If so, please look at Big Int error in React production build?

Hi @shahbaz,

I am (unfortunately :smiley: ) not getting the BigInt error.

I thought there could be some dependency issues with the Biconomy library, which I was using before. Hence, I uninstalled all biconomy related packages and now I am getting the following error:

Module not found: Error: Can’t resolve ‘@walletconnect/client’ in ‘…\node_modules@web3auth\wallet-connect-v1-adapter\dist’

It is only a warning - although it’s annoying - but I can still browse the website.

EDIT: THE ERROR OCCURS ON THIS LINE: await web3auth.initModal()

The full browser console are shown above. Here is a better picture of the errors (the 4 yellow warnings are not related to my webapp):

I resolved the @walletconnect/client issue by reinstalling all dependencies. However, I still get a blank modal.

It seems to be a conflict with the @metamask/obs-store package, which is a dependency of @web3auth/modal, according to the console logs posted in my previous post.

Could you please assist?

@shahbaz, what additional info can I provide for you to assess the source of this error? It has been 1 week and no solution yet

@clement.fel Please update to the latest version of the SDK and let me know if you are still facing this issue.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.