What's the right way to use enableWeb3?

This is what I have right now, but it’s spamming the user when the user denied to connect his wallet.


useEffect(() => {

    (async () => {

      try {

        if (!isInitialized) {

          initialize({

            appId: ###########

            serverUrl: ##########

          });

        }

        if (isInitialized && !isWeb3Enabled) {

          try {

            const wc = window as WindowChain;

            const provider = wc.ethereum;

            if (window.localStorage.walletconnect) {

              await enableWeb3({
                provider: "walletconnect"
              })

            } else

              if (provider) {

                await enableWeb3()

              }

          } catch (e) {

            console.log(e)

          }

        }

        if (isInitialized && isWeb3Enabled)

          await getProperty();

      } catch (error) {

       

      setPropertyData(myData)

        console.log("error", error);

      }

    }

    )()

  }, [isWeb3Enabled, isInitialized])

You can use enableWeb3 when the user does something e.g. clicks a connect wallet button or run it when the page/component is mounted (in a useEffect). What is the error?

There’s no error, it’s just that it keeps on asking user to connect his metamask. Not authenticate.

it look like it is a loop here, it will try to enable web3 every time when it is not enabled?