-
Notifications
You must be signed in to change notification settings - Fork 199
Description
Overview
Able to repro this one quite often locally, we should absolutely find the smoking gun
Gut feel is something is wrong state-wise, as clearing cache usually fixes this.
Claude spike below:
Able to repro this one quite often locally, we should absolutely find the smoking gun
Gut feel is something is wrong state-wise, as clearing cache usually fixes this.
Claude Spike
Error: Uncaught (in promise) Error: missing swapperName thrown at useTradeExecution.tsx:128
Root Cause: State desynchronization between activeQuoteMeta and tradeQuotes in Redux.
The Bug Flow
- User gets quote and selects it →
activeQuoteMetais set - Something triggers
clearTradeQuotesaction (possibly quote refresh, input change, or component re-mount) tradeQuotesare cleared BUTactiveQuoteMetais intentionally preserved (tradeQuoteSlice.ts:29)- User clicks "Sign and Broadcast"
selectActiveSwapperNameselector checks if quote exists:tradeQuotes[activeQuoteMeta.swapperName][activeQuoteMeta.identifier]- Quote doesn't exist (was cleared) → selector returns
undefined - Execution fails: "missing swapperName"
Key Code Locations
Where activeQuoteMeta is preserved:
src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts:25-31
clearTradeQuotes: create.reducer(state => ({
...initialState,
tradeExecution: state.tradeExecution,
activeQuoteMeta: state.activeQuoteMeta, // ← Preserved to handle "backing out from preview"
sortOption: state.sortOption,
}))Where swapperName check happens:
src/state/slices/tradeQuoteSlice/selectors.ts:214-227
selectActiveSwapperName: (activeQuoteMetaOrDefault, tradeQuotes) => {
if (activeQuoteMetaOrDefault === undefined) return
if (tradeQuotes[activeQuoteMetaOrDefault.swapperName]?.[activeQuoteMetaOrDefault.identifier]) {
return activeQuoteMetaOrDefault.swapperName
}
// Returns undefined if quote doesn't exist
}Investigation Needed
-
When does
clearTradeQuotesget called?- During quote refresh?
- When user changes input amounts?
- On component re-mount?
- Add logging to track all
clearTradeQuotesdispatches
-
Is preserving
activeQuoteMetastill necessary?- Comment mentions "backing out from preview"
- Test: preview → back → preview navigation
- Does it actually need the preserved quote, or can it re-select?
-
Race condition timing:
- Is there a timing window between selecting quote and executing?
- Could quote refresh happen while user is on confirm screen?
Potential Fixes
Option A: Stop preserving activeQuoteMeta (simplest)
- Remove
activeQuoteMeta: state.activeQuoteMetafrom clearTradeQuotes reducer - Risk: May break navigation UX (quotes need re-selection when backing out)
Option B: Conditional preservation
- Add parameter to clearTradeQuotes to control when to preserve
- Only preserve when needed for navigation
- Clear when quote refresh happens
Option C: Validate quote exists before execution
- In execution hook, check if quote still exists in tradeQuotes
- If not, re-fetch or show error to user
- More defensive but doesn't fix root cause
Recommended Approach
Investigate Option A first:
- Remove activeQuoteMeta preservation
- Test swap execution (should fix the error)
- Test navigation flow (preview → back → preview)
- If navigation breaks, implement Option B
References and additional details
N/A
Acceptance Criteria
- That sneaky error is gone
Need By Date
No response
Screenshots/Mockups
No response
Estimated effort
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status