-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding rental details popup and rendering more nfts
- Loading branch information
1 parent
4d41106
commit f638a13
Showing
6 changed files
with
200 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { ReactNode } from "react"; | ||
|
||
export const Popup = ({ closeHandler, children }: { closeHandler: () => void; children: ReactNode }) => { | ||
return ( | ||
<div | ||
className="fixed h-screen w-screen top-0 left-0 flex justify-center items-center z-10" | ||
style={{ backgroundColor: "rgba(0,0,0,.2)" }} | ||
onClick={e => { | ||
if (e.target === e.currentTarget) { | ||
closeHandler(); | ||
} | ||
}} | ||
> | ||
<div className="bg-white shadow relative p-4"> | ||
<div | ||
className="absolute right-0 top-0 cursor-pointer p-3 text-xl" | ||
style={{ fontFamily: "Arial" }} | ||
onClick={closeHandler} | ||
> | ||
✖ | ||
</div> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { useState } from "react"; | ||
import { NftWithMetadata } from "../../../types/nftTypes.js"; | ||
import DatePicker from "react-datepicker"; | ||
|
||
export const RentDetails = ({ nft }: { nft: NftWithMetadata }) => { | ||
const [dateRange, setDateRange] = useState<[Date, Date]>([new Date(), new Date()]); | ||
const [startDate, endDate] = dateRange; | ||
|
||
return ( | ||
<div> | ||
<h1 className="text-3xl font-bold">{nft.name}</h1> | ||
<p className="text-lg">{nft.nft.listing.description}</p> | ||
<h3 className="text-xl">Pick your date:</h3> | ||
<DatePicker | ||
selectsRange={true} | ||
startDate={startDate} | ||
endDate={endDate} | ||
onChange={(update: any) => { | ||
setDateRange(update); | ||
}} | ||
minDate={new Date()} | ||
showDisabledMonthNavigation | ||
inline | ||
/> | ||
<h3 className="text-xl">Price per day: {nft.nft.listing.pricePerDay} ETH</h3> | ||
<h3 className="text-xl">Collateral: {nft.nft.listing.collateral} ETH</h3> | ||
<button className="mt-2 w-48 bg-indigo-800 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-md"> | ||
Rent! | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
import { getNFTMetadata } from "./web3"; | ||
import { NftWithMetadata, Nft, AvaliabilityStatus, Attribute } from "../../../types/nftTypes.js"; | ||
|
||
|
||
const getMetadataForAllNfts = async (nfts: Nft[]) => { | ||
const awaitables = []; | ||
for (const nft of nfts) { | ||
awaitables.push(getNFTMetadata(nft.specification.collection, nft.specification.id)); | ||
} | ||
return Promise.all(awaitables); | ||
}; | ||
|
||
const calculateAvaliabiltyStatus = (nft: Nft) => { | ||
const now = new Date(); | ||
if (nft.listing.datesForRent.some(date => date.startDate <= now && date.endDate >= now)) { | ||
return AvaliabilityStatus.Avaliabile; | ||
} else { | ||
return AvaliabilityStatus.Unavaliabile; | ||
} | ||
}; | ||
|
||
const mapIpfsToUrl = (ipfs: string) => { | ||
return `https://ipfs.io/ipfs/${ipfs.slice(7)}`; | ||
}; | ||
|
||
export const mergeNftsWithMetadata = async (nfts: Nft[]) => { | ||
let nftsWithMetadata = []; | ||
const metadatas = await getMetadataForAllNfts(nfts); | ||
for (let i = 0; i < nfts.length; i++) { | ||
const metadata = metadatas[i].metadata!; | ||
|
||
let attributes: Attribute[] = []; | ||
if (metadata.attributes) { | ||
attributes = metadata.attributes.map(attribute => { | ||
return { | ||
traitType: attribute.trait_type, | ||
value: attribute.value, | ||
}; | ||
}); | ||
} | ||
|
||
let image = metadata.image!; | ||
|
||
if (image.startsWith("ipfs://")) { | ||
image = mapIpfsToUrl(image); | ||
} | ||
|
||
const nftWithMetadata: NftWithMetadata = { | ||
nft: nfts[i], | ||
name: metadata.name!, | ||
image, | ||
attributes, | ||
avaliability: { status: calculateAvaliabiltyStatus(nfts[i]) }, | ||
}; | ||
nftsWithMetadata.push(nftWithMetadata); | ||
} | ||
return nftsWithMetadata; | ||
}; |
Oops, something went wrong.
f638a13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nerp – ./
nerp.vercel.app
nerp-git-master-gstenger98.vercel.app
www.n3rp.com
n3rp.com
nerp-gstenger98.vercel.app