Skip to content

Commit

Permalink
feat: bundle graphql data in with source code
Browse files Browse the repository at this point in the history
  • Loading branch information
aidankinzett committed May 21, 2024
1 parent 83f0364 commit 90c611c
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 12 deletions.
29 changes: 29 additions & 0 deletions web/src/app/PopulateQueryCache.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

import { useEffect } from "react";
import { queryClient } from "@/context";
import { AllDataQuery } from "@/gql/graphql";

/**
* This component is used to populate the query cache with the data fetched from the server.
* To use this fetch the data from the server in a server component and pass it to this component.
*/
export default function PopulateQueryCache({
data,
featuresData,
}: {
data: AllDataQuery;
featuresData: any;
}) {
useEffect(() => {
// using the same query key as in useGraphql.tsx
queryClient.setQueryData(["graphql"], data);
}, [data]);

useEffect(() => {
// using the same query key as in useFeatureFlag.tsx
queryClient.setQueryData(["featureFlags"], featuresData);
}, [featuresData]);

return null;
}
10 changes: 8 additions & 2 deletions web/src/app/faucet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const FaucetPage = () => {
abi: faucet.abi,
// @ts-expect-error
functionName: "isMember",
// @ts-expect-error
args: [address as Hash],
});

Expand All @@ -38,7 +39,7 @@ const FaucetPage = () => {
return;
}

const hash = await writeContract({
const hash = writeContract({
address: faucetAddress,
abi: faucet.abi,
functionName: "claimAmount",
Expand All @@ -58,7 +59,12 @@ const FaucetPage = () => {
<h1 className={"w-full text-xs"}>Faucet</h1>
<p>Request a random amount of test tokens ($FLY stakers only)</p>
<img src="https://static.long.so/fly-stakers.jpg" />
<Button className={"w-full"} variant={"secondary"} onClick={onClick} disabled={!isStaker}>
<Button
className={"w-full"}
variant={"secondary"}
onClick={onClick}
disabled={!isStaker}
>
Request
</Button>
</div>
Expand Down
21 changes: 19 additions & 2 deletions web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { NavigationMenu } from "@/app/_layout/NavigationMenu";
import { Inter } from "next/font/google";
import { cn } from "@/lib/utils";
import { FeatureFlagConfig } from "@/app/_layout/FeatureFlagConfig";
import { useQueryClient } from "@tanstack/react-query";
import request from "graphql-request";
import { graphqlEndpoint } from "@/config/graphqlEndpoint";
import { graphqlQuery } from "@/hooks/useGraphql";
import PopulateQueryCache from "@/app/PopulateQueryCache";

const title = "Long Tail AMM";

Expand All @@ -29,7 +34,7 @@ export const metadata: Metadata = {
siteId: "",
creator: "@superpositionso",
creatorId: "",
images: [image]
images: [image],
},
openGraph: {
title: "Long Tail AMM",
Expand All @@ -50,15 +55,27 @@ const inter = Inter({
weight: ["400", "500"],
});

export default function RootLayout({
export const dynamic = "force-static";

export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const gitHash = process.env.GIT_HASH;

// make server-side requests for pre-fetching data
const data = await request(graphqlEndpoint, graphqlQuery);

const featuresDataRequest = await fetch(
"https://features.long.so/features.json",
);
const featuresData = await featuresDataRequest.json();

return (
<html lang="en">
<Provider>
<PopulateQueryCache data={data} featuresData={featuresData} />
<body
className={cn("flex min-h-screen flex-col bg-white", inter.className)}
>
Expand Down
9 changes: 8 additions & 1 deletion web/src/app/stake/AllPools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ export const AllPoolsFragment = graphql(`
}
}
}
liquidityOverTime {
tvlOverTime {
daily
}
liquidityOverTime {
daily {
fusdc {
valueScaled
}
}
}
liquidityIncentives {
valueUsd
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { State, WagmiProvider } from "wagmi";

// Setup queryClient
const queryClient = new QueryClient();
export const queryClient = new QueryClient();

if (!projectId) throw new Error("Project ID is not defined");

Expand Down
4 changes: 2 additions & 2 deletions web/src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
*/
const documents = {
"\n fragment SwapFormFragment on SeawaterPool {\n address\n earnedFeesAPRFUSDC\n earnedFeesAPRToken1\n token {\n address\n decimals\n name\n symbol\n }\n }\n": types.SwapFormFragmentFragmentDoc,
"\n fragment AllPoolsFragment on SeawaterPool {\n address\n token {\n name\n }\n volumeOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n tvlOverTime {\n daily\n }\n liquidityIncentives {\n valueUsd\n }\n superIncentives {\n valueUsd\n }\n }\n": types.AllPoolsFragmentFragmentDoc,
"\n fragment AllPoolsFragment on SeawaterPool {\n address\n token {\n name\n }\n volumeOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n tvlOverTime {\n daily\n }\n liquidityOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n liquidityIncentives {\n valueUsd\n }\n superIncentives {\n valueUsd\n }\n }\n": types.AllPoolsFragmentFragmentDoc,
"\n fragment SelectPrimeAssetFragment on SeawaterPool {\n address\n volumeOverTime {\n daily {\n fusdc {\n valueUsd\n }\n }\n }\n token {\n name\n symbol\n address\n }\n }\n": types.SelectPrimeAssetFragmentFragmentDoc,
"\n fragment ManagePoolFragment on SeawaterPool {\n address\n id\n token {\n symbol\n name\n }\n liquidityIncentives {\n valueScaled # TODO: we want a percentage here\n }\n superIncentives {\n valueScaled # TODO: we want a percentage here\n }\n utilityIncentives {\n amountGivenOut\n maximumAmount\n }\n earnedFeesAPRFUSDC\n }\n": types.ManagePoolFragmentFragmentDoc,
"\n fragment SwapExploreFragment on SeawaterPool {\n token {\n name\n symbol\n address\n }\n price\n }\n": types.SwapExploreFragmentFragmentDoc,
Expand Down Expand Up @@ -44,7 +44,7 @@ export function graphql(source: "\n fragment SwapFormFragment on SeawaterPool {
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment AllPoolsFragment on SeawaterPool {\n address\n token {\n name\n }\n volumeOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n tvlOverTime {\n daily\n }\n liquidityIncentives {\n valueUsd\n }\n superIncentives {\n valueUsd\n }\n }\n"): (typeof documents)["\n fragment AllPoolsFragment on SeawaterPool {\n address\n token {\n name\n }\n volumeOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n tvlOverTime {\n daily\n }\n liquidityIncentives {\n valueUsd\n }\n superIncentives {\n valueUsd\n }\n }\n"];
export function graphql(source: "\n fragment AllPoolsFragment on SeawaterPool {\n address\n token {\n name\n }\n volumeOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n tvlOverTime {\n daily\n }\n liquidityOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n liquidityIncentives {\n valueUsd\n }\n superIncentives {\n valueUsd\n }\n }\n"): (typeof documents)["\n fragment AllPoolsFragment on SeawaterPool {\n address\n token {\n name\n }\n volumeOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n tvlOverTime {\n daily\n }\n liquidityOverTime {\n daily {\n fusdc {\n valueScaled\n }\n }\n }\n liquidityIncentives {\n valueUsd\n }\n superIncentives {\n valueUsd\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit 90c611c

Please sign in to comment.