mirror of
https://github.com/oceanprotocol/react.git
synced 2025-01-21 02:09:57 +01:00
price fetching fixes
This commit is contained in:
parent
afbf0295cc
commit
b438742000
@ -10,6 +10,7 @@ import {
|
|||||||
import { useOcean } from 'providers'
|
import { useOcean } from 'providers'
|
||||||
import { getBestDataTokenPrice } from 'utils/dtUtils'
|
import { getBestDataTokenPrice } from 'utils/dtUtils'
|
||||||
import { isDDO } from 'utils'
|
import { isDDO } from 'utils'
|
||||||
|
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
||||||
|
|
||||||
interface UseMetadata {
|
interface UseMetadata {
|
||||||
ddo: DDO | undefined
|
ddo: DDO | undefined
|
||||||
@ -22,7 +23,7 @@ interface UseMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useMetadata(asset?: DID | string | DDO): UseMetadata {
|
function useMetadata(asset?: DID | string | DDO): UseMetadata {
|
||||||
const { ocean, accountId, networkId, config } = useOcean()
|
const { ocean, config, status, networkId } = useOcean()
|
||||||
const [internalDdo, setDDO] = useState<DDO>()
|
const [internalDdo, setDDO] = useState<DDO>()
|
||||||
const [internalDid, setDID] = useState<DID | string>()
|
const [internalDid, setDID] = useState<DID | string>()
|
||||||
const [metadata, setMetadata] = useState<Metadata>()
|
const [metadata, setMetadata] = useState<Metadata>()
|
||||||
@ -90,7 +91,13 @@ function useMetadata(asset?: DID | string | DDO): UseMetadata {
|
|||||||
setTitle(metadata.main.name)
|
setTitle(metadata.main.name)
|
||||||
setIsLoaded(true)
|
setIsLoaded(true)
|
||||||
|
|
||||||
if (!accountId) return
|
// Stop here and do not start fetching from chain, when not connected properly.
|
||||||
|
if (
|
||||||
|
status !== 1 ||
|
||||||
|
networkId !== (config as ConfigHelperConfig).networkId
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
// Set price again, but from chain
|
// Set price again, but from chain
|
||||||
const priceLive = await getPrice(internalDdo.dataToken)
|
const priceLive = await getPrice(internalDdo.dataToken)
|
||||||
priceLive && internalDdo.price !== priceLive && setPrice(priceLive)
|
priceLive && internalDdo.price !== priceLive && setPrice(priceLive)
|
||||||
@ -98,7 +105,13 @@ function useMetadata(asset?: DID | string | DDO): UseMetadata {
|
|||||||
init()
|
init()
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
if (!internalDdo || !accountId) return
|
if (
|
||||||
|
!internalDdo ||
|
||||||
|
status !== 1 ||
|
||||||
|
networkId !== (config as ConfigHelperConfig).networkId
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
const priceLive = await getPrice(internalDdo.dataToken)
|
const priceLive = await getPrice(internalDdo.dataToken)
|
||||||
priceLive && setPrice(priceLive)
|
priceLive && setPrice(priceLive)
|
||||||
}, 10000)
|
}, 10000)
|
||||||
@ -106,7 +119,7 @@ function useMetadata(asset?: DID | string | DDO): UseMetadata {
|
|||||||
return () => {
|
return () => {
|
||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
}
|
}
|
||||||
}, [accountId, networkId, internalDdo, getMetadata, getPrice])
|
}, [status, networkId, config, internalDdo, getMetadata, getPrice])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ddo: internalDdo,
|
ddo: internalDdo,
|
||||||
|
Loading…
Reference in New Issue
Block a user