-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2304 from webb-tools/linh/overview-service-table
feat(tangle-dapp): Integrate backend on Active Service table on Overview page
- Loading branch information
Showing
6 changed files
with
76 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import ServiceOverviewContext from '../../context/ServiceOverviewContext'; | ||
|
||
export default function ServiceDetailsLayout({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) { | ||
return <ServiceOverviewContext>{children}</ServiceOverviewContext>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client'; | ||
|
||
import { Option } from '@polkadot/types'; | ||
import { TanglePrimitivesJobsJobInfo } from '@polkadot/types/lookup'; | ||
import { createContext, FC, PropsWithChildren, useCallback } from 'react'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import usePolkadotApiRx from '../hooks/usePolkadotApiRx'; | ||
import { Service } from '../types'; | ||
import { extractServiceDetails } from '../utils/polkadot/services'; | ||
|
||
export const ServiceOverviewContext = createContext<{ | ||
services: Service[]; | ||
isLoading: boolean; | ||
}>({ | ||
services: [], | ||
isLoading: true, | ||
}); | ||
|
||
const ServiceOverviewProvider: FC<PropsWithChildren> = ({ children }) => { | ||
const { data: services, isLoading } = usePolkadotApiRx( | ||
useCallback((api) => { | ||
return api.query.jobs.submittedJobs.entries().pipe( | ||
map((jobsData) => | ||
jobsData | ||
.map(([key, job]) => { | ||
const id = key.args[1].toString(); | ||
const service = extractServiceDetails( | ||
id, | ||
job as Option<TanglePrimitivesJobsJobInfo> | ||
); | ||
return service; | ||
}) | ||
.filter((service): service is Service => service !== null) | ||
) | ||
); | ||
}, []) | ||
); | ||
|
||
return ( | ||
<ServiceOverviewContext.Provider | ||
value={{ services: services ?? [], isLoading }} | ||
> | ||
{children} | ||
</ServiceOverviewContext.Provider> | ||
); | ||
}; | ||
|
||
export default ServiceOverviewProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { default as useActiveServices } from './useActiveServices'; | ||
export { default as useServiceOverview } from './useServiceOverview'; |
51 changes: 0 additions & 51 deletions
51
apps/tangle-dapp/data/serviceOverview/useActiveServices.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use client'; | ||
|
||
import { useContext } from 'react'; | ||
|
||
import { ServiceOverviewContext } from '../../context/ServiceOverviewContext'; | ||
|
||
export default function useServiceOverview() { | ||
return useContext(ServiceOverviewContext); | ||
} |