1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

refresh interval tweaks (#257)

This commit is contained in:
Matthias Kretschmann 2020-11-17 13:10:12 +01:00 committed by GitHub
parent fa7de2eeb4
commit 7f2a5e7515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 7 deletions

View File

@ -17,6 +17,8 @@ interface MarketStatsResponse {
datatoken: number datatoken: number
} }
const refreshInterval = 60000 // 60 sec.
export default function MarketStats(): ReactElement { export default function MarketStats(): ReactElement {
const [ref, inView] = useInView() const [ref, inView] = useInView()
const [stats, setStats] = useState<MarketStatsResponse>() const [stats, setStats] = useState<MarketStatsResponse>()
@ -40,8 +42,8 @@ export default function MarketStats(): ReactElement {
} }
} }
// Update every 10 sec. when in viewport // Update periodically when in viewport
const interval = setInterval(getStats, 10000) const interval = setInterval(getStats, refreshInterval)
if (!inView) { if (!inView) {
clearInterval(interval) clearInterval(interval)

View File

@ -41,7 +41,7 @@ const contentQuery = graphql`
} }
` `
const refreshInterval = 10000 // 10 sec. const refreshInterval = 15000 // 15 sec.
export default function Pool({ ddo }: { ddo: DDO }): ReactElement { export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const data = useStaticQuery(contentQuery) const data = useStaticQuery(contentQuery)

View File

@ -4,7 +4,7 @@ import { DDO } from '@oceanprotocol/lib'
import FormTrade from './FormTrade' import FormTrade from './FormTrade'
import TokenBalance from '../../../../@types/TokenBalance' import TokenBalance from '../../../../@types/TokenBalance'
const refreshInterval = 6000 // 6 sec, if the interval is bellow 3-5 seconds the price will be 0 all the time const refreshInterval = 10000 // 10 sec, if the interval is bellow 3-5 seconds the price will be 0 all the time
export default function Trade({ ddo }: { ddo: DDO }): ReactElement { export default function Trade({ ddo }: { ddo: DDO }): ReactElement {
const { ocean, balance, accountId, networkId, refreshBalance } = useOcean() const { ocean, balance, accountId, networkId, refreshBalance } = useOcean()

View File

@ -15,6 +15,8 @@ import { DDO } from '@oceanprotocol/lib'
import Price from './Price' import Price from './Price'
import Decimal from 'decimal.js' import Decimal from 'decimal.js'
const refreshInterval = 10000 // 10 sec.
export default function Dynamic({ export default function Dynamic({
ddo, ddo,
content content
@ -74,7 +76,7 @@ export default function Dynamic({
if (!account) return if (!account) return
refreshBalance() refreshBalance()
const balanceInterval = setInterval(() => refreshBalance(), 10000) // 10 sec. const balanceInterval = setInterval(() => refreshBalance(), refreshInterval)
return () => { return () => {
clearInterval(balanceInterval) clearInterval(balanceInterval)

View File

@ -50,7 +50,7 @@ export default function PageTemplateAssetDetails({
init() init()
// Periodically try to get DDO when not present yet // Periodically try to get DDO when not present yet
const timer = !ddo && setInterval(() => init(), 2000) const timer = !ddo && setInterval(() => init(), 5000)
return () => clearInterval(timer) return () => clearInterval(timer)
}, [ddo, did, config.metadataCacheUri]) }, [ddo, did, config.metadataCacheUri])

View File

@ -21,6 +21,8 @@ const initialData: PricesValue = {
btc: 0.0 btc: 0.0
} }
const refreshInterval = 120000 // 120 sec.
const PricesContext = createContext(null) const PricesContext = createContext(null)
export default function PricesProvider({ export default function PricesProvider({
@ -43,7 +45,7 @@ export default function PricesProvider({
// Fetch new prices periodically with swr // Fetch new prices periodically with swr
useSWR(url, fetchData, { useSWR(url, fetchData, {
refreshInterval: 60000, // 60 sec. refreshInterval,
onSuccess onSuccess
}) })