From ee30a61fed6bf15f3459dbca68f9b0610b226a53 Mon Sep 17 00:00:00 2001 From: Alejandro Moncada-Larrotiz Date: Tue, 19 Dec 2023 22:46:40 -0500 Subject: [PATCH] fixes and added reverify all option --- .../ticket-to-space/ReverifyModal.tsx | 51 ++++++++++--------- .../ticket-to-space/SubmitTTSInfoModal.tsx | 6 +++ .../ticket-to-space/ViewNFTDataModal.tsx | 35 +++++++++---- ui/pages/sweepstakes/index.tsx | 2 + 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/ui/components/ticket-to-space/ReverifyModal.tsx b/ui/components/ticket-to-space/ReverifyModal.tsx index 15de72935..8e0fb6bec 100644 --- a/ui/components/ticket-to-space/ReverifyModal.tsx +++ b/ui/components/ticket-to-space/ReverifyModal.tsx @@ -7,10 +7,10 @@ import PrivyWalletContext from '../../lib/privy/privy-wallet-context' type SubmitInfoModalProps = { setReverifyEnabled: Function setViewEnabled: Function - nftId: string + nftIds: string[] } -export function ReverifyModal({ setReverifyEnabled, setViewEnabled, nftId }: SubmitInfoModalProps) { +export function ReverifyModal({ setReverifyEnabled, setViewEnabled, nftIds }: SubmitInfoModalProps) { const address = useAddress() const { selectedWallet } = useContext(PrivyWalletContext) const { wallets } = useWallets() @@ -39,31 +39,36 @@ export function ReverifyModal({ setReverifyEnabled, setViewEnabled, nftId }: Sub const signature = await signMessage() setStatus('Submitting...') - const res = await fetch(`/api/db/nft?address=${address}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'moondao-api-key': signature, - } as any, - body: JSON.stringify({ - tokenId: nftId, - email, - name: fullName, - address: address, - }), - }) - setStatus('') - const data = await res.json() + + let success = true + for (let i = 0; i < nftIds.length; i++) { + const res = await fetch(`/api/db/nft?address=${address}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'moondao-api-key': signature, + } as any, + body: JSON.stringify({ + tokenId: nftIds[i], + email, + name: fullName, + address: address, + }), + }) + setStatus('') + const data = await res.json() + if (!data.success) success = false + } + setReverifyEnabled(false) setViewEnabled(false) - if (data.success) { + if (success) { toast.success("You're all set! There's nothing else you need to do.") } else { - toast.error( - 'There was an issue adding your info to the database. Please contact a moondao member.' - ) + toast.error( + 'There was an issue adding your info to the database. Please contact a moondao member.' + ) } - console.log(2) } return ( @@ -77,7 +82,7 @@ export function ReverifyModal({ setReverifyEnabled, setViewEnabled, nftId }: Sub className="fixed top-0 left-0 w-screen h-screen bg-[#00000080] backdrop-blur-sm flex justify-center items-center z-[1000]" >
-

Reverify NFT {Number(nftId)}

+

Reverify {nftIds.length > 1 ? "All NFTs" : "NFT " + Number(nftIds)}

Please enter your full legal name (as displayed on a government issued photo ID) and the best email for us to contact you if you win a prize diff --git a/ui/components/ticket-to-space/SubmitTTSInfoModal.tsx b/ui/components/ticket-to-space/SubmitTTSInfoModal.tsx index e201a7ab0..1e3bbbb36 100644 --- a/ui/components/ticket-to-space/SubmitTTSInfoModal.tsx +++ b/ui/components/ticket-to-space/SubmitTTSInfoModal.tsx @@ -41,6 +41,10 @@ export function SubmitTTSInfoModal({ const [fullName, setFullName] = useState('') const [checkBoxEnabled, setCheckBoxEnabled] = useState(true) + function timeout(delay: number) { + return new Promise( res => setTimeout(res, delay) ); + } + function filterNewNFTS( prevNFTs: Array, newNFTs: Array @@ -248,6 +252,8 @@ export function SubmitTTSInfoModal({ setStatus('Verifying identity...') + await timeout(3000); + const newNFTBalance = await ttsContract.erc721.getOwnedTokenIds( address ) diff --git a/ui/components/ticket-to-space/ViewNFTDataModal.tsx b/ui/components/ticket-to-space/ViewNFTDataModal.tsx index fad54026f..722eb475a 100644 --- a/ui/components/ticket-to-space/ViewNFTDataModal.tsx +++ b/ui/components/ticket-to-space/ViewNFTDataModal.tsx @@ -22,7 +22,7 @@ export function ViewNFTDataModal({ const [isLoading, setIsLoading] = useState(true) const [enableReverifyModal, setReverifyModal] = useState(false) - const [reverifyNFTId, setReverifyNFTId] = useState("") + const [reverifyNFTId, setReverifyNFTId] = useState([]) const [userNFTs, setUserNFTs] = useState< { id: any @@ -62,8 +62,10 @@ export function ViewNFTDataModal({ const { data: verifiedNfts } = await verifiedNftsRes.json() - if (!verifiedNfts) - return + if (!verifiedNfts) return + + const email = verifiedNfts[0].email + const name = verifiedNfts[0].name let nftsList = [] for (let i = 0; i < ownedNfts.length; i++) { @@ -86,15 +88,14 @@ export function ViewNFTDataModal({ updateTime: verifiedNfts[j].updatedAt, }) } - console.log(verifiedNfts[j]) found = true } } if (!found) nftsList.push({ id: ownedNfts[i]._hex, - name: 'Unverified', - email: 'Unverified', + name: name || 'Unverified', + email: email || 'Unverified', }) } @@ -115,7 +116,7 @@ export function ViewNFTDataModal({ id="submit-tts-info-modal-backdrop" className="fixed top-0 left-0 w-screen h-screen bg-[#00000080] backdrop-blur-sm flex justify-center items-center z-[1000]" > - {enableReverifyModal && } + {enableReverifyModal && }

View your NFTs

@@ -128,6 +129,7 @@ export function ViewNFTDataModal({ Please sign the message in your wallet to view your Verified NFTs

) : ( + <>
{userNFTs.map((nft, i) => (
{ setReverifyModal(true) - setReverifyNFTId(nft.id) + setReverifyNFTId([nft.id]) }} className="text-moon-gold ml-2" > @@ -149,9 +151,24 @@ export function ViewNFTDataModal({
))}
+ + + )} -
+ + +
+ {balance > 0 &&
+ } )}