Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| mutationPromise | ||
| .then((result) => { |
There was a problem hiding this comment.
nit: use a try/catch instead of .then/.catch
| groupSeparator, | ||
| selectedLocale, | ||
| const submitTransaction = useCallback(() => { | ||
| const tradeId = `spot-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`; |
There was a problem hiding this comment.
this is a pretty weird way to generate a random number? why the arbitrary slice.
you can use a variety of functions here like
import { randomInt, randomUUID } from 'crypto'
or you can use the summary.payload
spot-${Date.now()}-${side}-${tokenSymbol}-${payload.pool}
There was a problem hiding this comment.
unless you really like the base36 w/ slice
There was a problem hiding this comment.
lol no thats my bad i forgot we have the randomUUID from crypto library, ill replace this
There was a problem hiding this comment.
did we remove disabled and loading states for faster sequential submission?
I think this is generally a good idea.
We should allow the backend to validate and give the user the ability to execute as many trades in succession as they want here.
There was a problem hiding this comment.
yee, exactly- after some testing it appeared they were largely unnecessary since the backend validates the submission and we want the frontend to be more optimistic here
Changes
Make spot trade submissions optimistic — show a pending toast immediately on submit, clear the form, and update the toast when the transaction resolves.
src/state/spotTrades.ts— Added 'pending' status and updateSpotTrade reducer for optimistic state transitionssrc/hooks/useSpotTransactionSubmit.ts— Accept payload as a mutation variable (not closure-captured) to avoid React-Query v5 re-render race conditionsrc/hooks/useSpotForm.tsx— Fire-and-forget submit: dispatch pending trade → kick off mutation → reset form immediately → update trade on resolvesrc/pages/spot/SpotTradeForm.tsx— Remove isPending from UI disabled/loading statessrc/hooks/useNotificationTypes.tsx— Handle pending state with loading spinner + infinite duration toast that updates on success/errorIssue
ENG-1539
Screenshots/Recordings