Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Official-MoonDao/MoonDAO in…
Browse files Browse the repository at this point in the history
…to thirdwebV5-migration
  • Loading branch information
namedotget committed Jan 10, 2025
2 parents 1e63e49 + ca115fd commit f0a6134
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
50 changes: 36 additions & 14 deletions ui/components/project/ProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//This component dipslays a project card using project data directly from tableland
import Image from 'next/image'
import Link from 'next/link'
import React, { memo } from 'react'
import ChainContext from '@/lib/thirdweb/chain-context'
import useUniqueHatWearers from '@/lib/hats/useUniqueHatWearers'
import { useAddress, useContract, useSDK } from '@thirdweb-dev/react'
import { useSubHats } from '@/lib/hats/useSubHats'
import React, { useContext, memo } from 'react'
import useProjectData, { Project } from '@/lib/project/useProjectData'
import NumberStepper from '../layout/NumberStepper'

Expand All @@ -10,6 +14,7 @@ type ProjectCardProps = {
projectContract: any
hatsContract: any
distribute?: boolean
userContributed?: boolean
distribution?: Record<string, number>
handleDistributionChange?: (projectId: string, value: number) => void
}
Expand All @@ -22,6 +27,7 @@ const ProjectCardContent = memo(
proposalJSON,
totalBudget,
distribute,
userContributed,
}: any) => {
return (
<div
Expand All @@ -30,18 +36,21 @@ const ProjectCardContent = memo(
>
<div className="flex justify-between">
<h1 className="font-GoodTimes">{project?.name || ''}</h1>
{distribute && (
<NumberStepper
number={distribution?.[project?.id] || 0}
setNumber={(value: any) => {
if (distribution && handleDistributionChange) {
handleDistributionChange?.(String(project?.id), value)
}
}}
step={1}
max={100}
/>
)}
{distribute &&
(userContributed ? (
<p>Contributed</p>
) : (
<NumberStepper
number={distribution?.[project?.id] || 0}
setNumber={(value: any) => {
if (distribution && handleDistributionChange) {
handleDistributionChange?.(String(project?.id), value)
}
}}
step={1}
max={100}
/>
))}
</div>
<div className="flex gap-2"></div>
<div>
Expand All @@ -65,11 +74,23 @@ export default function ProjectCard({
distribution,
handleDistributionChange,
}: ProjectCardProps) {
const { proposalJSON, totalBudget } = useProjectData(
const { adminHatId, proposalJSON, totalBudget } = useProjectData(
projectContract,
hatsContract,
project
)
const { selectedChain } = useContext(ChainContext)
const hats = useSubHats(selectedChain, adminHatId)
const wearers = useUniqueHatWearers(hats)
const address = useAddress()
let userContributed = false
if (wearers && address) {
wearers.forEach((wearer: { address: string }) => {
if (address.toLowerCase() === wearer['address'].toLowerCase()) {
userContributed = true
}
})
}

if (!project) return null

Expand All @@ -79,6 +100,7 @@ export default function ProjectCard({
<ProjectCardContent
project={project}
distribute={distribute}
userContributed={userContributed}
distribution={distribution}
handleDistributionChange={handleDistributionChange}
proposalJSON={proposalJSON}
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/project/useProjectData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export default function useProjectData(
const [hatTreeId, setHatTreeId] = useState<string>()

const { data: adminHatId } = useHandleRead(projectContract, 'teamAdminHat', [
project?.id || '',
project?.id ?? '',
])

const { data: managerHatId } = useHandleRead(
projectContract,
'teamManagerHat',
[project?.id || '']
[project?.id ?? '']
)

const isActive = useMemo(() => {
Expand Down

0 comments on commit f0a6134

Please sign in to comment.