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

more ComputeJobs refactor

This commit is contained in:
Matthias Kretschmann 2021-09-01 15:15:25 +02:00
parent e998dc777a
commit e3900e8326
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 13 additions and 20 deletions

View File

@ -473,11 +473,7 @@ export default function Compute({
</footer> </footer>
{accountId && ( {accountId && (
<AssetActionHistoryTable title="Your Compute Jobs"> <AssetActionHistoryTable title="Your Compute Jobs">
<ComputeJobs <ComputeJobs minimal />
minimal
assetDTAddress={ddo.dataTokenInfo.address}
chainId={ddo.chainId}
/>
</AssetActionHistoryTable> </AssetActionHistoryTable>
)} )}
</> </>

View File

@ -15,6 +15,7 @@ import { getOceanConfig } from '../../../../../utils/ocean'
import NetworkName from '../../../../atoms/NetworkName' import NetworkName from '../../../../atoms/NetworkName'
import { getComputeJobs } from './utils' import { getComputeJobs } from './utils'
import styles from './index.module.css' import styles from './index.module.css'
import { useAsset } from '../../../../../providers/Asset'
export function Status({ children }: { children: string }): ReactElement { export function Status({ children }: { children: string }): ReactElement {
return <div className={styles.status}>{children}</div> return <div className={styles.status}>{children}</div>
@ -68,16 +69,13 @@ const columns = [
] ]
export default function ComputeJobs({ export default function ComputeJobs({
minimal, minimal
assetDTAddress,
chainId
}: { }: {
minimal?: boolean minimal?: boolean
assetDTAddress?: string
chainId?: number
}): ReactElement { }): ReactElement {
const { ocean, account, config, connect } = useOcean() const { ocean, account, config, connect } = useOcean()
const { accountId, networkId } = useWeb3() const { accountId, networkId } = useWeb3()
const { ddo } = useAsset()
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([]) const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
@ -104,10 +102,9 @@ export default function ComputeJobs({
setIsLoading(true) setIsLoading(true)
const jobs = await getComputeJobs( const jobs = await getComputeJobs(
accountId, ddo?.dataTokenInfo?.address,
assetDTAddress,
chainIds, chainIds,
chainId, ddo?.chainId,
config, config,
ocean, ocean,
account account
@ -118,7 +115,7 @@ export default function ComputeJobs({
} finally { } finally {
setIsLoading(false) setIsLoading(false)
} }
}, [account, accountId, assetDTAddress, chainIds, chainId, config, ocean]) }, [account, accountId, chainIds, ddo, config, ocean])
useEffect(() => { useEffect(() => {
fetchJobs() fetchJobs()
@ -126,7 +123,7 @@ export default function ComputeJobs({
return accountId ? ( return accountId ? (
<> <>
{jobs.length <= 0 || minimal || ( {(jobs?.length || !minimal) && (
<Button <Button
style="text" style="text"
size="small" size="small"

View File

@ -89,7 +89,6 @@ async function getAssetMetadata(
} }
export async function getComputeJobs( export async function getComputeJobs(
accountId: string,
assetDTAddress: string, assetDTAddress: string,
chainIds: number[], chainIds: number[],
chainId: number, chainId: number,
@ -99,12 +98,13 @@ export async function getComputeJobs(
): Promise<ComputeJobMetaData[]> { ): Promise<ComputeJobMetaData[]> {
const variables = assetDTAddress const variables = assetDTAddress
? { ? {
user: accountId?.toLowerCase(), user: account?.getId().toLowerCase(),
datatokenAddress: assetDTAddress.toLowerCase() datatokenAddress: assetDTAddress.toLowerCase()
} }
: { : {
user: accountId?.toLowerCase() user: account?.getId().toLowerCase()
} }
const result = await fetchDataForMultipleChains( const result = await fetchDataForMultipleChains(
assetDTAddress ? getComputeOrdersByDatatokenAddress : getComputeOrders, assetDTAddress ? getComputeOrdersByDatatokenAddress : getComputeOrders,
variables, variables,
@ -112,8 +112,8 @@ export async function getComputeJobs(
) )
let data: TokenOrder[] = [] let data: TokenOrder[] = []
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
if (!result[i].tokenOrders) continue if (!result[i]?.tokenOrders) continue
result[i].tokenOrders.forEach((tokenOrder: TokenOrder) => { result[i]?.tokenOrders.forEach((tokenOrder: TokenOrder) => {
data.push(tokenOrder) data.push(tokenOrder)
}) })
} }