diff --git a/src/hooks/useMetadata/useMetadata.ts b/src/hooks/useMetadata/useMetadata.ts index b044b33..1ce46ac 100644 --- a/src/hooks/useMetadata/useMetadata.ts +++ b/src/hooks/useMetadata/useMetadata.ts @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react' import axios from 'axios' import { DID, DDO, MetaData, Curation } from '@oceanprotocol/squid' -import { useOcean } from '../../providers' +import { useOcean, OceanConnectionStatus } from '../../providers' interface UseMetadata { ddo: DDO @@ -15,18 +15,21 @@ interface UseMetadata { } function useMetadata(did?: DID | string): UseMetadata { - const { aquarius, config } = useOcean() + const { aquarius, config, status } = useOcean() const [ddo, setDDO] = useState() const [metadata, setMetadata] = useState() const [title, setTitle] = useState() async function getDDO(did: DID | string): Promise { + if(status!=OceanConnectionStatus.CONNECTED) return + const ddo = await aquarius.retrieveDDO(did) return ddo } async function getMetadata(did: DID | string): Promise { const ddo = await getDDO(did) + if(!ddo) return const metadata = ddo.findServiceByType('metadata') return metadata.attributes } @@ -38,6 +41,7 @@ function useMetadata(did?: DID | string): UseMetadata { async function getTitle(did: DID | string): Promise { const metadata = await getMetadata(did) + console.log(metadata) return metadata.main.name } @@ -48,6 +52,7 @@ function useMetadata(did?: DID | string): UseMetadata { useEffect(() => { async function init(): Promise { + if(!did) return const ddo = await getDDO(did) setDDO(ddo) diff --git a/src/providers/OceanProvider/OceanProvider.tsx b/src/providers/OceanProvider/OceanProvider.tsx index b18f180..6cea893 100644 --- a/src/providers/OceanProvider/OceanProvider.tsx +++ b/src/providers/OceanProvider/OceanProvider.tsx @@ -3,7 +3,7 @@ import { Ocean, Config, Account, Aquarius, Logger } from '@oceanprotocol/squid' import Web3 from 'web3' import Balance from '@oceanprotocol/squid/dist/node/models/Balance' import { connectOcean } from './utils' -import { useWeb3 } from '../Web3Provider' +import { useWeb3, InjectedProviderStatus } from '../Web3Provider' enum OceanConnectionStatus { OCEAN_CONNECTION_ERROR = -1, @@ -40,7 +40,7 @@ function OceanProvider({ const [status, setStatus] = useState( OceanConnectionStatus.NOT_CONNECTED ) - const { web3 } = useWeb3() + const { web3,ethProviderStatus } = useWeb3() // ------------------------------------------------------------- // 1. On mount, connect to Aquarius instance right away @@ -54,8 +54,8 @@ function OceanProvider({ // 2. Once `web3` becomes available, connect to the whole network // ------------------------------------------------------------- useEffect(() => { - if (!web3) return - + if (!web3 || ethProviderStatus!= InjectedProviderStatus.CONNECTED ) return + console.log(ethProviderStatus) async function init(): Promise { const { ocean, account, accountId, balance } = await connectOcean( web3,