Skip to content

Commit

Permalink
Review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 committed Nov 6, 2024
1 parent b1b4336 commit 9c5c982
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 51 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"framer-motion": "^11.3.31",
"grpc-tools": "^1.12.4",
"grpc_tools_node_protoc_ts": "^5.3.3",
"iso-datestring-validator": "^2.2.2",
"kysely": "^0.27.4",
"lightweight-charts": "^4.2.0",
"lodash": "^4.17.21",
Expand Down
11 changes: 0 additions & 11 deletions pnpm-lock.yaml

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

10 changes: 1 addition & 9 deletions src/pages/trade/api/candles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@ import { usePathSymbols } from '@/pages/trade/model/use-path.ts';
import { OhlcData } from 'lightweight-charts';
import { DurationWindow } from '@/shared/database/schema.ts';

const DEX_ENABLED_DATE = '2024-08-01';

export const useCandles = (durationWindow: DurationWindow) => {
const { baseSymbol, quoteSymbol } = usePathSymbols();

const query = useQuery({
queryKey: ['candles', baseSymbol, quoteSymbol, durationWindow, DEX_ENABLED_DATE],
queryKey: ['candles', baseSymbol, quoteSymbol, durationWindow],
queryFn: async (): Promise<OhlcData[]> => {
const todayIso = new Date().toISOString().split('T')[0];
if (!todayIso) {
throw new Error("Unable to generate today's date as an iso string");
}
const paramsObj = {
baseAsset: baseSymbol,
quoteAsset: quoteSymbol,
startDate: todayIso,
endDate: DEX_ENABLED_DATE,
durationWindow,
};
const baseUrl = '/api/candles';
Expand Down
3 changes: 3 additions & 0 deletions src/pages/trade/redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { redirect } from 'next/navigation';
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { envQueryFn } from '@/shared/api/env/env.ts';
import { useQuery } from '@tanstack/react-query';
import { assetPatterns } from '@penumbra-zone/types/assets';

const redirectSymbolsQueryFn = async () => {
const { PENUMBRA_CHAIN_ID } = await envQueryFn();
const chainRegistryClient = new ChainRegistryClient();
const registry = await chainRegistryClient.remote.get(PENUMBRA_CHAIN_ID);
const allAssets = registry
.getAllAssets()
.filter(m => !assetPatterns.delegationToken.matches(m.display))
.toSorted((a, b) => Number(b.priorityScore - a.priorityScore));

const baseAsset = allAssets[0]?.symbol;
const quoteAsset = allAssets[1]?.symbol;
if (!baseAsset || !quoteAsset) {
Expand Down
21 changes: 0 additions & 21 deletions src/shared/api/server/candles/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { pindexer } from '@/shared/database';
import { isValidDate } from 'iso-datestring-validator';
import { CandleApiResponse } from '@/shared/api/server/candles/types.ts';
import { durationWindows, isDurationWindow } from '@/shared/database/schema.ts';
import { dbCandleToOhlc, mergeCandles } from '@/shared/api/server/candles/utils.ts';
Expand Down Expand Up @@ -33,22 +32,6 @@ export async function GET(req: NextRequest): Promise<NextResponse<CandleApiRespo
);
}

const startDateParam = searchParams.get('startDate');
const endDateParam = searchParams.get('endDate');
if (
!startDateParam ||
!endDateParam ||
!isValidDate(startDateParam) ||
!isValidDate(endDateParam)
) {
return NextResponse.json(
{ error: 'start or end date missing or invalid iso format' },
{ status: 400 },
);
}
const startDate = new Date(startDateParam);
const endDate = new Date(endDateParam);

const registryClient = new ChainRegistryClient();
const registry = await registryClient.remote.get(chainId);

Expand All @@ -71,15 +54,11 @@ export async function GET(req: NextRequest): Promise<NextResponse<CandleApiRespo
const candlesFwd = await pindexer.candles(
baseAssetMetadata.penumbraAssetId,
quoteAssetMetadata.penumbraAssetId,
startDate,
endDate,
durationWindow,
);
const candlesReverse = await pindexer.candles(
quoteAssetMetadata.penumbraAssetId,
baseAssetMetadata.penumbraAssetId,
startDate,
endDate,
durationWindow,
);

Expand Down
10 changes: 1 addition & 9 deletions src/shared/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,14 @@ class Pindexer {
.execute();
}

async candles(
baseAsset: AssetId,
quoteAsset: AssetId,
start: Date,
end: Date,
window: DurationWindow,
) {
async candles(baseAsset: AssetId, quoteAsset: AssetId, window: DurationWindow) {
return this.db
.selectFrom('dex_ex_price_charts')
.innerJoin('dex_ex_candlesticks', 'candlestick_id', 'dex_ex_candlesticks.id')
.select(['start_time', 'open', 'close', 'low', 'high', 'swap_volume', 'direct_volume'])
.where('the_window', '=', window)
.where('asset_start', '=', Buffer.from(baseAsset.inner))
.where('asset_end', '=', Buffer.from(quoteAsset.inner))
.where('start_time', '<', start)
.where('start_time', '>=', end)
.execute();
}
}
Expand Down

0 comments on commit 9c5c982

Please sign in to comment.