From 6b329c26523ee5952e814d28c59be895cb931bb5 Mon Sep 17 00:00:00 2001 From: Jason Schwarz Date: Fri, 8 Sep 2023 12:13:20 -0700 Subject: [PATCH 1/2] coming-soon --- components/ComingSoon.tsx | 28 ++++++++++++++++++++++++++++ pages/_app.tsx | 23 +++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 components/ComingSoon.tsx diff --git a/components/ComingSoon.tsx b/components/ComingSoon.tsx new file mode 100644 index 0000000..6ec1ef8 --- /dev/null +++ b/components/ComingSoon.tsx @@ -0,0 +1,28 @@ +import { Box, Flex, Heading, Text, Image } from "@chakra-ui/react"; + +const ComingSoon = () => { + const Logo = () => { + return ( + + Loader + + Defikids + + + ); + }; + + return ( + + {Logo()} + + Coming Soon + + We are working hard to bring you the best experience. + + + + ); +}; + +export default ComingSoon; diff --git a/pages/_app.tsx b/pages/_app.tsx index 45695a4..a532bab 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -16,6 +16,7 @@ import { chains, wagmiConfig } from "@/services/wagmi/wagmiConfig"; import "@rainbow-me/rainbowkit/styles.css"; import { RainbowKitProvider } from "@rainbow-me/rainbowkit"; import { WagmiConfig } from "wagmi"; +import ComingSoon from "../components/ComingSoon"; function MyApp({ Component, pageProps }) { const [hasCheckedUserType, setHasCheckedUserType] = useState(false); @@ -46,6 +47,28 @@ function MyApp({ Component, pageProps }) { return true; }; + if (true) { + return ( + + + + {/* */} + + + + + ); + } + return ( Date: Sun, 10 Sep 2023 07:01:03 -0700 Subject: [PATCH 2/2] Unpin old avatar when updating --- BFF/ipfs/unpin.ts | 20 +++++++++++++ components/AvatarSelection.tsx | 50 +++++++++++++++++++++++++++++-- pages/_app.tsx | 22 -------------- pages/api/ipfs/unpin-from-ipfs.ts | 22 ++++++++++++++ 4 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 BFF/ipfs/unpin.ts create mode 100644 pages/api/ipfs/unpin-from-ipfs.ts diff --git a/BFF/ipfs/unpin.ts b/BFF/ipfs/unpin.ts new file mode 100644 index 0000000..d855c76 --- /dev/null +++ b/BFF/ipfs/unpin.ts @@ -0,0 +1,20 @@ +import pinataSDK from "@pinata/sdk"; + +import dotenv from "dotenv"; +dotenv.config(); + +export async function unpin({ hash }: { hash: string }) { + console.log("hash", hash); + const PINATA_KEY = process.env.PINATA_KEY; + const PINATA_SECRET_KEY = process.env.PINATA_SECRET_KEY; + + const pinata = new pinataSDK(PINATA_KEY, PINATA_SECRET_KEY); + + try { + const result = await pinata.unpin(hash); + return result; + } catch (error) { + console.error("Error unpinning file on IPFS:", error); + return { mediaError: "Internal Server Error" }; + } +} diff --git a/components/AvatarSelection.tsx b/components/AvatarSelection.tsx index 63ede7a..f684bad 100644 --- a/components/AvatarSelection.tsx +++ b/components/AvatarSelection.tsx @@ -35,6 +35,8 @@ export const AvatarSelection = ({ //============================================================================= const fileInputRef = useRef(null); + console.log("familyDetails - on load", familyDetails); + const openFileInput = () => { fileInputRef.current.click(); }; @@ -79,6 +81,19 @@ export const AvatarSelection = ({ } }; + const unpinFromIpfs = async (ipfsHash: string) => { + try { + // send as query param + const result = await axios.get( + `/api/ipfs/unpin-from-ipfs?ipfsHash=${ipfsHash}` + ); + console.log(result.data); + return result.data.success; + } catch (e) { + console.error(e as Error); + } + }; + const handleSubmit = async () => { console.log("selectedFile", selectedFile); setIsLoading(true); @@ -101,11 +116,40 @@ export const AvatarSelection = ({ return; } - setActiveStep(1); - const avatar = `https://ipfs.io/ipfs/${ifpsHash}`; console.log(avatar); + // delete old avatar from ipfs + console.log("familyDetails?.avatarURI", familyDetails?.avatarURI); + console.log("avatar", avatar); + console.log( + "familyDetails?.avatarURI.includes(ipfs)", + familyDetails?.avatarURI.includes("ipfs") + ); + console.log( + "familyDetails?.avatarURI !== avatar", + familyDetails?.avatarURI !== avatar + ); + if ( + familyDetails?.avatarURI && + familyDetails?.avatarURI.includes("ipfs") && + familyDetails?.avatarURI !== avatar + ) { + const oldIpfsHash = familyDetails?.avatarURI.split("/")[4]; + const result = await unpinFromIpfs(oldIpfsHash); + if (result.success === false) { + toast({ + title: "Error", + description: "Failed to delete old avatar from IPFS", + status: "error", + }); + setIsLoading(false); + return; + } + } + + setActiveStep(1); + const body = { ...familyDetails, avatarURI: avatar, @@ -116,6 +160,8 @@ export const AvatarSelection = ({ value: body, }; + console.log("payload", payload); + await axios.post(`/api/vercel/set-json`, payload); setUserDetails(body); fetchFamilyDetails(); diff --git a/pages/_app.tsx b/pages/_app.tsx index a532bab..0f2382b 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -47,28 +47,6 @@ function MyApp({ Component, pageProps }) { return true; }; - if (true) { - return ( - - - - {/* */} - - - - - ); - } - return (