Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev blocked projects and block Metakeys copy-cat #4067

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/ProjectDashboard/ProjectDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Footer } from 'components/Footer'
import { TransactionProvider } from 'contexts/Transaction/TransactionProvider'
import { useHasNftRewards } from 'hooks/JB721Delegate/useHasNftRewards'
import { twMerge } from 'tailwind-merge'
import { BlockedProjectBanner } from './components/BlockedProjectBanner'
import { Cart } from './components/Cart'
import { CoverPhoto } from './components/CoverPhoto'
import { CurrentBalanceCard } from './components/CurrentBalanceCard'
Expand Down Expand Up @@ -35,6 +36,7 @@ export const ProjectDashboard = () => {
<div className="flex w-full justify-center md:px-6">
<div className="flex w-full max-w-6xl flex-col">
<ProjectHeader className="mt-12 px-4 md:mt-4 md:px-0" />
<BlockedProjectBanner className="mt-10" />
<div
className={twMerge(
'mt-10 flex w-full flex-col gap-4 px-4 md:flex-row md:px-0',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Trans } from '@lingui/macro'
import Banner from 'components/Banner'
import ExternalLink from 'components/ExternalLink'
import { useV2BlockedProject } from 'hooks/useBlockedProject'

export function BlockedProjectBanner({ className }: { className?: string }) {
const isBlockedProject = useV2BlockedProject()
if (!isBlockedProject) return null

const delistingPolicyLink =
'https://github.com/peeldao/proposals/pull/42/files'
const discordLink = 'https://discord.gg/wFTh4QnDzk'

return (
<div className={className}>
<Banner
title={<Trans>Delisted project</Trans>}
body={
<Trans>
This project has been <strong>delisted</strong> for breaching our{' '}
<ExternalLink href={delistingPolicyLink}>policy</ExternalLink>.{' '}
<ExternalLink href={discordLink}>Get in touch</ExternalLink>.
</Trans>
}
variant="warning"
/>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Trans, t } from '@lingui/macro'
import { Button, Tooltip } from 'antd'
import { usePayProjectCard } from 'components/ProjectDashboard/hooks'
import { Formik } from 'formik'
import { useV2BlockedProject } from 'hooks/useBlockedProject'
import { V2V3CurrencyOption } from 'models/v2v3/currencyOption'
import { twMerge } from 'tailwind-merge'
import { V2V3_CURRENCY_ETH } from 'utils/v2v3/currency'
Expand All @@ -14,6 +15,8 @@ import { PayInput } from './components/PayInput'
import { TokensPerEth } from './components/TokensPerEth'

export const PayProjectCard = ({ className }: { className?: string }) => {
const isBlockedProject = useV2BlockedProject()

const { validationSchema, paymentsPaused, addPay } = usePayProjectCard()
const determiningIfProjectCanReceivePayments = paymentsPaused === undefined

Expand Down Expand Up @@ -74,7 +77,7 @@ export const PayProjectCard = ({ className }: { className?: string }) => {
>
<Button
loading={determiningIfProjectCanReceivePayments}
disabled={paymentsPaused}
disabled={paymentsPaused || isBlockedProject}
htmlType="submit"
className="h-12 text-base"
style={{ height: '48px' }}
Expand Down
16 changes: 16 additions & 0 deletions src/constants/blocklist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NetworkName } from 'models/networkName'
import { readNetwork } from './networks'

const PROJECT_IDS = {
METAKEYS_COPYCAT: 564, // copycat of 563
}

// List of delisted projects
const V2_BLOCKLISTED_PROJECT_IDS_BY_NETWORK: Partial<
Record<NetworkName, number[]>
> = {
[NetworkName.mainnet]: [PROJECT_IDS.METAKEYS_COPYCAT],
}

export const V2_BLOCKLISTED_PROJECT_IDS =
V2_BLOCKLISTED_PROJECT_IDS_BY_NETWORK[readNetwork.name] ?? []
12 changes: 12 additions & 0 deletions src/hooks/useBlockedProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { V2_BLOCKLISTED_PROJECT_IDS } from 'constants/blocklist'
import { PV_V2 } from 'constants/pv'
import { ProjectMetadataContext } from 'contexts/shared/ProjectMetadataContext'
import { useContext } from 'react'

export const useV2BlockedProject = () => {
const { projectId, pv } = useContext(ProjectMetadataContext)
const isBlockedProject = projectId
? V2_BLOCKLISTED_PROJECT_IDS.includes(projectId) && pv === PV_V2
: false
return isBlockedProject
}
15 changes: 12 additions & 3 deletions src/hooks/useProjects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import axios from 'axios'
import { V2_BLOCKLISTED_PROJECT_IDS } from 'constants/blocklist'
import { PV_V2 } from 'constants/pv'
import { BigNumber } from 'ethers'
import { DBProject, DBProjectQueryOpts, DBProjectRow } from 'models/dbProject'
import { Json } from 'models/json'
Expand All @@ -14,6 +16,11 @@ import { parseDBProject, parseDBProjectJson } from 'utils/sgDbProjects'

const DEFAULT_STALE_TIME = 60 * 1000 // 60 seconds

// Filter applied to all DB project query results
// TODO this could be applied at the /api/projects level, but would take some more finessing. we're working quick here
const dbProjectFilter: (p: DBProject) => boolean = (p: DBProject) =>
!(p.pv === PV_V2 && V2_BLOCKLISTED_PROJECT_IDS.includes(p.projectId))

export function useDBProjectsQuery(
opts: DBProjectQueryOpts | null,
reactQueryOptions?: UseQueryOptions<
Expand All @@ -36,7 +43,7 @@ export function useDBProjectsQuery(
.get<Json<DBProjectRow>[]>(
`/api/projects?${formatQueryParams(opts)}`,
)
.then(res => res.data?.map(parseDBProject))
.then(res => res.data?.map(parseDBProject).filter(dbProjectFilter))
: Promise.resolve([] as DBProject[]),
{
staleTime: DEFAULT_STALE_TIME,
Expand Down Expand Up @@ -68,7 +75,9 @@ export function useDBProjectsInfiniteQuery(
pageSize,
})}`,
)
.then(res => (res.data ? res.data.map(parseDBProject) : []))
.then(res =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds filters to "all" (same as the "new" query) and "trending" projects queries

res.data ? res.data.map(parseDBProject).filter(dbProjectFilter) : [],
)
},
{
staleTime: DEFAULT_STALE_TIME,
Expand All @@ -93,7 +102,7 @@ export function useTrendingProjects(count: number) {
'/api/projects/trending?count=' + count,
)

return res.data.map(parseDBProjectJson)
return res.data.map(parseDBProjectJson).filter(dbProjectFilter)
})
}

Expand Down
6 changes: 6 additions & 0 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,9 @@ msgstr ""
msgid "Custom strategy"
msgstr ""

msgid "Delisted project"
msgstr ""

msgid "If you use the default governance option (no governance), the voting weight will still be accessible on the blockchain for use in Snapshot strategies or any other desired purpose."
msgstr ""

Expand Down Expand Up @@ -3932,6 +3935,9 @@ msgstr ""
msgid "Duration"
msgstr ""

msgid "This project has been <0>delisted</0> for breaching our <1>policy</1>. <2>Get in touch</2>."
msgstr ""

msgid "Supporters will be sent to this page if they click the button on your pop-up. You can preview this below."
msgstr ""

Expand Down
Loading