From 154dd1460696d1249fe4ff275bb3c26a39454bfe Mon Sep 17 00:00:00 2001
From: wraeth-eth <104132113+wraeth-eth@users.noreply.github.com>
Date: Wed, 25 Oct 2023 15:51:28 +1100
Subject: [PATCH] allow selection of nfts in pay project (#122)
### Description
Allow the selection of NFTs in the pay project page
[Screen Recording 2023-10-25 at 1.27.33 pm.mov](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/pinTSPPZHK80UCzWAYgo/2c5972e2-9594-4737-807c-4e028a7b7599.mov)
---
src/components/Project/ProjectPayPage.tsx | 47 +++++++++++--------
.../Project/components/PayRewardCard.tsx | 31 ++++++++++--
.../Project/components/ProjectPayForm.tsx | 23 +++++++--
.../Project/components/ProjectPayRewards.tsx | 28 ++++++++++-
.../Project/providers/ProjectPayContext.tsx | 19 ++++++++
.../Project/providers/projectPayReducer.ts | 27 +++++++++++
6 files changed, 148 insertions(+), 27 deletions(-)
create mode 100644 src/components/Project/providers/ProjectPayContext.tsx
create mode 100644 src/components/Project/providers/projectPayReducer.ts
diff --git a/src/components/Project/ProjectPayPage.tsx b/src/components/Project/ProjectPayPage.tsx
index 83d554ef..c3d628f4 100644
--- a/src/components/Project/ProjectPayPage.tsx
+++ b/src/components/Project/ProjectPayPage.tsx
@@ -1,39 +1,48 @@
import { useJbProject } from '@/hooks/useJbProject'
import { ChevronLeftIcon } from '@heroicons/react/24/outline'
import Link from 'next/link'
+import React from 'react'
import { twMerge } from 'tailwind-merge'
import { Button } from '../ui/Button'
import { ProjectPayForm } from './components/ProjectPayForm'
import { ProjectPayRewards } from './components/ProjectPayRewards'
+import { projectPayReducer } from './providers/projectPayReducer'
+import { ProjectPayContext } from './providers/ProjectPayContext'
export const ProjectPayPage = () => {
const { name } = useJbProject()
+ const [state, dispatch] = React.useReducer(projectPayReducer, {
+ nftRewardIds: [],
+ })
+
return (
-
- {/* Left panel */}
-
-
-
-
-
- You are paying
-
-
{name}
+
+
+ {/* Left panel */}
+
+
+
+
+
+ You are paying
+
+
{name}
-
- Select a reward
-
+
+ Select a reward
+
-
+
+
-
- {/* Right panel */}
-
-
+ {/* Right panel */}
+
-
+
)
}
diff --git a/src/components/Project/components/PayRewardCard.tsx b/src/components/Project/components/PayRewardCard.tsx
index dab7bc95..e00ebdbd 100644
--- a/src/components/Project/components/PayRewardCard.tsx
+++ b/src/components/Project/components/PayRewardCard.tsx
@@ -6,23 +6,32 @@ import { formatEther } from 'juice-hooks'
import { RewardDialog } from './RewardDialog'
import { Button } from '@/components/ui/Button'
import { Separator } from '@/components/ui/Separator'
+import React from 'react'
+import { CheckIcon } from '@heroicons/react/24/solid'
export type PayRewardCardProps = {
className?: string
nft: JB721DelegateTierTier
+ isSelected?: boolean
+ onClick?: () => void
}
export const PayRewardCard: React.FC
= ({
className,
nft,
+ isSelected,
+ onClick,
}) => {
const remaining = nft.remainingQuantity.toString()
return (
= ({
-
- {remaining} remaining
+
+ {remaining} remaining
+
-
+
+
+
)
}
diff --git a/src/components/Project/components/ProjectPayForm.tsx b/src/components/Project/components/ProjectPayForm.tsx
index fd803e21..f8a33c83 100644
--- a/src/components/Project/components/ProjectPayForm.tsx
+++ b/src/components/Project/components/ProjectPayForm.tsx
@@ -10,10 +10,13 @@ import {
FormMessage,
} from '@/components/ui/Form'
import { zodResolver } from '@hookform/resolvers/zod'
-import { PropsWithChildren, useCallback } from 'react'
+import { PropsWithChildren, useCallback, useMemo } from 'react'
import { useForm } from 'react-hook-form'
import { twMerge } from 'tailwind-merge'
import { z } from 'zod'
+import { useProjectPay } from '../providers/ProjectPayContext'
+import { useJbProject } from '@/hooks/useJbProject'
+import { formatEther } from 'juice-hooks'
const WEI = 1e-18
@@ -34,6 +37,9 @@ export type ProjectPayFormProps = {
export const ProjectPayForm: React.FC
= ({
className,
}) => {
+ const { nfts } = useJbProject()
+ const { nftRewardIds } = useProjectPay()
+
const form = useForm>({
resolver: zodResolver(formSchema),
defaultValues: {
@@ -44,12 +50,23 @@ export const ProjectPayForm: React.FC = ({
},
})
+ const totalNftSelectionPrice = useMemo(
+ () =>
+ nftRewardIds.reduce((acc, nftId) => {
+ if (!nfts) return acc
+ const nft = nfts.find(nft => nft.id === nftId)
+ if (!nft) return acc
+ return acc + nft.price
+ }, 0n),
+ [nftRewardIds, nfts],
+ )
+
const onSubmit = useCallback(async (values: z.infer) => {
console.log(values)
}, [])
// TODO
- const total = 0
+ const total = totalNftSelectionPrice
return (