Skip to content

Commit

Permalink
fix: add archived state on project page (#4244)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomquirk authored Feb 1, 2024
1 parent 8fe5fdc commit e727f93
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 115 deletions.
3 changes: 0 additions & 3 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,3 @@ DB_PROJECTS_WEBHOOK_URL=
# Discord Webhook URL for /contact page.
CONTACT_WEBHOOK_URL=

# Github access token (for project archival requests)
GITHUB_ACCESS_TOKEN=

15 changes: 2 additions & 13 deletions src/components/Project/ArchiveProject.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { t, Trans } from '@lingui/macro'
import { Button, Statistic } from 'antd'
import axios from 'axios'
import { Callout } from 'components/Callout/Callout'
import { PV_V1, PV_V2 } from 'constants/pv'
import { ProjectMetadataContext } from 'contexts/shared/ProjectMetadataContext'
Expand Down Expand Up @@ -65,17 +64,6 @@ export function ArchiveProject({
return emitErrorNotification(t`Failed to update project metadata`)
}

// Create github issue when archive is requested
// https://docs.github.com/en/rest/reference/issues#create-an-issue
// Do this first, in case the user closes the page before the on-chain tx completes
axios.post(`/api/github/archive-project`, {
archived,
projectId,
projectMetadata,
handle,
pv,
})

const txSuccessful = await storeCidTx(
{ cid: uploadedMetadata.Hash },
{
Expand All @@ -87,8 +75,9 @@ export function ArchiveProject({
},
)
if (!txSuccessful) {
emitErrorNotification(t`Transaction unsuccessful`)
emitErrorNotification(t`Failed to update project metadata`)
setIsLoadingArchive(false)
return
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Cog6ToothIcon } from '@heroicons/react/24/outline'
import { Trans } from '@lingui/macro'
import { Button, Divider } from 'antd'
import { Badge } from 'components/Badge'
import { DomainBadge } from 'components/DomainBadge'
import EthereumAddress from 'components/EthereumAddress'
import { GnosisSafeBadge } from 'components/Project/ProjectHeader/GnosisSafeBadge'
Expand All @@ -23,8 +24,16 @@ import { Subtitle } from './components/Subtitle'
import ToolsDrawerButton from './components/ToolsDrawerButton'

export const ProjectHeader = ({ className }: { className?: string }) => {
const { title, subtitle, domain, projectId, handle, owner, gnosisSafe } =
useProjectHeader()
const {
title,
subtitle,
domain,
projectId,
handle,
owner,
gnosisSafe,
archived,
} = useProjectHeader()
const isMobile = useMobile()
const canReconfigure = useV2V3WalletHasPermission(
V2V3OperatorPermission.RECONFIGURE,
Expand Down Expand Up @@ -72,7 +81,9 @@ export const ProjectHeader = ({ className }: { className?: string }) => {
</h1>
<DomainBadge domain={domain} projectId={projectId} />
</div>

<div className="flex">
{archived ? <Badge variant="warning">Archived</Badge> : null}
</div>
<div className="flex flex-col justify-between gap-8 md:flex-row md:gap-12">
<div className="flex min-w-0 flex-col gap-3">
{subtitle &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const MOCK_PROJECT_HEADER_DATA: ProjectHeaderData = {
totalVolume: BigNumber.from(420),
last7DaysPercent: 69,
gnosisSafe: undefined,
archived: false,
}

describe('ProjectHeaderStats', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ProjectHeaderData {
totalVolume: BigNumber | undefined
last7DaysPercent: number
gnosisSafe: GnosisSafe | undefined | null
archived: boolean | undefined
}

export const useProjectHeader = (): ProjectHeaderData => {
Expand Down Expand Up @@ -48,5 +49,6 @@ export const useProjectHeader = (): ProjectHeaderData => {
totalVolume,
last7DaysPercent,
gnosisSafe,
archived: projectMetadata?.archived,
}
}
10 changes: 10 additions & 0 deletions src/hooks/v2v3/usePayProjectDisabled.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { t } from '@lingui/macro'
import { useProjectContext } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectContext'
import { useProjectIsOFACListed } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectIsOFACListed'
import { useProjectMetadataContext } from 'contexts/shared/ProjectMetadataContext'
import { useV2V3BlockedProject } from './useBlockedProject'

export enum PayDisabledReason {
Expand All @@ -23,6 +24,7 @@ export function usePayProjectDisabled(): {
reason: PayDisabledReason | undefined
message: string | undefined
} {
const { projectMetadata } = useProjectMetadataContext()
const { fundingCycleMetadata, loading } = useProjectContext()
const isBlockedProject = useV2V3BlockedProject()
const { isAddressListedInOFAC, isLoading: isOFACLoading } =
Expand Down Expand Up @@ -61,6 +63,14 @@ export function usePayProjectDisabled(): {
}
}

if (projectMetadata?.archived) {
return {
...disabled,
reason: PayDisabledReason.BLOCKED,
message: t`This project has been archived and can't be paid.`,
}
}

return {
payDisabled: false,
loading: false,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/supabase/projects/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function dbpLog(

// log the error to the console
if (type === 'alert') {
logger.error({ data: { type, message: DBP_ALERTS[opts.alert] } })
logger.error({ data: { type, message: DBP_ALERTS[opts.alert], body } })
} else {
logger.info({ data: { type, message: DBP_NOTIFS[opts.notif] } })
}
Expand Down
6 changes: 3 additions & 3 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ msgstr ""
msgid "Juicebox loading animation"
msgstr ""

msgid "This project has been archived and can't be paid."
msgstr ""

msgid "Payments to this project paused"
msgstr ""

Expand Down Expand Up @@ -4691,9 +4694,6 @@ msgstr ""
msgid "Potential risks"
msgstr ""

msgid "Transaction unsuccessful"
msgstr ""

msgid "All-in-one crowdfunding with powerful treasury management and redemptions."
msgstr ""

Expand Down
82 changes: 0 additions & 82 deletions src/pages/api/github/archive-project.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/pages/api/ipfs/[cid].ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (!req) {
res.status(500).end()
}
if (req.method !== 'GET') {
return res.status(405).end()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { Database } from 'types/database.types'
import { getProjectMetadata } from 'utils/server/metadata'

/**
* Force refresh a given project's metadata in the database.
*/
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method !== 'PUT') {
return res.status(405).end()
}

try {
const { projectId, pv } = req.query
if (!projectId || !pv) {
return res.status(400).json({ error: 'projectId is required' })
}

const supabase = createServerSupabaseClient<Database>({ req, res })

const metadata = await getProjectMetadata(projectId as string)
await supabase
.from('projects')
.update({ archived: metadata?.archived }) // TODO add more
.eq('id', projectId)

return res.status(204).end()
} catch (error) {
return res.status(500).end()
}
}
export default handler
2 changes: 1 addition & 1 deletion src/pages/api/nextjs/revalidate-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default async function handler(

// Update database projects whenever a project needs revalidating. However, database will only get updated if the new project data is already available in the subgraph, which can sometimes take a couple minutes
await axios
.get('/api/projects/update')
.get(`${process.env.NEXT_PUBLIC_BASE_URL}api/projects/update`)
// can throw error when env isnt set correctly
.catch(err => console.error('Database projects update failed', err))

Expand Down
9 changes: 0 additions & 9 deletions src/pages/api/projects/update-retry-ipfs.ts

This file was deleted.

0 comments on commit e727f93

Please sign in to comment.