Skip to content

Commit

Permalink
fix: bridge ui cookie hydration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
VGau committed Nov 20, 2024
1 parent c0b28f1 commit eb9566e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bridge-ui/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BridgeLayout from "@/components/bridge/BridgeLayout";

export default async function Home() {
export default function Home() {
return (
<div className="min-w-min max-w-lg md:m-auto">
<h1 className="mb-6 text-4xl font-bold md:hidden">Bridge</h1>
Expand Down
12 changes: 4 additions & 8 deletions bridge-ui/src/components/layouts/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { headers } from "next/headers";
import { cookieToInitialState } from "wagmi";
import { Web3Provider } from "@/contexts/web3.context";
import { ModalProvider } from "@/contexts/modal.context";
import { TokenStoreProvider } from "@/stores/tokenStoreProvider";
import { getTokenConfig } from "@/services/tokenService";
import { wagmiConfig } from "@/config";

type ProvidersProps = {
children: JSX.Element;
};

export async function Providers({ children }: ProvidersProps) {
const initialState = cookieToInitialState(wagmiConfig, headers().get("cookie"));
const tokensList = await getTokenConfig();

return (
<TokenStoreProvider initialState={{ tokensList }}>
<Web3Provider initialState={initialState}>
<Web3Provider>
<TokenStoreProvider initialState={{ tokensList }}>
<ModalProvider>{children}</ModalProvider>
</Web3Provider>
</TokenStoreProvider>
</TokenStoreProvider>
</Web3Provider>
);
}
4 changes: 0 additions & 4 deletions bridge-ui/src/config/wagmi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defaultWagmiConfig } from "@web3modal/wagmi/react/config";
import { cookieStorage, createStorage } from "wagmi";
import { http, injected } from "@wagmi/core";
import { mainnet, sepolia, linea, lineaSepolia } from "@wagmi/core/chains";
import { walletConnect, coinbaseWallet } from "@wagmi/connectors";
Expand Down Expand Up @@ -43,7 +42,4 @@ export const wagmiConfig = defaultWagmiConfig({
[linea.id]: http(`https://linea-mainnet.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_ID}`, { batch: true }),
[lineaSepolia.id]: http(`https://linea-sepolia.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_ID}`, { batch: true }),
},
storage: createStorage({
storage: cookieStorage,
}),
});
7 changes: 3 additions & 4 deletions bridge-ui/src/contexts/web3.context.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { ReactNode } from "react";
import { State, WagmiProvider } from "wagmi";
import { WagmiProvider } from "wagmi";
import { createWeb3Modal } from "@web3modal/wagmi/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { config, wagmiConfig } from "@/config";
Expand All @@ -14,12 +14,11 @@ createWeb3Modal({ wagmiConfig, projectId: config.walletConnectId });

type Web3ProviderProps = {
children: ReactNode;
initialState?: State;
};

export function Web3Provider({ children, initialState }: Web3ProviderProps) {
export function Web3Provider({ children }: Web3ProviderProps) {
return (
<WagmiProvider config={wagmiConfig} initialState={initialState}>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
);
Expand Down
4 changes: 2 additions & 2 deletions bridge-ui/src/services/tokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export async function fetchTokenInfo(
export async function getTokens(networkTypes: NetworkTypes): Promise<Token[]> {
try {
// Fetch the JSON data from the URL.
let url = process.env.NEXT_PUBLIC_MAINNET_TOKEN_LIST ? (process.env.NEXT_PUBLIC_MAINNET_TOKEN_LIST as string) : "";
let url = process.env.MAINNET_TOKEN_LIST ? (process.env.MAINNET_TOKEN_LIST as string) : "";
if (networkTypes === NetworkTypes.SEPOLIA) {
url = process.env.NEXT_PUBLIC_SEPOLIA_TOKEN_LIST ? (process.env.NEXT_PUBLIC_SEPOLIA_TOKEN_LIST as string) : "";
url = process.env.SEPOLIA_TOKEN_LIST ? (process.env.SEPOLIA_TOKEN_LIST as string) : "";
}

const response = await fetch(url);
Expand Down

0 comments on commit eb9566e

Please sign in to comment.