mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* wagmi + ethers + web3modal setup * refactor wallet components * fallback providers, more config * kick out useWeb3 * remove all useWeb3 imports * more web3.js usage removal * isAddress utils replacement * restore add token / add network * less accountId changes * web3 legacy tinkering, utils/web3 → utils/wallet * legacy web3 object for ocean.js * graph sync fix, remove custom network switching code * package updates, merge fixes * downgrade to ethers v5 * fix project id * switch to ConnectKit * connectkit theming * add existing chains to wagmi * rewrite getPaymentCollector() * kick out getPaymentCollector completely, use wagmi hooks instead * Revert "kick out getPaymentCollector completely, use wagmi hooks instead" This reverts commit 54c7d1ef1a2dec0b1575a685125ba78336b30f59. * switch getPaymentCollector * calcBaseInGivenDatatokensOut reorg * wip integrate ocean lib 3.0.0 * update orbis components to use wagmi instead of web hooks * more oceanjs integration updates * more refactors * fix build * update ocean lib * fix publish * fix order fixed rate * remove logs * debug and stop infinite cycle orbis connect * fix orbis dm connection * mock use network and fix some more tests * mock wagmi switch network * mock wagmi useProvider createClient and connectKit getDefaultClient * fix jest tests * try storybook fix * cleanups and bump ocean lib * fix order * bump lib to next.5 and add more modal style * bump ocean.js lib to 3.0.0 --------- Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
124 lines
3.0 KiB
TypeScript
124 lines
3.0 KiB
TypeScript
import React, { ReactElement, useCallback, useEffect, useState } from 'react'
|
|
import Tabs from '@shared/atoms/Tabs'
|
|
import PublishedList from './PublishedList'
|
|
import Downloads from './Downloads'
|
|
import ComputeJobs from './ComputeJobs'
|
|
import styles from './index.module.css'
|
|
import { getComputeJobs } from '@utils/compute'
|
|
import { useUserPreferences } from '@context/UserPreferences'
|
|
import { useCancelToken } from '@hooks/useCancelToken'
|
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
|
import { useAccount } from 'wagmi'
|
|
|
|
interface HistoryTab {
|
|
title: string
|
|
content: JSX.Element
|
|
}
|
|
|
|
const refreshInterval = 10000 // 10 sec.
|
|
|
|
function getTabs(
|
|
accountId: string,
|
|
userAccountId: string,
|
|
jobs: ComputeJobMetaData[],
|
|
isLoadingJobs: boolean,
|
|
refetchJobs: boolean,
|
|
setRefetchJobs: any
|
|
): HistoryTab[] {
|
|
const defaultTabs: HistoryTab[] = [
|
|
{
|
|
title: 'Published',
|
|
content: <PublishedList accountId={accountId} />
|
|
},
|
|
{
|
|
title: 'Downloads',
|
|
content: <Downloads accountId={accountId} />
|
|
}
|
|
]
|
|
const computeTab: HistoryTab = {
|
|
title: 'Compute Jobs',
|
|
content: (
|
|
<ComputeJobs
|
|
jobs={jobs}
|
|
isLoading={isLoadingJobs}
|
|
refetchJobs={() => setRefetchJobs(!refetchJobs)}
|
|
/>
|
|
)
|
|
}
|
|
if (accountId === userAccountId) {
|
|
defaultTabs.push(computeTab)
|
|
}
|
|
return defaultTabs
|
|
}
|
|
|
|
export default function HistoryPage({
|
|
accountIdentifier
|
|
}: {
|
|
accountIdentifier: string
|
|
}): ReactElement {
|
|
const { address: accountId } = useAccount()
|
|
const { chainIds } = useUserPreferences()
|
|
const newCancelToken = useCancelToken()
|
|
|
|
const url = new URL(location.href)
|
|
const defaultTab = url.searchParams.get('defaultTab')
|
|
|
|
const [refetchJobs, setRefetchJobs] = useState(false)
|
|
const [isLoadingJobs, setIsLoadingJobs] = useState(false)
|
|
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
|
|
|
|
const fetchJobs = useCallback(
|
|
async (type: string) => {
|
|
if (!chainIds || chainIds.length === 0 || !accountId) {
|
|
return
|
|
}
|
|
|
|
try {
|
|
type === 'init' && setIsLoadingJobs(true)
|
|
const computeJobs = await getComputeJobs(
|
|
chainIds,
|
|
accountId,
|
|
null,
|
|
newCancelToken()
|
|
)
|
|
setJobs(computeJobs.computeJobs)
|
|
setIsLoadingJobs(!computeJobs.isLoaded)
|
|
} catch (error) {
|
|
LoggerInstance.error(error.message)
|
|
setIsLoadingJobs(false)
|
|
}
|
|
},
|
|
[accountId, chainIds, isLoadingJobs, newCancelToken]
|
|
)
|
|
|
|
useEffect(() => {
|
|
fetchJobs('init')
|
|
|
|
// init periodic refresh for jobs
|
|
const balanceInterval = setInterval(
|
|
() => fetchJobs('repeat'),
|
|
refreshInterval
|
|
)
|
|
|
|
return () => {
|
|
clearInterval(balanceInterval)
|
|
}
|
|
}, [refetchJobs])
|
|
|
|
const tabs = getTabs(
|
|
accountIdentifier,
|
|
accountId,
|
|
jobs,
|
|
isLoadingJobs,
|
|
refetchJobs,
|
|
setRefetchJobs
|
|
)
|
|
|
|
let defaultTabIndex = 0
|
|
defaultTab === 'ComputeJobs' ? (defaultTabIndex = 4) : (defaultTabIndex = 0)
|
|
|
|
return (
|
|
<Tabs items={tabs} className={styles.tabs} defaultIndex={defaultTabIndex} />
|
|
)
|
|
}
|