-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
|
||
export const useBook = (symbol1: string | undefined, symbol2: string | undefined) => { | ||
export const useBook = () => { | ||
const { baseSymbol, quoteSymbol } = usePathSymbols(); |
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.
const jsonRes = (await res.json()) as RouteBookApiResponse; | ||
if ('error' in jsonRes) { | ||
throw new Error(jsonRes.error); | ||
} |
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.
Because nextjs can return an error field, we need to parse it and re-throw if we see it
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}`); | ||
} | ||
}; |
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.
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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but we have an issue for that: #107
// TODO: Delete when possible, this is deprecated | ||
export class IndexerQuerier { | ||
private pool: Pool; |
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.
Bye bye old db client
@@ -72,10 +74,10 @@ export async function GET(req: NextRequest): Promise<NextResponse<AllResponses>> | |||
output: baseAssetMetadata.penumbraAssetId, | |||
}); | |||
|
|||
const simQuerier = new SimulationQuerier({ grpcEndpoint }); | |||
const client = createClient(grpcEndpoint, SimulationService); |
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.
Finding the query classes to be unnecessary, we can just create a client in line when we want to query
1b541d1
to
c507d1b
Compare
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.
Nearly this whole file was copied over from the previous implementation
src/shared/database/index.ts
Outdated
async candles( | ||
baseAsset: AssetId, | ||
quoteAsset: AssetId, | ||
start: Date, | ||
end: Date, | ||
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(); |
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.
@conorsch after this is merged, the nextjs app will no longer have a dependency on the old database and only on the new one fyi. |
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.
Encountered one large bug related to the initial route redirect, see screenshot shared above. Standing by to assist with backend changes once we're happy with the diff.
src/pages/trade/api/candles.tsx
Outdated
import { OhlcData } from 'lightweight-charts'; | ||
import { DurationWindow } from '@/shared/database/schema.ts'; | ||
|
||
const DEX_ENABLED_DATE = '2024-08-01'; |
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.
The DEX_ENABLED_DATE
const is applicable only to the penumbra-1
chain; in general I'd prefer to avoid assumptions about chain id in any of the frontend code bases. Practically speaking, I don't expect this specific assumption to have adverse affects for e.g. testnet chains, but at the same time, are we really gaining anything from it? The genesis date is not far behind the dex-enable date for penumbra-1
, and as time goes on, the comparative savings on the query will be minuscule.
Is the motivation for this cut-off date to make queries more efficient, or does the cut-off date avoid the need for error handling or similar?
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.
Good catch. We should make this chain agnostic. Given we have such little data, it's hard for me to determine what is the upper bound for this query. Aka, should we only be pulling data from the last year? Alas, I'm going to remove the start/end date logic and just pull whatever candlestick data is in the database. Think it's worthwhile revisiting this topic in a year.
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}`); | ||
} | ||
}; |
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.
38fb560
to
bffa031
Compare
bffa031
to
9c5c982
Compare
(@conorsch OOO today, but gave the approval ✅ offline) |
Closes prax-wallet/prax#229
Closes #92
compressed.mov