( network: SQNetworks, address: string, ipfsEndpoint = IPFS_NODE_ENDPOINT )
| 25 | export type Project = z.infer<typeof projectSchema>; |
| 26 | |
| 27 | export async function listProjects( |
| 28 | network: SQNetworks, |
| 29 | address: string, |
| 30 | ipfsEndpoint = IPFS_NODE_ENDPOINT |
| 31 | ): Promise<Project[]> { |
| 32 | const res = await getQueryClient(network).query<GetProjectsQuery, GetProjectsQueryVariables>({ |
| 33 | query: GetProjects, |
| 34 | variables: {address: utils.getAddress(address)}, |
| 35 | }); |
| 36 | |
| 37 | if (res.errors) { |
| 38 | throw new Error(`Failed to fetch projects for address ${address}`); |
| 39 | } |
| 40 | |
| 41 | const ipfs = new IPFSHTTPClientLite({url: ipfsEndpoint}); |
| 42 | |
| 43 | const raw = res.data?.projects?.nodes ?? []; |
| 44 | const projects = await Promise.all( |
| 45 | raw.map(async (p) => { |
| 46 | if (!p) return null; |
| 47 | const {__typename, type, ...rest} = p; |
| 48 | |
| 49 | return <Project>{ |
| 50 | ...rest, |
| 51 | type: ProjectType[gqlProjectTypeToProjectType(type)], |
| 52 | meta: await resultToJson(ipfs.cat(p.metadata), true), |
| 53 | }; |
| 54 | }) |
| 55 | ); |
| 56 | |
| 57 | return projects.filter((p): p is Project => p !== null); |
| 58 | } |
no test coverage detected