diff --git a/src/app/pool/page.tsx b/src/app/pool/page.tsx index 5dc4107..d8be2c8 100644 --- a/src/app/pool/page.tsx +++ b/src/app/pool/page.tsx @@ -37,8 +37,6 @@ function PoolPage() { const needSwitch = currentId && chainId && currentId !== chainId; - console.log("needSwitch", needSwitch, currentId, chainId, chain); - useMemo(() => { if (!chainId || !currentId || !chain) return; switchChain({ chainId: chain }); diff --git a/src/app/pools/page.tsx b/src/app/pools/page.tsx index 723723f..4439f84 100644 --- a/src/app/pools/page.tsx +++ b/src/app/pools/page.tsx @@ -144,13 +144,15 @@ const PoolsPage = () => {
{pools && - pools.map((pool, i) => ( - - ))} + pools.map((pool, i) => + /^ipfs/.test(pool.tokenURI) ? ( + + ) : undefined + )}
{pools && pools.length > 0 ? ( diff --git a/src/components/UI/Pool/Details/Details.tsx b/src/components/UI/Pool/Details/Details.tsx index 769cfbe..5cdb16f 100644 --- a/src/components/UI/Pool/Details/Details.tsx +++ b/src/components/UI/Pool/Details/Details.tsx @@ -5,6 +5,7 @@ import { usePoolData } from "@/src/hooks/usePools"; import { useTimestamp } from "@/src/hooks/useTimestamps"; import { Manage } from "@toqen/react"; import Image from "next/image"; +import Link from "next/link"; import { useMemo, useState } from "react"; import { PiCoinsDuotone, @@ -149,13 +150,7 @@ export const Details = () => {
{launchBlock}
- - Block #{pool?.launchBlock.toString()} - + Block #{pool?.launchBlock.toString()}
@@ -224,15 +219,15 @@ export const Details = () => { {pool?.owner && pool?.owner === ZERO_ADDRESS ? ( <>NONE ) : ( - {pool?.owner && pool?.owner === ZERO_ADDRESS ? `NONE` : pool?.owner} - + )} diff --git a/src/components/UI/Pool/Hero/Hero.tsx b/src/components/UI/Pool/Hero/Hero.tsx index 63cf5ec..b2fd698 100644 --- a/src/components/UI/Pool/Hero/Hero.tsx +++ b/src/components/UI/Pool/Hero/Hero.tsx @@ -1,4 +1,5 @@ import { TOKEN_LOGO, ZERO_ADDRESS as ZERO } from "@/src/constants"; +import { useWriteStaqeProtocolEditPool } from "@/src/generated"; import { useMetadata } from "@/src/hooks/useMetadata"; import { usePoolData } from "@/src/hooks/usePools"; import { useTimestamp } from "@/src/hooks/useTimestamps"; @@ -76,6 +77,8 @@ export const Hero = () => { return result; }, [pool]); + const { writeContract, status: offChain } = useWriteStaqeProtocolEditPool(); + return (
@@ -100,7 +103,25 @@ export const Hero = () => { > )}
-
+
+ { + pool?.id && + writeContract({ + args: [ + BigInt(pool?.id), + 0n, + /^_/.test(pool?.tokenURI) + ? `${pool?.tokenURI.replace(/^_/, "")}` + : `_${pool?.tokenURI}`, + ], + }); + }} + > + {pool?.tokenURI && + (/^_/.test(pool?.tokenURI) ? `show pool` : `hide pool`)} +
{metadata && ( diff --git a/src/components/UI/Pools/Card.tsx b/src/components/UI/Pools/Card.tsx index 48a4128..21f72b7 100644 --- a/src/components/UI/Pools/Card.tsx +++ b/src/components/UI/Pools/Card.tsx @@ -15,8 +15,6 @@ const Stake = ({ erc721?: IToken | undefined; metadata: IMetadata | undefined; }) => { - console.log("metadata", metadata); - const logoERC20 = useMemo(() => { if (!metadata || !erc20) return TOKEN_LOGO; return metadata?.logoURIs?.[erc20.tokenAddress]; @@ -64,7 +62,7 @@ const Stake = ({ {hasERC20 && (
ERC20 ERC721 Reward string | null; - setItem: (key: string, value: string) => void; + getItem: (key: string) => string | null; + setItem: (key: string, value: string) => void; } const localStorageFallback: IStorage = { - getItem: () => null, - setItem: () => { }, + getItem: () => null, + setItem: () => {}, }; // window.localStorage -const storage: IStorage = isBrowser ? window.localStorage : localStorageFallback; +const storage: IStorage = isBrowser + ? window.localStorage + : localStorageFallback; -export const fetchMetadata = async (tokenURI: string | undefined): Promise => { - if (tokenURI === undefined || tokenURI === '') return; +export const fetchMetadata = async ( + tokenURI: string | undefined +): Promise => { + if (tokenURI === undefined || tokenURI === "") return; - const lastUpdateMetadata = storage.getItem("lastUpdateMetadata"); - const nowDate = new Date().getTime(); - const updDate = new Date(parseInt(lastUpdateMetadata || "0", 10)).getTime(); - const shouldFetch = nowDate - updDate > 0; // 86400000 + const lastUpdateMetadata = storage.getItem("lastUpdateMetadata"); + const nowDate = new Date().getTime(); + const updDate = new Date(parseInt(lastUpdateMetadata || "0", 10)).getTime(); + const shouldFetch = nowDate - updDate > 0; // 86400000 - if (!shouldFetch) return defaultMetadata; + if (!shouldFetch) return defaultMetadata; - const response = await fetch(`${GATEWAY_URL}${tokenURI.replace(/ipfs:\/\//g, "")}`); + const response = /^ipfs/.test(tokenURI) + ? await fetch(`${GATEWAY_URL}${tokenURI.replace(/ipfs:\/\//g, "")}`) + : null; - if (!response.ok) return defaultMetadata; + if (!response || !response.ok) return defaultMetadata; - const metadata: IMetadata = await response.json(); + const metadata: IMetadata = await response.json(); - metadata.image = /^ipfs/.test(metadata.image) - ? `${GATEWAY_URL}${metadata.image.replace(/ipfs:\/\//g, "")}` - : metadata.image; - metadata.banner_image = /^ipfs/.test(metadata.banner_image ?? "") - ? `${GATEWAY_URL}${(metadata.banner_image ?? "").replace(/ipfs:\/\//g, "")}` - : metadata.banner_image; + metadata.image = /^ipfs/.test(metadata.image) + ? `${GATEWAY_URL}${metadata.image.replace(/ipfs:\/\//g, "")}` + : metadata.image; + metadata.banner_image = /^ipfs/.test(metadata.banner_image ?? "") + ? `${GATEWAY_URL}${(metadata.banner_image ?? "").replace(/ipfs:\/\//g, "")}` + : metadata.banner_image; - if (metadata.tokens && metadata.tokens.length) { - metadata.tokens.forEach(token => { - if (token.address && token.logoURI) { - if (!metadata.logoURIs) { - metadata.logoURIs = {} - } - metadata.logoURIs[token.address] = `${GATEWAY_URL}${(token.logoURI ?? "").replace(/ipfs:\/\//g, "")}`; - } - }) - } + if (metadata.tokens && metadata.tokens.length) { + metadata.tokens.forEach((token) => { + if (token.address && token.logoURI) { + if (!metadata.logoURIs) { + metadata.logoURIs = {}; + } + metadata.logoURIs[token.address] = + `${GATEWAY_URL}${(token.logoURI ?? "").replace(/ipfs:\/\//g, "")}`; + } + }); + } - storage.setItem(tokenURI, JSON.stringify(metadata)); - storage.setItem("lastUpdateMetadata", nowDate.toString()); + storage.setItem(tokenURI, JSON.stringify(metadata)); + storage.setItem("lastUpdateMetadata", nowDate.toString()); - return metadata; + return metadata; }; -export const getMetadata = async (tokenURI: string): Promise => { - try { - const storedMetadata = storage.getItem(tokenURI); - // return storedMetadata ? JSON.parse(storedMetadata) : await fetchMetadata(tokenURI); - return await fetchMetadata(tokenURI); - } catch (error) { - console.error("Failed to fetch or parse metadata:", error); - return defaultMetadata; - } +export const getMetadata = async ( + tokenURI: string +): Promise => { + try { + const storedMetadata = storage.getItem(tokenURI); + // return storedMetadata ? JSON.parse(storedMetadata) : await fetchMetadata(tokenURI); + return await fetchMetadata(tokenURI); + } catch (error) { + console.error("Failed to fetch or parse metadata:", error); + return defaultMetadata; + } };