11import { TABLE_REFETCH_INTERVAL } from '@/config' ;
22import { useQuery } from '@tanstack/react-query' ;
3+ import { getIExec } from '@/externals/iexecSdkClient' ;
34import { ErrorAlert } from '@/modules/ErrorAlert' ;
45import JsonBlock from '@/modules/JsonBlock' ;
56import useUserStore from '@/stores/useUser.store' ;
67import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey' ;
78
8- function useTaskRawData ( { taskId } : { taskId : string } ) {
9+ function useTaskRawData ( {
10+ taskWorkerpoolId,
11+ taskId,
12+ } : {
13+ taskWorkerpoolId ?: string ;
14+ taskId : string ;
15+ } ) {
916 const { chainId } = useUserStore ( ) ;
1017
11- const queryKey = [ chainId , 'task' , 'raw' , taskId ] ;
18+ const queryKey = [ chainId , 'task' , 'raw' , taskWorkerpoolId , taskId ] ;
19+
1220 const { data, isLoading, isRefetching, isError, errorUpdateCount } = useQuery (
1321 {
1422 queryKey,
1523 queryFn : async ( ) => {
16- const response = await fetch (
17- `https://core-prod.arbitrum-mainnet.iex.ec/tasks/${ taskId } `
24+ const iexec = await getIExec ( ) ;
25+ const apiUrl = await iexec . workerpool . getWorkerpoolApiUrl (
26+ taskWorkerpoolId !
1827 ) ;
28+
29+ const response = await fetch ( `${ apiUrl } /tasks/${ taskId } ` ) ;
1930 if ( ! response . ok ) {
2031 throw new Error ( 'Failed to fetch task raw data' ) ;
2132 }
22- console . log ( response ) ;
23-
2433 return response . json ( ) ;
2534 } ,
2635 refetchInterval : TABLE_REFETCH_INTERVAL ,
2736 placeholderData : createPlaceholderDataFnForQueryKey ( queryKey ) ,
37+ enabled : ! ! taskWorkerpoolId && ! ! taskId ,
2838 }
2939 ) ;
3040
@@ -37,18 +47,32 @@ function useTaskRawData({ taskId }: { taskId: string }) {
3747 } ;
3848}
3949
40- export function TaskRawData ( { taskId } : { taskId : string } ) {
41- const { data : tasks , hasPastError } = useTaskRawData ( { taskId } ) ;
42-
43- // TODO: handle loading state
50+ export function TaskRawData ( {
51+ taskWorkerpoolId,
52+ taskId,
53+ } : {
54+ taskWorkerpoolId ?: string ;
55+ taskId : string ;
56+ } ) {
57+ const {
58+ data : tasks ,
59+ hasPastError,
60+ isLoading,
61+ } = useTaskRawData ( { taskWorkerpoolId, taskId } ) ;
4462
45- return hasPastError && ! tasks . length ? (
46- < ErrorAlert message = "An error occurred during task raw data loading." />
63+ return hasPastError && ( ! tasks || ! tasks . length ) ? (
64+ < ErrorAlert
65+ message = {
66+ "Unable to load raw task data: the workerpool associated with this task doesn't expose a public API"
67+ }
68+ />
4769 ) : (
48- < div className = "dark:bg-tooltip rounded-3xl border bg-[#fafaff] p-6" >
49- < JsonBlock copyText = "Copy all" collapsed = { 5 } >
50- { tasks }
51- </ JsonBlock >
70+ < div className = "dark:bg-tooltip min-h-40 rounded-3xl border bg-[#fafaff] p-6" >
71+ { isLoading ? (
72+ < p > Loading...</ p >
73+ ) : (
74+ < JsonBlock collapsed = { 5 } > { tasks } </ JsonBlock >
75+ ) }
5276 </ div >
5377 ) ;
5478}
0 commit comments