Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #143: experimentally request summary data on server #145

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { QueryClientProvider } from '@tanstack/react-query';
import { ToastProvider } from '@penumbra-zone/ui/Toast';
import { TooltipProvider } from '@penumbra-zone/ui/Tooltip';
import { Header, SyncBar } from '@/widgets/header';
import { queryClient } from '@/shared/const/queryClient';
import { getQueryClient } from '@/shared/const/queryClient';

// Used so that observer() won't subscribe to any observables used in an SSR environment
// and no garbage collection problems are introduced.
enableStaticRendering(typeof window === 'undefined');

export const App = ({ children }: { children: ReactNode }) => {
return (
<QueryClientProvider client={queryClient}>
<QueryClientProvider client={getQueryClient()}>
<TooltipProvider>
<main className='relative z-0'>
<SyncBar />
Expand Down
3 changes: 0 additions & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const PnpmInstallPlugin = {

const nextConfig = {
transpilePackages: ['@penumbra-zone/protobuf'],
compiler: {
styledComponents: true,
},
webpack: config => {
config.module.rules.push({
test: /\.svg$/i,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"babel-loader": "^9.1.3",
"eslint": "8.57.0",
"eslint-config-next": "14.2.3",
"eslint-plugin-react": "^7.35.2",
"eslint-plugin-react": "^7.37.2",
"globals": "^15.9.0",
"kysely-codegen": "^0.17.0",
"postcss": "^8.4.47",
Expand Down
124 changes: 114 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/pages/trade/model/use-path.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use client';

import { useAssets } from '@/shared/api/assets';
import { useParams } from 'next/navigation';
import { useQuery } from '@tanstack/react-query';

interface PathParams {
export interface PathParams {
baseSymbol: string;
quoteSymbol: string;
[key: string]: string; // required for useParams signature
}

export const usePathSymbols = () => {
const params = useParams<PathParams>();
if (!params) {
if (!params?.baseSymbol || !params.quoteSymbol) {
throw new Error('No symbol params in path');
}
return { baseSymbol: params.baseSymbol, quoteSymbol: params.quoteSymbol };
Expand Down
36 changes: 36 additions & 0 deletions src/pages/trade/model/use-prefetch-summary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PathParams } from '@/pages/trade/model/use-path';
import { getSummary } from '@/shared/api/server/summary';
import { DurationWindow } from '@/shared/utils/duration.ts';
import { getQueryClient } from '@/shared/const/queryClient';
import { useServerParams } from '@/shared/utils/server-params';

export const usePrefetchSummary = (window: DurationWindow) => {
const queryClient = getQueryClient();
const { baseSymbol, quoteSymbol } = useServerParams<PathParams>();

return {
queryClient,
prefetch: () =>
queryClient.prefetchQuery({
queryKey: ['summary', baseSymbol, quoteSymbol],
queryFn: async () => {
const paramsObj = {
durationWindow: window,
baseAsset: baseSymbol,
quoteAsset: quoteSymbol,
};
const baseUrl = 'https://localhost/api/summary';
const urlParams = new URLSearchParams(paramsObj).toString();
const res = await getSummary({ url: `${baseUrl}?${urlParams}` });
if ('error' in res) {
throw new Error(res.error);
}
return {
...res,
asset_start: res.asset_start.toJSON(),
asset_end: res.asset_end.toJSON(),
};
},
}),
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { usePathSymbols } from '@/pages/trade/model/use-path.ts';
import { SummaryResponse } from '@/shared/api/server/summary.ts';
import { usePathSymbols } from '@/pages/trade/model/use-path';
import { SummaryResponse } from '@/shared/api/server/summary';
import { DurationWindow } from '@/shared/utils/duration.ts';

export const useSummary = (window: DurationWindow) => {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/trade/ui/chart.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import cn from 'clsx';
import { useEffect, useRef, useState } from 'react';
import { createChart, IChartApi, OhlcData } from 'lightweight-charts';
Expand Down
2 changes: 2 additions & 0 deletions src/pages/trade/ui/form-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useState } from 'react';
import { useAutoAnimate } from '@formkit/auto-animate/react';
import { Tabs } from '@penumbra-zone/ui/Tabs';
Expand Down
2 changes: 2 additions & 0 deletions src/pages/trade/ui/history-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useState } from 'react';
import { useAutoAnimate } from '@formkit/auto-animate/react';
import { Tabs } from '@penumbra-zone/ui/Tabs';
Expand Down
Loading