fix: manual receive address empty confirm step #5947
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes the manual receive address screen being borked currently.
tl;dr of why that is:
<ManualAddressEntry />
validation method initially resets the manual receive address before parsing, validating, and setting it againweb/src/components/MultiHopTrade/components/TradeInput/components/ManualAddressEntry.tsx
Line 75 in 7f12fa4
useGetTradeQuotes
reacts to this and this condition failsweb/src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx
Line 204 in 7f12fa4
we then end up in the following block, where we reset the active quote index:
web/src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx
Lines 264 to 267 in 7f12fa4
selectActiveSwapperName
returns undefined<TradeInput />
anymore after clicking the preview button, we never set the active quote index againThe core issue of this is validation being re-ran while
<ManualAddressEntry />
despite the input not changing, instead of it immediately unmounting (which it does only a few render cycles later, after re-validation occurred), and is most likely a combination of react-hook-form v7 not automagically unregistering inputs after unmount (see https://github.com/orgs/react-hook-form/discussions/3714), however, none of manualunregister()
calls,shouldUnregister
, nor using ashow
state variable that's set withReactDOM.flushSync()
to avoid batching helped here.if you ever run into a similar validation running right before unmount kind of bug, the above could be explored.
While this doesn't fix the core issue of why the validation gets re-ran after clicking the confirm button, this fixes the current issue at hand, and this bug is very much isolated to our
useGetTradeQuotes
hook reactivity, so this is unlikely to produce other bugs in the future.Pull Request Type
Issue (if applicable)
closes #5945
Risk
Low, see testing steps. Theoretically, not resetting the manual receive address in store beforehand could bring bugs, however, we do gracefully handle it already, and a catch block has been added for extra safety.
Testing
Engineering
Operations
Screenshots (if applicable)
Invalid manual receive address
Valid receive address