Skip to content

Commit

Permalink
Merge branch 'dev' into v4-edit-cycle-review-3
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyd-eth authored Aug 30, 2024
2 parents 495f91d + 74c8519 commit 059030d
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NEXT_PUBLIC_SUBGRAPH_URL=
SUBGRAPH_URL=

# wallet connect
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=

##### Variables for complete functionality #####

Expand Down
81 changes: 61 additions & 20 deletions src/components/VolumeChart/hooks/useProjectTimeline.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { useQuery } from '@tanstack/react-query'
import { PV_V4 } from 'constants/pv'
import { PV_V2, PV_V4 } from 'constants/pv'
import { readProvider } from 'constants/readProvider'
import EthDater from 'ethereum-block-by-date'
import { ProjectTlQuery, useProjectTlQuery } from 'generated/graphql'
import {
ProjectTlQuery,
useProjectsQuery,
useProjectTlQuery,
} from 'generated/graphql'
import { client } from 'lib/apollo/client'
import { PV } from 'models/pv'
import { ProjectTlDocument } from 'packages/v4/graphql/client/graphql'
Expand All @@ -11,6 +15,8 @@ import { useMemo } from 'react'
import { wadToFloat } from 'utils/format/formatNumber'
import { getSubgraphIdForProject } from 'utils/graph'
import { daysToMS, minutesToMS } from 'utils/units'
import { RomanStormVariables } from 'constants/romanStorm'

import { ProjectTimelinePoint, ProjectTimelineRange } from '../types'

const COUNT = 30
Expand All @@ -24,6 +30,25 @@ export function useProjectTimeline({
pv: PV
range: ProjectTimelineRange
}) {
const exceptionTimestamp = useMemo(() => {
return RomanStormVariables.PROJECT_ID === projectId
? RomanStormVariables.SNAPSHOT_TIMESTAMP
: null
}, [projectId])

const { data: romanStormData } = useProjectsQuery({
client,
fetchPolicy: 'no-cache',
skip: projectId !== RomanStormVariables.PROJECT_ID,
variables: {
where: {
projectId,
pv: PV_V2,
},
block: { number: RomanStormVariables.SNAPSHOT_BLOCK },
},
})

const { data: blockData, isLoading: isLoadingBlockNumbers } = useQuery({
queryKey: ['block-numbers', range],
queryFn: async () => {
Expand Down Expand Up @@ -70,22 +95,23 @@ export function useProjectTimeline({
return { blocks, timestamps }
}, [blockData])

const { data: v1v2v3QueryResult, loading: isLoadingQuery } = useProjectTlQuery({
client,
variables: {
id: blocks ? getSubgraphIdForProject(pv, projectId) : '',
...blocks,
},
skip: pv === PV_V4
})
const { data: v1v2v3QueryResult, loading: isLoadingQuery } =
useProjectTlQuery({
client,
variables: {
id: blocks ? getSubgraphIdForProject(pv, projectId) : '',
...blocks,
},
skip: pv === PV_V4,
})

const { data: v4QueryResult } = useSubgraphQuery({
document: ProjectTlDocument,
document: ProjectTlDocument,
variables: {
id: blocks ? projectId.toString() : '',
...blocks,
},
enabled: pv === PV_V4
enabled: pv === PV_V4,
})

const points = useMemo(() => {
Expand All @@ -95,16 +121,31 @@ export function useProjectTimeline({
const points: ProjectTimelinePoint[] = []

for (let i = 0; i < COUNT; i++) {
const point = (queryResult as ProjectTlQuery)[`p${i}` as keyof typeof queryResult]
const point = (queryResult as ProjectTlQuery)[
`p${i}` as keyof typeof queryResult
]

if (!point) continue

points.push({
timestamp: timestamps[i],
trendingScore: wadToFloat(point.trendingScore),
balance: wadToFloat(point.currentBalance),
volume: wadToFloat(point.volume),
})
if (exceptionTimestamp && exceptionTimestamp > timestamps[i]) {
points.push({
timestamp: timestamps[i],
trendingScore: 0,
balance: 0,
volume: 0,
})
} else {
const volume =
projectId === RomanStormVariables.PROJECT_ID
? point.volume.sub(romanStormData?.projects[0].volume || 0)
: point.volume

points.push({
timestamp: timestamps[i],
trendingScore: wadToFloat(point.trendingScore),
balance: wadToFloat(point.currentBalance),
volume: wadToFloat(volume),
})
}
}

return points
Expand Down
9 changes: 9 additions & 0 deletions src/constants/romanStorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const PROJECT_ID = 618
const SNAPSHOT_BLOCK = 20229376
const SNAPSHOT_TIMESTAMP = 1720050599

export const RomanStormVariables = {
PROJECT_ID,
SNAPSHOT_BLOCK,
SNAPSHOT_TIMESTAMP,
}
3 changes: 2 additions & 1 deletion src/graphql/projects/projects.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ query Projects(
$skip: Int,
$orderBy: Project_orderBy
$orderDirection: OrderDirection
$block: Block_height
) {
projects(where: $where, first: $first, skip: $skip) {
projects(where: $where, first: $first, skip: $skip, block: $block) {
id
projectId
metadataUri
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/projects/trendingProjects.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ query TrendingProjects(
$skip: Int
$orderBy: Project_orderBy
$orderDirection: OrderDirection
$block: Block_height
) {
projects(
where: $where
first: $first
skip: $skip
orderBy: $orderBy
orderDirection: desc
block: $block
) {
id
projectId
Expand Down
15 changes: 14 additions & 1 deletion src/hooks/useProjectEvents.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useMemo } from 'react'

import {
OrderDirection,
ProjectEvent_OrderBy,
useProjectEventsQuery
useProjectEventsQuery,
} from 'generated/graphql'
import { client } from 'lib/apollo/client'
import { ProjectEventsQueryArgs } from 'models/projectEvents'
import { RomanStormVariables } from 'constants/romanStorm'

export function useProjectEvents({
filter,
Expand All @@ -14,6 +17,13 @@ export function useProjectEvents({
first,
skip,
}: ProjectEventsQueryArgs) {
const projectSnapshotTimestamp = useMemo(() => {
if (projectId === RomanStormVariables.PROJECT_ID) {
return RomanStormVariables.SNAPSHOT_TIMESTAMP
}
return null
}, [projectId])

return useProjectEventsQuery({
client,
variables: {
Expand All @@ -27,6 +37,9 @@ export function useProjectEvents({
where: {
...(pv ? { pv } : {}),
...(projectId ? { projectId } : {}),
...(projectSnapshotTimestamp
? { timestamp_gt: projectSnapshotTimestamp }
: {}),
...(from
? {
// subgraph needs addresses to be lowercased
Expand Down
38 changes: 30 additions & 8 deletions src/packages/v2v3/contexts/Project/useV2V3ProjectState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PV_V2 } from 'constants/pv'
import { RomanStormVariables } from 'constants/romanStorm'
import {
ETH_PAYOUT_SPLIT_GROUP,
RESERVED_TOKEN_SPLIT_GROUP,
Expand Down Expand Up @@ -95,14 +96,35 @@ export function useV2V3ProjectState({ projectId }: { projectId: number }) {
},
})

const projects = data?.projects
const projectStatsData = first(projects)
const {
createdAt,
volume: totalVolume,
trendingVolume,
paymentsCount,
} = projectStatsData ?? {}
const { data: romanStormData } = useProjectsQuery({
client,
fetchPolicy: 'no-cache',
skip: projectId !== RomanStormVariables.PROJECT_ID,
variables: {
where: {
projectId,
pv: PV_V2,
},
block: { number: RomanStormVariables.SNAPSHOT_BLOCK },
},
})

const projectStatsData = first(data?.projects)
const projectRomanStormStatsData = first(romanStormData?.projects)

let totalVolume = projectStatsData?.volume
let paymentsCount = projectStatsData?.paymentsCount ?? 0

if (projectId === RomanStormVariables.PROJECT_ID && projectStatsData) {
const BIG_ZERO = BigNumber.from(0)

totalVolume = (totalVolume || BIG_ZERO).sub(
projectRomanStormStatsData?.volume || BIG_ZERO,
)
paymentsCount -= projectRomanStormStatsData?.paymentsCount ?? 0
}

const { createdAt, trendingVolume } = projectStatsData ?? {}

/**
* Load funding cycle data
Expand Down
4 changes: 2 additions & 2 deletions src/packages/v4/graphql/queries/project.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query Projects($where: Project_filter, $first: Int, $skip: Int) {
projects(where: $where, first: $first, skip: $skip) {
query Projects($where: Project_filter, $first: Int, $skip: Int, $block: Block_height) {
projects(where: $where, first: $first, skip: $skip, block: $block) {
projectId
metadata
handle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export default function CycleDeadlineDropdown({
return (
<Form.Item name="approvalHook" required>
<Select className={className}>
{[{ name: '1 day @todo', address: '0x00'}].map((strategy: BallotStrategy) => (
<Select.Option key={strategy.address} value={strategy.address}>
<Trans>{strategy.name}</Trans>
</Select.Option>
))}
{[{ name: '1 day @todo', address: '0x00' }].map(
(strategy: BallotStrategy) => (
<Select.Option key={strategy.address} value={strategy.address}>
<Trans>{strategy.name}</Trans>
</Select.Option>
),
)}
</Select>
</Form.Item>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ export function EditCyclePage() {
</Link>
) : null}
{/* <Tooltip title={error}> */}
<Button
type="primary"
onClick={() => setConfirmModalOpen(true)}
disabled={false}//Boolean(error)}
>
<Trans>Save changes</Trans>
</Button>
<Button
type="primary"
onClick={() => setConfirmModalOpen(true)}
disabled={false} //Boolean(error)}
>
<Trans>Save changes</Trans>
</Button>
{/* </Tooltip> */}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ export function ProjectSettingsContent({
}: {
settingsPageKey: SettingsPageKey
}) {

const ActiveSettingsPage = useMemo(
() => SettingsPageComponents[settingsPageKey],
[settingsPageKey],
)

// const hasExistingNfts = !isZeroAddress(fundingCycleMetadata?.dataSource)
const pageTitle =
V4SettingsPageKeyTitleMap(false)[settingsPageKey]
const pageTitle = V4SettingsPageKeyTitleMap(false)[settingsPageKey]

return (
<ProjectSettingsLayout>
Expand Down
44 changes: 43 additions & 1 deletion src/pages/api/projects/trending.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { PV_V1, PV_V2 } from 'constants/pv'
import { RomanStormVariables } from 'constants/romanStorm'
import { BigNumber } from 'ethers'
import {
OrderDirection,
Project_OrderBy,
Expand Down Expand Up @@ -47,11 +49,51 @@ const handler: NextApiHandler = async (req, res) => {
},
})

const projects = [...projectsRes.data.projects]

try {
const romanProjectIndex = projects.findIndex(
el => el.projectId === RomanStormVariables.PROJECT_ID && el.pv === '2',
)

if (romanProjectIndex >= 0) {
const filteredProjects = await serverClient.query<
TrendingProjectsQuery,
QueryProjectsArgs
>({
fetchPolicy: 'no-cache',
query: TrendingProjectsDocument,
variables: {
where: {
pv: '2',
projectId: RomanStormVariables.PROJECT_ID,
},
block: {
number: RomanStormVariables.SNAPSHOT_BLOCK,
},
},
})

const [romanProjectSnapshot] = filteredProjects.data.projects
const romanProject = projects[romanProjectIndex]

projects[romanProjectIndex] = {
...projects[romanProjectIndex],
volume: BigNumber.from(romanProject.volume ?? 0).sub(
BigNumber.from(romanProjectSnapshot.volume ?? 0),
), // Incorrect types are declared
paymentsCount:
romanProject.paymentsCount - romanProjectSnapshot.paymentsCount,
}
}
} catch {}

res.setHeader(
'Cache-Control',
`s-maxage=${CACHE_MAXAGE}, stale-while-revalidate`,
)
return res.status(200).json(projectsRes.data.projects)

return res.status(200).json(projects)
} catch (e) {
console.error(e)
return res.status(500).json({ error: 'Something went wrong' })
Expand Down

0 comments on commit 059030d

Please sign in to comment.