Skip to content

Commit

Permalink
Merge pull request #23 from daqhris/fix/query-client-setup
Browse files Browse the repository at this point in the history
Fix QueryClient setup for static generation
  • Loading branch information
daqhris authored Aug 10, 2024
2 parents 0fce5d0 + b729f57 commit 19f8c43
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 60 deletions.
5 changes: 3 additions & 2 deletions app/attestation/[uid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import React, { useEffect, useState } from "react";
import { Attestation } from "../../../types/attestation";
import { SchemaEncoder } from "@ethereum-attestation-service/eas-sdk";
import Lottie from "lottie-react";
// import Lottie from "lottie-react";
import tw from "tailwind-styled-components";
import { AttestationCard } from "~~/components/AttestationCard";
import skyAnimation from "~~/public/sky.json";

interface AttestationPageProps {
params: { uid: string };
Expand Down Expand Up @@ -154,6 +153,7 @@ export default function AttestationPage({ params }: AttestationPageProps) {
return (
<Container>
<AnimationWrapper>
{/* Lottie animation commented out to address build issues
<Lottie
animationData={skyAnimation}
style={{
Expand All @@ -165,6 +165,7 @@ export default function AttestationPage({ params }: AttestationPageProps) {
transform: "scale(3)",
}}
/>
*/}
</AnimationWrapper>
<Overlay />
<ContentWrapper>
Expand Down
15 changes: 15 additions & 0 deletions components/QueryClientProviderWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import getQueryClient from "../utils/queryClient";
import { QueryClientProvider } from "@tanstack/react-query";

interface QueryClientProviderWrapperProps {
children: React.ReactNode;
}

const QueryClientProviderWrapper: React.FC<QueryClientProviderWrapperProps> = ({ children }) => {
const queryClientRef = React.useRef(getQueryClient());

return <QueryClientProvider client={queryClientRef.current}>{children}</QueryClientProvider>;
};

export default QueryClientProviderWrapper;
5 changes: 2 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ const nextConfig = {
config.externals.push("pino-pretty", "lokijs", "encoding");
return config;
},
compiler: {
styledComponents: true,
},
images: {
domains: ['api.poap.tech', 'placehold.co'],
},
swcMinify: true,
compiler: undefined,
};

module.exports = nextConfig;
14 changes: 4 additions & 10 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import React from "react";
import getQueryClient from "../utils/queryClient";
import { QueryClientProvider } from "@tanstack/react-query";

const Custom404 = () => {
const queryClient = getQueryClient();

return (
<QueryClientProvider client={queryClient}>
<div>
<h1>404 - Page Not Found</h1>
<p>The page you are looking for does not exist.</p>
</div>
</QueryClientProvider>
<div>
<h1>404 - Page Not Found</h1>
<p>The page you are looking for does not exist.</p>
</div>
);
};

Expand Down
31 changes: 9 additions & 22 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from "react";
import type { AppProps } from "next/app";
import "../styles/globals.css";
import getQueryClient from "../utils/queryClient";
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
import { DehydratedState, HydrationBoundary, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { WagmiConfig, createConfig, http } from "wagmi";
import { mainnet, sepolia } from "wagmi/chains";
import QueryClientProviderWrapper from "../components/QueryClientProviderWrapper";

// Configure chains & providers
const config = createConfig({
Expand All @@ -23,28 +21,17 @@ const client = new ApolloClient({
cache: new InMemoryCache(),
});

type MyAppProps = AppProps & {
pageProps: {
dehydratedState?: DehydratedState;
};
};
type MyAppProps = AppProps;

function MyApp({ Component, pageProps }: MyAppProps) {
console.log("MyApp rendering");
const queryClient = getQueryClient();
console.log("QueryClient obtained:", queryClient);

return (
<QueryClientProvider client={queryClient}>
<HydrationBoundary state={pageProps.dehydratedState}>
<WagmiConfig config={config}>
<ApolloProvider client={client}>
<Component {...pageProps} />
</ApolloProvider>
</WagmiConfig>
</HydrationBoundary>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
<QueryClientProviderWrapper>
<WagmiConfig config={config}>
<ApolloProvider client={client}>
<Component {...pageProps} />
</ApolloProvider>
</WagmiConfig>
</QueryClientProviderWrapper>
);
}

Expand Down
14 changes: 4 additions & 10 deletions pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import React from "react";
import getQueryClient from "../utils/queryClient";
import { QueryClientProvider } from "@tanstack/react-query";
import { NextPageContext } from "next";

interface ErrorProps {
statusCode?: number;
}

const Error = ({ statusCode }: ErrorProps) => {
const queryClient = getQueryClient();

return (
<QueryClientProvider client={queryClient}>
<div>
<h1>Error {statusCode}</h1>
<p>{statusCode ? "An error " + statusCode + " occurred on server" : "An error occurred on client"}</p>
</div>
</QueryClientProvider>
<div>
<h1>Error {statusCode}</h1>
<p>{statusCode ? "An error " + statusCode + " occurred on server" : "An error occurred on client"}</p>
</div>
);
};

Expand Down
12 changes: 6 additions & 6 deletions pages/api/mission-enrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

const EASContractAddress = "0xC2679fBD37d54388Ce493F1DB75320D236e1815e"; // Sepolia v0.26
const missionEnrollmentSchemaUid = "0x40e5abe23a3378a9a43b7e874c5cb8dfd4d6b0823501d317acee41e08d3af4dd";
const provider = new ethers.AlchemyProvider("sepolia", process.env.NEXT_PUBLIC_ALCHEMY_API_KEY);
const provider = new ethers.providers.AlchemyProvider("sepolia", process.env.NEXT_PUBLIC_ALCHEMY_API_KEY);
const signer = new ethers.Wallet(process.env.ETH_KEY as string, provider);
const eas = new EAS(EASContractAddress);
eas.connect(signer);
eas.connect(signer as any);

const schemaEncoder = new SchemaEncoder("string missionProposal");

Expand All @@ -31,15 +31,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

const offchainAttestation = await offchain.signOffchainAttestation(
{
recipient: ethers.ZeroAddress,
recipient: ethers.constants.AddressZero,
data,
refUID: ethers.ZeroHash,
refUID: ethers.constants.HashZero,
revocable: true,
expirationTime: BigInt(0),
time: BigInt(Date.now() / 1000),
time: BigInt(Math.floor(Date.now() / 1000)),
schema: missionEnrollmentSchemaUid,
},
signer,
signer as any,
);

const encodedOffchainAttestation = offchainAttestation;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/poapVerification.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { verifyPOAPOwnership, verifyETHGlobalBrusselsPOAPOwnership } from "./poapVerification";
import { verifyETHGlobalBrusselsPOAPOwnership, verifyPOAPOwnership } from "./poapVerification";
import axios from "axios";

jest.mock("axios");
Expand Down
14 changes: 8 additions & 6 deletions utils/wagmi-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useEffect, useState } from "react";
import type { JsonRpcProvider, JsonRpcSigner } from "ethers";
import { ethers } from "ethers";
import { type HttpTransport, PublicClient, WalletClient } from "viem";
import { usePublicClient, useWalletClient } from "wagmi";

type JsonRpcProvider = ethers.providers.JsonRpcProvider;
type JsonRpcSigner = ethers.providers.JsonRpcSigner;

export function publicClientToProvider(publicClient: PublicClient) {
const { chain, transport } = publicClient;

Expand All @@ -18,12 +20,12 @@ export function publicClientToProvider(publicClient: PublicClient) {
};
if (transport.type === "fallback") {
const providers = (transport.transports as ReturnType<HttpTransport>[]).map(
({ value }) => new ethers.JsonRpcProvider(value?.url, network),
({ value }) => new ethers.providers.JsonRpcProvider(value?.url, network),
);
if (providers.length === 1) return providers[0];
return new ethers.FallbackProvider(providers);
return new ethers.providers.FallbackProvider(providers);
}
return new ethers.JsonRpcProvider(transport.url, network);
return new ethers.providers.JsonRpcProvider(transport.url, network);
}

export function walletClientToSigner(walletClient: WalletClient) {
Expand All @@ -42,8 +44,8 @@ export function walletClientToSigner(walletClient: WalletClient) {
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new ethers.BrowserProvider(transport, network);
return new ethers.JsonRpcSigner(provider, account.address);
const provider = new ethers.providers.Web3Provider(transport as any, network);
return provider.getSigner(account.address);
}

export function useSigner() {
Expand Down

0 comments on commit 19f8c43

Please sign in to comment.