useDApp icon indicating copy to clipboard operation
useDApp copied to clipboard

Hooks (useCall & useCalls) not returning data when wallet not connected / wrong network / !window.ethereum

Open nickhere432 opened this issue 4 years ago • 7 comments

Hooks (useCall & useCalls) not returning data when wallet not connected / wrong network / !window.ethereum. Checking network tab, all RPC calls are 200.

Steps to reproduce:

  1. Disconnect app in metamask if already connected.
  2. Refresh app
  3. useCall & useCalls hook returns undefined or
  4. Open app in incognito tab.
  5. useCall & useCalls hook returns undefined

nickhere432 avatar Apr 08 '22 15:04 nickhere432

Could you please include a code example?

dmaretskyi avatar Apr 08 '22 15:04 dmaretskyi

Could you please include a code example?

function useContractInfo() {
    const { value, error } =
        useCall({
            contract: new Contract(contractAddress, contractInterface),
            method: 'getContractInfo',
            args: []
        }) ?? {};
    if (error) {
        console.error(error.message);
        return {
            totalStaked: undefined,
            totalRefBonus: undefined,
            totalUsers: undefined
        };
    }

    return {
        totalStaked: value?.[0],
        totalRefBonus: value?.[1],
        totalUsers: value?.[2]
    };
}

nickhere432 avatar Apr 08 '22 15:04 nickhere432

Could you please include a code example?

function useContractInfo() {
    const { value, error } =
        useCall({
            contract: new Contract(contractAddress, contractInterface),
            method: 'getContractInfo',
            args: []
        }) ?? {};
    if (error) {
        console.error(error.message);
        return {
            totalStaked: undefined,
            totalRefBonus: undefined,
            totalUsers: undefined
        };
    }

    return {
        totalStaked: value?.[0],
        totalRefBonus: value?.[1],
        totalUsers: value?.[2]
    };
}

I'm thinking you should use codesandbox.com since the example you posted doesn't have the contractAddress, contractInterface variables defined

ItsShadowl avatar Apr 09 '22 11:04 ItsShadowl

Ran into the same issue, Check your config and make sure you're importing Mainnet.chainId rather than Mainnet.chainID. the Docs need to be updated.

CasperGhostCrypto avatar Apr 15 '22 22:04 CasperGhostCrypto

same issue facing => useCall return value and error undefined. React: v18 usedapp/core: 1.0.0 ethers: 5.5.x

aaqibsheikh avatar Apr 16 '22 00:04 aaqibsheikh

Same issue here too.

dnilosek avatar May 01 '22 22:05 dnilosek

Same issue as https://github.com/TrueFiEng/useDApp/issues/725#issuecomment-1110230151.

ItsShadowl avatar May 01 '22 23:05 ItsShadowl