Skip to content

Commit

Permalink
cache Roman storm project nfts
Browse files Browse the repository at this point in the history
  • Loading branch information
wraeth-eth committed Jan 24, 2024
1 parent 8a9853b commit 87832f1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Footer } from 'components/Footer/Footer'
import { NftRewardsContext } from 'contexts/NftRewards/NftRewardsContext'
import { TransactionProvider } from 'contexts/Transaction/TransactionProvider'
import { useHasNftRewards } from 'hooks/JB721Delegate/useHasNftRewards'
import { useContext, useMemo } from 'react'
import { twMerge } from 'tailwind-merge'
import { BlockedProjectBanner } from './components/BlockedProjectBanner'
import { Cart } from './components/Cart/Cart'
Expand All @@ -19,7 +20,13 @@ import { useProjectPageQueries } from './hooks/useProjectPageQueries'

export const ProjectDashboard = () => {
const { projectPayReceipt } = useProjectPageQueries()
const { value: hasNftRewards } = useHasNftRewards()
const {
nftRewards: { rewardTiers },
} = useContext(NftRewardsContext)
const hasNftRewards = useMemo(
() => (rewardTiers ?? []).length !== 0,
[rewardTiers],
)

// disable juicecrowd nft rewards
const shouldShowNftCard = hasNftRewards
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tab } from '@headlessui/react'
import { Trans, t } from '@lingui/macro'
import { useProjectPageQueries } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectPageQueries'
import { useHasNftRewards } from 'hooks/JB721Delegate/useHasNftRewards'
import { NftRewardsContext } from 'contexts/NftRewards/NftRewardsContext'
import { useIsUserAddress } from 'hooks/useIsUserAddress'
import { useOnScreen } from 'hooks/useOnScreen'
import {
Expand Down Expand Up @@ -35,7 +35,13 @@ export const ProjectTabs = ({ className }: { className?: string }) => {
const { projectPageTab, setProjectPageTab } = useProjectPageQueries()
const { projectOwnerAddress } = useProjectContext()
const isProjectOwner = useIsUserAddress(projectOwnerAddress)
const { value: hasNftRewards } = useHasNftRewards()
const {
nftRewards: { rewardTiers },
} = useContext(NftRewardsContext)
const hasNftRewards = useMemo(
() => (rewardTiers ?? []).length !== 0,
[rewardTiers],
)

const showNftRewards = hasNftRewards

Expand Down
119 changes: 110 additions & 9 deletions src/contexts/NftRewards/NftRewardsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useNftCollectionMetadataUri } from 'hooks/JB721Delegate/contractReader/
import { useNftCollectionPricingContext } from 'hooks/JB721Delegate/contractReader/useNftCollectionPricingContext'
import { useNftFlagsOf } from 'hooks/JB721Delegate/contractReader/useNftFlagsOf'
import { useNftTiers } from 'hooks/JB721Delegate/contractReader/useNftTiers'
import { JB721GovernanceType } from 'models/nftRewards'
import { useContext } from 'react'
import { JB721GovernanceType, NftRewardTier } from 'models/nftRewards'
import { useContext, useMemo } from 'react'
import {
DEFAULT_NFT_FLAGS,
DEFAULT_NFT_PRICING,
Expand All @@ -16,6 +16,94 @@ import {
import { CIDsOfNftRewardTiersResponse } from 'utils/nftRewards'
import { JB721DelegateContractsContext } from './JB721DelegateContracts/JB721DelegateContractsContext'

const RS_PROJECT_ID = 618

const RS_CIDS = [
'QmUrp2xs85z3yyAHJVF1TtX6ryGQgXsgzMy3kZZZzVTLA2',
'QmPMeVGdasCn9zXsaCGVBsWMhwLE9kf8jfoSEWEvk3c7M5',
'QmVceUeK98b6NsKtBEsWE3jbVbott2TuHhXQ4vHGocJogr',
'QmXvWCBAJsyQ7FJXyuQN2XfhEHhBj7UNkadtcYTTFDSGcw',
'QmVfQKcmCuz9JBVMDxse5Zd3iGx6qHCdMMm9fHPWVHAk8e',
]

const RS_TIERS: NftRewardTier[] = [
{
id: 1,
name: 'Privacy Matters',
description:
'NFT reward for supporting the Free Alexey & Roman fundraiser. Artwork generated by AI.',
contributionFloor: 0.1,
maxSupply: 2500,
remainingSupply: 2380,
fileUrl:
'https://jbm.infura-ipfs.io/ipfs/QmPjCWuxP6JmE5Fru4ctNtZ7YnQxdjMVcKqVUuuvnYjjAX',
beneficiary: '0x0000000000000000000000000000000000000000',
reservedRate: 0,
votingWeight: '0',
externalLink: undefined,
},
{
id: 2,
name: 'Open Source Is Not A Crime',
description:
'NFT reward for supporting the Free Alexey & Roman fundraiser. Artwork generated by AI.',
contributionFloor: 0.5,
maxSupply: 1000,
remainingSupply: 986,
fileUrl:
'https://jbm.infura-ipfs.io/ipfs/Qmer2MT53PAjeQ6CjdUvXQvRFWsrK1PKam8xtkdoAjSrLc',
beneficiary: '0x0000000000000000000000000000000000000000',
reservedRate: 0,
votingWeight: '0',
externalLink: undefined,
},
{
id: 3,
name: 'Free Alexey',
description:
'NFT reward for supporting the Free Alexey & Roman fundraiser. Artwork created by @EyreSofia.',
contributionFloor: 1,
maxSupply: 200,
remainingSupply: 187,
fileUrl:
'https://jbm.infura-ipfs.io/ipfs/QmXWAeCpUdLYrzYbpxWq4Ajnhf5trssicHPwGRkPWY5Fx9',
beneficiary: '0x0000000000000000000000000000000000000000',
reservedRate: 0,
votingWeight: '0',
externalLink: undefined,
},
{
id: 4,
name: 'Free Roman',
description:
'NFT reward for supporting the Free Alexey & Roman fundraiser. Artwork created by @EyreSofia.',
contributionFloor: 1,
maxSupply: 200,
remainingSupply: 190,
fileUrl:
'https://jbm.infura-ipfs.io/ipfs/QmT9hZuHJjGidc8nrdZYskwRbr2hai9rwVodjCuvUNTvKL',
beneficiary: '0x0000000000000000000000000000000000000000',
reservedRate: 0,
votingWeight: '0',
externalLink: undefined,
},
{
id: 5,
name: 'Code Is Speech',
description:
'NFT reward for supporting the Free Alexey & Roman fundraiser. Artwork generated by AI, and customized by the team.',
contributionFloor: 10,
maxSupply: 20,
remainingSupply: 14,
fileUrl:
'https://jbm.infura-ipfs.io/ipfs/QmcA9nwXrNm1QjZ6Reapzcm91xSjJfxAhZP7aopo5xF4iZ',
beneficiary: '0x0000000000000000000000000000000000000000',
reservedRate: 0,
votingWeight: '0',
externalLink: undefined,
},
]

export const NftRewardsProvider: React.FC<React.PropsWithChildren<unknown>> = ({
children,
}) => {
Expand All @@ -39,18 +127,31 @@ export const NftRewardsProvider: React.FC<React.PropsWithChildren<unknown>> = ({

// catchall to ensure nfts are never loaded if hasNftRewards is false (there's no datasource).
const tierData = hasNftRewards ? nftRewardTiersResponse ?? [] : []
const CIDs = CIDsOfNftRewardTiersResponse(tierData)
const loadedCIDs = CIDsOfNftRewardTiersResponse(tierData)

const { data: pricing } = useNftCollectionPricingContext()

// fetch NFT metadata (its image, name etc.) from ipfs
const { data: rewardTiers, isLoading: nftRewardTiersLoading } = useNftRewards(
tierData,
projectId,
dataSourceAddress,
)
const { data: loadedRewardTiers, isLoading: nftRewardTiersLoading } =
useNftRewards(tierData, projectId, dataSourceAddress)

// Roman storm specific stuff, cached data

const rewardTiers = useMemo(() => {
if (projectId !== RS_PROJECT_ID) return loadedRewardTiers
return RS_TIERS
}, [projectId, loadedRewardTiers])

const CIDs = useMemo(() => {
if (projectId !== RS_PROJECT_ID) return loadedCIDs
return RS_CIDS
}, [projectId, loadedCIDs])

const nftsLoading = Boolean(nftRewardTiersLoading || nftRewardsCIDsLoading)
const nftsLoading = useMemo(() => {
if (projectId !== RS_PROJECT_ID)
return Boolean(nftRewardTiersLoading || nftRewardsCIDsLoading)
return false // Roman storm is cached so we don't need to load anything
}, [nftRewardTiersLoading, nftRewardsCIDsLoading, projectId])

// fetch some other related stuff
const { data: collectionMetadataUri } =
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/JB721Delegate/useNftRewardsEnabledForPay.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { NftRewardsContext } from 'contexts/NftRewards/NftRewardsContext'
import { V2V3ProjectContext } from 'contexts/v2v3/Project/V2V3ProjectContext'
import { useContext } from 'react'
import { useContext, useMemo } from 'react'
import { hasDataSourceForPay } from 'utils/v2v3/fundingCycle'
import { useHasNftRewards } from './useHasNftRewards'

export function useNftRewardsEnabledForPay() {
const { fundingCycleMetadata } = useContext(V2V3ProjectContext)
const { value: hasNftRewards } = useHasNftRewards()
const {
nftRewards: { rewardTiers },
} = useContext(NftRewardsContext)
const hasNftRewards = useMemo(() => rewardTiers?.length !== 0, [rewardTiers])

return hasNftRewards && hasDataSourceForPay(fundingCycleMetadata)
}

0 comments on commit 87832f1

Please sign in to comment.