-
Notifications
You must be signed in to change notification settings - Fork 1
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
Candles v2 (time windows) #128
Changes from all commits
6c7db97
7f50851
8102bd1
04c2020
c507d1b
b1b4336
9c5c982
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { GET } from '@/shared/api/server/candles/index.ts'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { redirect } from 'next/navigation'; | ||
import { RedirectToPair } from '@/pages/trade/redirect.tsx'; | ||
|
||
export default function RedirectPage() { | ||
redirect('/trade/UM/GM'); | ||
} | ||
export default RedirectToPair; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useRefetchOnNewBlock } from '@/shared/api/compact-block.ts'; | ||
import { RouteBookResponse, RouteBookResponseJson } from '@/shared/api/server/book/types'; | ||
import { RouteBookResponse } from '@/shared/api/server/book/types'; | ||
import { deserializeRouteBookResponseJson } from '@/shared/api/server/book/serialization.ts'; | ||
import { RouteBookApiResponse } from '@/shared/api/server/book'; | ||
import { usePathSymbols } from '@/pages/trade/model/use-path.ts'; | ||
|
||
export const useBook = (symbol1: string | undefined, symbol2: string | undefined) => { | ||
export const useBook = () => { | ||
const { baseSymbol, quoteSymbol } = usePathSymbols(); | ||
const query = useQuery({ | ||
queryKey: ['book', symbol1, symbol2], | ||
queryKey: ['book', baseSymbol, quoteSymbol], | ||
queryFn: async (): Promise<RouteBookResponse> => { | ||
if (!symbol1 || !symbol2) { | ||
throw new Error('Missing symbols'); | ||
} | ||
|
||
const paramsObj = { | ||
baseAsset: symbol1, | ||
quoteAsset: symbol2, | ||
baseAsset: baseSymbol, | ||
quoteAsset: quoteSymbol, | ||
}; | ||
const baseUrl = '/api/book'; | ||
const urlParams = new URLSearchParams(paramsObj).toString(); | ||
const res = await fetch(`${baseUrl}?${urlParams}`); | ||
const data = (await res.json()) as RouteBookResponseJson; | ||
return deserializeRouteBookResponseJson(data); | ||
const jsonRes = (await res.json()) as RouteBookApiResponse; | ||
if ('error' in jsonRes) { | ||
throw new Error(jsonRes.error); | ||
} | ||
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because nextjs can return an error field, we need to parse it and re-throw if we see it |
||
return deserializeRouteBookResponseJson(jsonRes); | ||
}, | ||
enabled: !!symbol1 && !!symbol2, | ||
}); | ||
|
||
useRefetchOnNewBlock(query); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use client'; | ||
|
||
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) { | ||
throw new Error('Could not find symbols in registry'); | ||
} | ||
|
||
return { baseAsset, quoteAsset }; | ||
}; | ||
|
||
export const RedirectToPair = () => { | ||
const { data, isLoading, error } = useQuery({ | ||
queryKey: ['redirectSymbols'], | ||
retry: 1, | ||
queryFn: redirectSymbolsQueryFn, | ||
}); | ||
|
||
if (error) { | ||
return <div className='text-red-600'>{String(error)}</div>; | ||
} else if (isLoading || !data) { | ||
return <div className='text-white'>Loading...</div>; | ||
} else { | ||
redirect(`/trade/${data.baseAsset}/${data.quoteAsset}`); | ||
} | ||
}; | ||
Comment on lines
+27
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was finding it a bit annoying that we had a hard-coded pair here. This causes issues when going back and forth between testnet/mainnet. When ahead and created a hook to pull the highest priority pair and show that as the default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely a bug in the implementation. I should have been filtering out delegation tokens, fixed! Also, added some sample priority scores: prax-wallet/registry#109. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, but we have an issue for that: #107 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realizing a few hooks are relying upon async data fetching for the path symbols. This is not necessary because they are synchronously available. So created a new
usePathSymbols();
for that.