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

fixes and added reverify all option #41

Merged
merged 1 commit into from
Dec 20, 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
51 changes: 28 additions & 23 deletions ui/components/ticket-to-space/ReverifyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 (
Expand All @@ -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]"
>
<div className="flex flex-col gap-2 items-start justify-start w-[300px] md:w-[500px] p-8 bg-[#080C20] rounded-md">
<h1 className="text-2xl text-white">Reverify NFT {Number(nftId)}</h1>
<h1 className="text-2xl text-white">Reverify {nftIds.length > 1 ? "All NFTs" : "NFT " + Number(nftIds)}</h1>
<p className="opacity-50 mb-4 text-gray-300">
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
Expand Down
6 changes: 6 additions & 0 deletions ui/components/ticket-to-space/SubmitTTSInfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export function SubmitTTSInfoModal({
const [fullName, setFullName] = useState<string>('')
const [checkBoxEnabled, setCheckBoxEnabled] = useState<boolean>(true)

function timeout(delay: number) {
return new Promise( res => setTimeout(res, delay) );
}

function filterNewNFTS(
prevNFTs: Array<BigNumber>,
newNFTs: Array<BigNumber>
Expand Down Expand Up @@ -248,6 +252,8 @@ export function SubmitTTSInfoModal({

setStatus('Verifying identity...')

await timeout(3000);

const newNFTBalance = await ttsContract.erc721.getOwnedTokenIds(
address
)
Expand Down
35 changes: 26 additions & 9 deletions ui/components/ticket-to-space/ViewNFTDataModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function ViewNFTDataModal({

const [isLoading, setIsLoading] = useState(true)
const [enableReverifyModal, setReverifyModal] = useState(false)
const [reverifyNFTId, setReverifyNFTId] = useState<string>("")
const [reverifyNFTId, setReverifyNFTId] = useState<string[]>([])
const [userNFTs, setUserNFTs] = useState<
{
id: any
Expand Down Expand Up @@ -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++) {
Expand All @@ -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',
})
}

Expand All @@ -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 && <ReverifyModal setReverifyEnabled={setReverifyModal} setViewEnabled={setEnabled} nftId={reverifyNFTId}/>}
{enableReverifyModal && <ReverifyModal setReverifyEnabled={setReverifyModal} setViewEnabled={setEnabled} nftIds={reverifyNFTId}/>}
<div className="flex flex-col gap-2 items-start justify-start w-[300px] md:w-[500px] lg:w-[750px] p-8 bg-[#080C20] rounded-md">
<h1 className="text-2xl">View your NFTs</h1>
<p className="opacity-50 mb-4">
Expand All @@ -128,6 +129,7 @@ export function ViewNFTDataModal({
Please sign the message in your wallet to view your Verified NFTs
</p>
) : (
<>
<div className="overflow-visible w-full h-[200px] overflow-y-scroll">
{userNFTs.map((nft, i) => (
<div
Expand All @@ -140,7 +142,7 @@ export function ViewNFTDataModal({
<button
onClick={() => {
setReverifyModal(true)
setReverifyNFTId(nft.id)
setReverifyNFTId([nft.id])
}}
className="text-moon-gold ml-2"
>
Expand All @@ -149,9 +151,24 @@ export function ViewNFTDataModal({
</div>
))}
</div>

<button
onClick={() => {
setReverifyModal(true)
let nftsList : string[] = []
userNFTs.map((nft) => (nftsList.push(nft.id)))
setReverifyNFTId(nftsList)
}}
className="text-moon-gold mt-2 text-lg"
>
Reverify All
</button>
</>
)}

<div className="flex w-full justify-between pt-8">


<div className="flex w-full justify-between pt-4">
<button
className="inline-flex justify-center w-1/3 rounded-sm border border-transparent shadow-sm px-4 py-2 bg-[#2A2A2A] text-base font-medium text-white hover:bg-white hover:text-moon-orange focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-moon-orange"
onClick={() => setEnabled(false)}
Expand Down
2 changes: 2 additions & 0 deletions ui/pages/sweepstakes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export default function Sweepstakes() {
</p>
</div>

{balance > 0 &&
<div>
<button
className="p-3 bg-moon-orange lg:text-lg"
Expand All @@ -215,6 +216,7 @@ export default function Sweepstakes() {
/>
)}
</div>
}
</>
)}
</div>
Expand Down
Loading