Skip to content

Commit

Permalink
50px fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dhiraj0911 committed Feb 24, 2024
1 parent 0a14a4e commit d7696c7
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 89 deletions.
3 changes: 3 additions & 0 deletions components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions pages/forgotpassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ForgotPassword = () => {
},
{
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
}
);
setVerify(true);
Expand All @@ -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;
}
Expand All @@ -63,7 +63,7 @@ const ForgotPassword = () => {
},
{
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
}
);
window.location.href = "/signin";
Expand Down
46 changes: 23 additions & 23 deletions pages/game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 16 additions & 1 deletion pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) => {
Expand Down
63 changes: 32 additions & 31 deletions pages/nft-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
32 changes: 16 additions & 16 deletions pages/resell-nft.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
6 changes: 3 additions & 3 deletions pages/signin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,15 +33,15 @@ const SignIn = () => {
},
{
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
}
);
router.push("/");
} catch (err) {
setInputError(true);
toast.error("Invalid email or password", {
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
});
}
};
Expand Down
8 changes: 4 additions & 4 deletions pages/signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ const SignUp = () => {
if (!emailRegex.test(email)) {
toast.error("Please enter a valid email address.", {
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
});
return;
}

if (!acceptedTerms) {
toast.error("You must accept the terms and conditions.", {
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
});
return;
}

if (password !== confirmPassword) {
toast.error("Passwords do not match", {
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
});
return;
}
Expand All @@ -49,7 +49,7 @@ const SignUp = () => {
},
{
position: "top-right",
style: { marginTop: "50px" },
style: { marginTop: "70px" },
}
);
};
Expand Down
11 changes: 3 additions & 8 deletions pages/wallet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d7696c7

Please sign in to comment.