From 1abe4067e6867e05dfca09b8af1fdcebc986d5b1 Mon Sep 17 00:00:00 2001 From: John Ballesteros Date: Wed, 3 Apr 2024 17:11:23 +0800 Subject: [PATCH] refactor: add wallet data hooks and cb --- app/layout.tsx | 27 +++++++++++---- src/shared/providers/wallet-provider.tsx | 43 +++++++++++++++++++---- src/users/api/get-wallet-data.ts | 18 ++++++++++ src/users/core/constants.ts | 22 ++++++++++++ src/users/core/query-keys.ts | 5 +++ src/users/core/schemas.ts | 44 ++++++++++++++++++++++++ src/users/hooks/use-wallet-data.ts | 14 ++++++++ 7 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 src/users/api/get-wallet-data.ts create mode 100644 src/users/core/constants.ts create mode 100644 src/users/core/query-keys.ts create mode 100644 src/users/core/schemas.ts create mode 100644 src/users/hooks/use-wallet-data.ts diff --git a/app/layout.tsx b/app/layout.tsx index 7558e503f..c64ff3c5f 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,8 +2,11 @@ import './globals.css'; import type { Metadata, Viewport } from 'next'; -import { METADATA } from '~/shared/core/constants'; +import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; + +import { METADATA, QUERY_STALETIME } from '~/shared/core/constants'; import { lato, roboto } from '~/shared/core/fonts'; +import { getQueryClient } from '~/shared/utils/get-query-client'; import { ConnectWalletButton } from '~/shared/components/connect-wallet-button'; import { InitPathSyncer } from '~/shared/components/init-path-syncer'; import { Nav } from '~/shared/components/nav'; @@ -13,6 +16,9 @@ import { ReactQueryProvider } from '~/shared/providers/react-query-provider'; import { WagmiProvider } from '~/shared/providers/wagmi-provider'; import { WalletProvider } from '~/shared/providers/wallet-provider'; +import { userQueryKeys } from '~/users/core/query-keys'; +import { getWalletData } from '~/users/api/get-wallet-data'; + export const metadata: Metadata = { title: METADATA.SITE_NAME, description: METADATA.SITE_SLOGAN, @@ -26,17 +32,26 @@ export const viewport: Viewport = { viewportFit: 'cover', }; -const RootLayout = ({ children }: { children: React.ReactNode }) => { +const RootLayout = async ({ children }: { children: React.ReactNode }) => { + const queryClient = getQueryClient(); + await queryClient.prefetchQuery({ + queryKey: userQueryKeys.walletData(), + queryFn: () => getWalletData(), + staleTime: QUERY_STALETIME.DEFAULT, + }); + return ( - -