Skip to content

fix: show pending spot trade#2091

Open
dwjanus wants to merge 1 commit intomainfrom
dwj/eng-1539-spot-show-pending
Open

fix: show pending spot trade#2091
dwjanus wants to merge 1 commit intomainfrom
dwj/eng-1539-spot-show-pending

Conversation

@dwjanus
Copy link
Contributor

@dwjanus dwjanus commented Mar 4, 2026

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 transitions
src/hooks/useSpotTransactionSubmit.ts — Accept payload as a mutation variable (not closure-captured) to avoid React-Query v5 re-render race condition
src/hooks/useSpotForm.tsx — Fire-and-forget submit: dispatch pending trade → kick off mutation → reset form immediately → update trade on resolve
src/pages/spot/SpotTradeForm.tsx — Remove isPending from UI disabled/loading states
src/hooks/useNotificationTypes.tsx — Handle pending state with loading spinner + infinite duration toast that updates on success/error

Issue

ENG-1539

Screenshots/Recordings

Screenshot 2026-03-04 at 3 07 12 PM Screenshot 2026-03-04 at 3 07 20 PM

@dwjanus dwjanus requested a review from a team as a code owner March 4, 2026 20:05
@linear
Copy link

linear bot commented Mar 4, 2026

@vercel
Copy link

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v4-staging Ready Ready Preview, Comment Mar 4, 2026 8:05pm
v4-testnet Ready Ready Preview, Comment Mar 4, 2026 8:05pm

Request Review

@dwjanus dwjanus changed the title show pending trade and success, keep form enabled fix: show pending spot trade Mar 4, 2026
Comment on lines +127 to +128
mutationPromise
.then((result) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you really like the base36 w/ slice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol no thats my bad i forgot we have the randomUUID from crypto library, ill replace this

Copy link
Collaborator

@jaredvu jaredvu Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants