-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string[]> => { | ||
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); | ||
} | ||
); | ||
}; |