From 59d4c54ee17ff1459214369eb6e3fedf2073ca83 Mon Sep 17 00:00:00 2001 From: Lucemans Date: Sun, 2 Jun 2024 08:44:25 +0000 Subject: [PATCH] Update VaultEntry Fetching --- src/components/vaults/VaultEntry.tsx | 2 +- src/hooks/useExpiryNames.tsx | 2 +- src/hooks/useVaultNames.tsx | 49 ++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/components/vaults/VaultEntry.tsx b/src/components/vaults/VaultEntry.tsx index 63f50c0..d22f334 100644 --- a/src/components/vaults/VaultEntry.tsx +++ b/src/components/vaults/VaultEntry.tsx @@ -36,7 +36,7 @@ export const VaultEntry: FC<{ vault: bigint }> = ({ vault }) => {
-
{names.length} names
+
{names?.length} names
{formatEther(balance || 0n)} ETH
diff --git a/src/hooks/useExpiryNames.tsx b/src/hooks/useExpiryNames.tsx index 2c3eb98..eaa6919 100644 --- a/src/hooks/useExpiryNames.tsx +++ b/src/hooks/useExpiryNames.tsx @@ -34,7 +34,7 @@ export const useExpiryNames = () => { const { data: block } = useBlockNumber({ chainId }); return useSWR( - "/subgrpah/" + block, + "/subgraph/all/" + block, async (): Promise<{ name: string; vault: string }[]> => { const x = await axios.post( // Yes, this uses a cors-anywhere bypass. This is a demo. diff --git a/src/hooks/useVaultNames.tsx b/src/hooks/useVaultNames.tsx index 348ec60..4560fe8 100644 --- a/src/hooks/useVaultNames.tsx +++ b/src/hooks/useVaultNames.tsx @@ -1,8 +1,51 @@ -import { useChainId } from "wagmi"; +import axios from "axios"; +import { gql } from "graphql-request"; +import useSWR from "swr"; +import { useBlockNumber, useChainId } from "wagmi"; +const query = gql` + query byVault($vaultId: BigFloat) { + allRescuenameNameAddeds(condition: { vault: $vaultId }) { + nodes { + name + } + } + } +`; + +export type ExpiryNames = { + data: { + allRescuenameNameAddeds: { + nodes: { + name: string; + }[]; + }; + }; +}; export const useVaultNames = (vaultId: bigint) => { const chainId = useChainId(); + const { data: block } = useBlockNumber({ chainId }); + + return useSWR( + "/subgraph/" + vaultId + "/" + block, + async (): Promise => { + const x = await axios.post( + // Yes, this uses a cors-anywhere bypass. This is a demo. + // The streamingfast entrypoint doesnt output the right cors headers + "https://cors-anywhere.herokuapp.com/https://srv.streamingfast.io/01bfe668/graphql", + { + query, + variables: { vaultId: vaultId.toString() } + } + ); + + const xy = x.data as ExpiryNames; + + console.log({ xy }); - // TODO: hook up to substream - return { data: ["lucemans", "nevvdevv"] }; + return xy.data.allRescuenameNameAddeds.nodes + .filter((node) => node.name.length >= 5) + .map((node) => node.name); + } + ); };