From d7696c71000c15beeb0ed66be0d49a13c0f7ed77 Mon Sep 17 00:00:00 2001 From: dhiraj0911 Date: Sat, 24 Feb 2024 21:59:08 +0530 Subject: [PATCH] 50px fix --- components/Navbar.jsx | 3 ++ pages/forgotpassword.jsx | 6 ++-- pages/game.jsx | 46 ++++++++++++++--------------- pages/index.jsx | 17 ++++++++++- pages/nft-details.jsx | 63 ++++++++++++++++++++-------------------- pages/resell-nft.jsx | 32 ++++++++++---------- pages/signin.jsx | 6 ++-- pages/signup.jsx | 8 ++--- pages/wallet.jsx | 11 ++----- 9 files changed, 103 insertions(+), 89 deletions(-) diff --git a/components/Navbar.jsx b/components/Navbar.jsx index 8a5b68c..21a92e0 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -91,7 +91,9 @@ const ButtonGroup = ({ setActive, router, setIsOpen }) => { const newImageFile = new File([blob], "resizedImage.png", { type: "image/png", }); + console.log("hit 1") if (vendorId) { + console.log("hit 2") const formData = new FormData(); formData.append("file", newImageFile); formData.append("vendorId", vendorId); @@ -104,6 +106,7 @@ const ButtonGroup = ({ setActive, router, setIsOpen }) => { }, } ); + console.log("hit 3") const avatarurl = response.data.location; setAvatar(avatarurl); const userdata = window.localStorage.getItem("userdata"); diff --git a/pages/forgotpassword.jsx b/pages/forgotpassword.jsx index fcd7857..bbe2fa0 100644 --- a/pages/forgotpassword.jsx +++ b/pages/forgotpassword.jsx @@ -28,7 +28,7 @@ const ForgotPassword = () => { }, { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, } ); setVerify(true); @@ -44,7 +44,7 @@ const ForgotPassword = () => { if (password !== confirmPassword) { toast.error("Passwords do not match", { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, }); return; } @@ -63,7 +63,7 @@ const ForgotPassword = () => { }, { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, } ); window.location.href = "/signin"; diff --git a/pages/game.jsx b/pages/game.jsx index 86f9738..32e4d12 100644 --- a/pages/game.jsx +++ b/pages/game.jsx @@ -46,29 +46,29 @@ const Game = () => { const uri = response.data.ipfsResult.IpfsHash; await createSale(uri, isWETH, price, rentPrice, isForSale, isForRent); handleCloseModal(); - // const ownerId = window.localStorage.getItem("vendor"); - // const { id } = currentAsset; - // try { - // const assets = await axios.post(`${API_BASE_URL}/api/assets/`, { - // id, - // uri, - // isForSale, - // isForRent, - // isWETH, - // price, - // rentPrice, - // owner: ownerId, - // }); - // const assetId = assets.data.id; - // const vendorId = window.localStorage.getItem("vendor"); - // await axios.post(`${API_BASE_URL}/api/transaction`, { - // assetId, - // vendorId, - // transactionType: "Create", - // }); - // } catch (error) { - // console.error("Error in storing asset in backend", error); - // } + const ownerId = window.localStorage.getItem("vendor"); + const { id } = currentAsset; + try { + const assets = await axios.post(`${API_BASE_URL}/api/assets/`, { + id, + uri, + isForSale, + isForRent, + isWETH, + price, + rentPrice, + owner: ownerId, + }); + const assetId = assets.data.id; + const vendorId = window.localStorage.getItem("vendor"); + await axios.post(`${API_BASE_URL}/api/transaction`, { + assetId, + vendorId, + transactionType: "Create", + }); + } catch (error) { + console.error("Error in storing asset in backend", error); + } setMintedAssets((prev) => ({ ...prev, [currentAsset.id]: true })); setPrice("0"); setRentPrice("0"); diff --git a/pages/index.jsx b/pages/index.jsx index 877ddd5..f6c49fd 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -8,6 +8,7 @@ import { } from "@thirdweb-dev/react"; import { NFTContext } from "../context/NFTContext"; import { Banner, CreatorCard, Loader, RentCard, BuyCard, SearchBar } from "../components"; +import axios from "axios"; import images from "../assets"; import { shortenAddress } from "../utils/shortenAddress"; @@ -37,6 +38,8 @@ const Home = () => { const status = useConnectionStatus(); const currentAccount = useAddress(); + const API_BASE_URL = process.env.NEXT_PUBLIC_PRODUCTION === "true" ? process.env.NEXT_PUBLIC_BASE_URL : "http://localhost:5000"; + const filteredRentNfts = useMemo(() => { let filtered = rentNfts.filter((nft) => nft.name.toLowerCase().includes(searchQueryRent.toLowerCase()) @@ -73,7 +76,7 @@ const Home = () => { return filtered; }, [myListings, searchQueryListed, sortOptionListed]); - useEffect(() => { + useEffect(async () => { if (currentAccount) { // Ensure currentAccount is not null or undefined fetchNFTs().then((items) => { const itemsForRent = []; @@ -114,6 +117,18 @@ const Home = () => { setSaleNfts(itemsForSale); setIsLoading(false); })}; + if (status === "connected") { + try { + const vendorId = window.localStorage.getItem("vendor"); + const lowerCaseAddress = currentAccount.toLowerCase(); + await axios.post(`${API_BASE_URL}/api/address`, { + vendorId, + address: lowerCaseAddress, + }); + } catch (error) { + console.error("Error sending address:", error); + } + } }, [currentAccount ? currentAccount : ""]); const handleScroll = (direction) => { diff --git a/pages/nft-details.jsx b/pages/nft-details.jsx index 5d58400..155fe62 100644 --- a/pages/nft-details.jsx +++ b/pages/nft-details.jsx @@ -2,6 +2,7 @@ import { useState, useEffect, useContext } from "react"; import { useRouter } from "next/router"; import axios from "axios"; import { + useConnectionStatus, useAddress, } from "@thirdweb-dev/react"; import { NFTContext } from "../context/NFTContext"; @@ -114,7 +115,7 @@ const NFTDetails = () => { const { isLoadingNFT, buyNft, rentNFT, userOf } = useContext(NFTContext); const [currency, setCurrency] = useState("MATIC"); - const currentAccount = useAddress() ? useAddress().toLowerCase() : ""; + const currentAccount = useConnectionStatus() === 'connected' ? useAddress().toLowerCase() : ""; const [nft, setNft] = useState({ description: "", @@ -187,22 +188,22 @@ const NFTDetails = () => { const buyCheckout = async () => { try { await buyNft(nft); - // await axios.put(`${API_BASE_URL}/api/assets/${nft.id}`, { - // sold: true, - // isForSale: false, - // isForRent: false, - // isWETH: false, - // price: null, - // rentPrice: null, - // owner: window.localStorage.getItem("vendor"), - // }); - // const asset = await axios.get(`${API_BASE_URL}/api/assets/${nft.id}`); - // const vendorId = window.localStorage.getItem("vendor"); - // await axios.post(`${API_BASE_URL}/api/transaction`, { - // assetId: asset.data._id, - // vendorId, - // transactionType: "Buy", - // }); + await axios.put(`${API_BASE_URL}/api/assets/${nft.id}`, { + sold: true, + isForSale: false, + isForRent: false, + isWETH: false, + price: null, + rentPrice: null, + owner: window.localStorage.getItem("vendor"), + }); + const asset = await axios.get(`${API_BASE_URL}/api/assets/${nft.id}`); + const vendorId = window.localStorage.getItem("vendor"); + await axios.post(`${API_BASE_URL}/api/transaction`, { + assetId: asset.data._id, + vendorId, + transactionType: "Buy", + }); setPaymentModal(false); setBuySuccessModal(true); } catch (error) { @@ -213,20 +214,20 @@ const NFTDetails = () => { const rentCheckout = async (rentalPeriodInDays) => { try { await rentNFT(nft, rentalPeriodInDays); - // await axios.put(`${API_BASE_URL}/api/assets/${nft.id}`, { - // rented: true, - // rentStart: Math.floor(Date.now() / 1000), - // rentEnd: - // Math.floor(Date.now() / 1000) + rentalPeriodInDays * 24 * 60 * 60, - // renter: window.localStorage.getItem("vendor"), - // }); - // const asset = await axios.get(`${API_BASE_URL}/api/assets/${nft.id}`); - // const vendorId = window.localStorage.getItem("vendor"); - // await axios.post(`${API_BASE_URL}/api/transaction`, { - // assetId: asset.data._id, - // vendorId, - // transactionType: "Rent", - // }); + await axios.put(`${API_BASE_URL}/api/assets/${nft.id}`, { + rented: true, + rentStart: Math.floor(Date.now() / 1000), + rentEnd: + Math.floor(Date.now() / 1000) + rentalPeriodInDays * 24 * 60 * 60, + renter: window.localStorage.getItem("vendor"), + }); + const asset = await axios.get(`${API_BASE_URL}/api/assets/${nft.id}`); + const vendorId = window.localStorage.getItem("vendor"); + await axios.post(`${API_BASE_URL}/api/transaction`, { + assetId: asset.data._id, + vendorId, + transactionType: "Rent", + }); setRentPaymentModal(false); setRentSuccessModal(true); } catch (error) { diff --git a/pages/resell-nft.jsx b/pages/resell-nft.jsx index 937e5b6..276ca70 100644 --- a/pages/resell-nft.jsx +++ b/pages/resell-nft.jsx @@ -36,22 +36,22 @@ const ResellNFT = () => { const resell = async () => { await reSale(tokenId, isWETH, price, rentPrice, isForRent, isForSale); - // await axios.put(`${API_BASE_URL}/api/assets/${id}`, { - // sold: false, - // isForSale, - // isForRent, - // isWETH, - // price, - // rentPrice, - // }); - // const asset = await axios.get(`${API_BASE_URL}/api/assets/${id}`); - // const vendorId = window.localStorage.getItem("vendor"); - // await axios.post(`${API_BASE_URL}/api/transaction`, { - // assetId: asset.data._id, - // vendorId, - // transactionType: "Resell", - // }); - // router.push("/"); + await axios.put(`${API_BASE_URL}/api/assets/${id}`, { + sold: false, + isForSale, + isForRent, + isWETH, + price, + rentPrice, + }); + const asset = await axios.get(`${API_BASE_URL}/api/assets/${id}`); + const vendorId = window.localStorage.getItem("vendor"); + await axios.post(`${API_BASE_URL}/api/transaction`, { + assetId: asset.data._id, + vendorId, + transactionType: "Resell", + }); + router.push("/"); setBuySuccessModal(true); }; diff --git a/pages/signin.jsx b/pages/signin.jsx index 10cb7ef..a7c6e68 100644 --- a/pages/signin.jsx +++ b/pages/signin.jsx @@ -18,7 +18,7 @@ const SignIn = () => { if (!email.trim() || !password.trim()) { toast.error("Please enter both email and password.", { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, }); setInputError(true); return; @@ -33,7 +33,7 @@ const SignIn = () => { }, { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, } ); router.push("/"); @@ -41,7 +41,7 @@ const SignIn = () => { setInputError(true); toast.error("Invalid email or password", { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, }); } }; diff --git a/pages/signup.jsx b/pages/signup.jsx index 8016d2b..e37ace1 100644 --- a/pages/signup.jsx +++ b/pages/signup.jsx @@ -19,7 +19,7 @@ const SignUp = () => { if (!emailRegex.test(email)) { toast.error("Please enter a valid email address.", { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, }); return; } @@ -27,7 +27,7 @@ const SignUp = () => { if (!acceptedTerms) { toast.error("You must accept the terms and conditions.", { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, }); return; } @@ -35,7 +35,7 @@ const SignUp = () => { if (password !== confirmPassword) { toast.error("Passwords do not match", { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, }); return; } @@ -49,7 +49,7 @@ const SignUp = () => { }, { position: "top-right", - style: { marginTop: "50px" }, + style: { marginTop: "70px" }, } ); }; diff --git a/pages/wallet.jsx b/pages/wallet.jsx index 51e250c..a8c7366 100644 --- a/pages/wallet.jsx +++ b/pages/wallet.jsx @@ -16,19 +16,14 @@ const Wallet = () => { ? process.env.NEXT_PUBLIC_BASE_URL : "http://localhost:5000"; - const address = useAddress(); - const connectionStatus = useConnectionStatus(); + const address = useConnectionStatus() === "connected" ? useAddress().toLowerCase() : null; const handleConnect = async () => { - // if (connectionStatus === "connected") { - // console.log(address); - // } - // console.log(connectionStatus) // try { // let vendorId = window.localStorage.getItem("vendor"); - // await axios.post(`${API_BASE_URL}/api/address/`, { + // await axios.post(`${API_BASE_URL}/api/address`, { // vendorId, - // address: accounts[0], + // address: address, // }); // } catch (error) { // console.error("Not signed In:", error);