Skip to content

Commit

Permalink
Support chain_id property on all sg/db projects
Browse files Browse the repository at this point in the history
  • Loading branch information
aeolianeth committed Sep 18, 2024
1 parent d0acde4 commit 82f144f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function ProjectCard({
project,
bookmarked,
}: {
project?: SubgraphQueryProject
project?: SubgraphQueryProject & { chainId?: number }
bookmarked?: boolean
}) {
const { data: metadata } = useProjectMetadata(project?.metadataUri)
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function ProjectCard({
: `/p/${handle}`

const projectCardUrl =
pv === PV_V4
pv === PV_V4 && chainId
? v4ProjectRoute({
projectId,
chainId,
Expand Down
10 changes: 8 additions & 2 deletions src/lib/api/supabase/projects/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
QueryProjectsArgs,
} from 'generated/graphql'

import { readNetwork } from 'constants/networks'
import { paginateDepleteQuery } from 'lib/apollo/paginateDepleteQuery'
import { serverClient, v4SepoliaServerClient } from 'lib/apollo/serverClient'
import { DBProject, DBProjectQueryOpts, SGSBCompareKey } from 'models/dbProject'
Expand Down Expand Up @@ -43,7 +44,12 @@ export async function queryAllSGProjectsForServer() {
])

// Response must be retyped with Json<>, because the serverClient does not perform the parsing expected by generated types
const _res = res as unknown as Json<Pick<Project, SGSBCompareKey>>[]
const _res = res.map(p => {
return {
...p,
chainId: readNetwork.chainId,
}
}) as unknown as Json<Pick<Project & { chainId: number }, SGSBCompareKey>>[]
const _resSepoliaV4 = resSepoliaV4.map(p => {
return {
...p,
Expand All @@ -52,7 +58,7 @@ export async function queryAllSGProjectsForServer() {
metadataUri: p.metadata,
chainId: sepolia.id,
}
}) as unknown as Json<Pick<Project, SGSBCompareKey>>[]
}) as unknown as Json<Pick<Project & { chainId: number }, SGSBCompareKey>>[]

return [..._res, ..._resSepoliaV4].map(formatSGProjectForDB)
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/dbProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Database } from 'types/database.types'
import { Project } from 'generated/graphql'
import { ProjectTagName } from './project-tags'
import { PV } from './pv'

export type SGSBCompareKey = Extract<keyof Project, keyof DBProject>
type P = Project & { chainId: number }
export type SGSBCompareKey = Extract<keyof P, keyof DBProject>

/**
* @param text Text to use for string search
Expand Down
4 changes: 3 additions & 1 deletion src/pages/api/projects/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const handler: NextApiHandler = async (_, res) => {
(await paginateDepleteQuery<DbProjectsQuery, QueryProjectsArgs>({
client: serverClient,
document: DbProjectsDocument,
})) as unknown as Json<Pick<Project, SGSBCompareKey>>[]
})) as unknown as Json<
Pick<Project & { chainId: number }, SGSBCompareKey>
>[]
).map(formatSGProjectForDB)

report += `\n\n${dbProjectsCount} projects in database`
Expand Down
9 changes: 5 additions & 4 deletions src/utils/sgDbProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function parseDBProjectsRow(p: DBProjectRow): Json<DBProject> {
paymentsCount: p.payments_count,
projectId: p.project_id,
pv: p.pv as PV,
chainId: p.chain_id,
redeemCount: p.redeem_count,
redeemVolume: p.redeem_volume,
redeemVolumeUSD: p.redeem_voume_usd,
Expand Down Expand Up @@ -152,7 +153,7 @@ export function formatSgProjectsForUpdate({
retryIpfs,
returnAllProjects,
}: {
sgProjects: Json<Pick<Project, SGSBCompareKey>>[]
sgProjects: Json<Pick<Project & { chainId: number }, SGSBCompareKey>>[]
dbProjects: Record<string, Json<DBProject>>
retryIpfs?: boolean
returnAllProjects?: boolean
Expand Down Expand Up @@ -243,7 +244,7 @@ export async function formatWithMetadata({
sgProject,
dbProject,
}: {
sgProject: Json<Pick<Project, SGSBCompareKey>>
sgProject: Json<Pick<Project & { chainId: number }, SGSBCompareKey>>
dbProject:
| Pick<
DBProject,
Expand Down Expand Up @@ -351,8 +352,8 @@ function padBigNumForSort(bn: string) {
}

export function formatSGProjectForDB(
p: Json<Pick<Project, SGSBCompareKey>>,
): Json<Pick<Project, SGSBCompareKey>> {
p: Json<Pick<Project & { chainId: number }, SGSBCompareKey>>,
): Json<Pick<Project & { chainId: number }, SGSBCompareKey>> {
return {
...p,
// Adjust BigNumber values before we compare them to database values
Expand Down

0 comments on commit 82f144f

Please sign in to comment.