Skip to content
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

enhance swap quote functionality with error handling and auto refresh #3803

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Ernesto-tha-great
Copy link

@Ernesto-tha-great Ernesto-tha-great commented Mar 13, 2025

  • Debounce time for updating the swap quote was reduced from 500ms to 300ms.
  • Added an error field in the QuoteUpdate type to store error messages.
  • Introduced a retry system to handle network failures and transient errors.
  • Ensures the user always sees the latest price without manually refreshing.
  • Improved readability and maintainability by restructuring the fetchQuote logic

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

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

Left some notes! Thanks for contributing these changes!

@Ernesto-tha-great
Copy link
Author

@Shadowfiend @hyphenized

I have taken the feedback into account and refactored the PR. Does this look better?

@Shadowfiend
Copy link
Contributor

The updated PR still does auto-refreshes but they're also being done on the frontend side, am I reading this right? Probably should stick to one or the other.

AJTECH0001 added a commit to AJTECH0001/extension that referenced this pull request Mar 23, 2025
Per Shadowfiend's PR tahowallet#3803 feedback, removed duplicate 10s useInterval (Swap.tsx) and 30s useEffect (useSwapQuote) to rely on backend fetchSwapPrice updates. Dropped unused amountInputHasFocus, fixed TS/ESLint errors (TS6133, TS1005, etc.), and kept PR tahowallet#3803 enhancements (300ms debounce, retries). Tested locally; assumes backend auto-refresh.
@Ernesto-tha-great
Copy link
Author

@Shadowfiend

Please take a look once more. I have removed the refresh on the FE

@Shadowfiend
Copy link
Contributor

You may have had a rebase issue here—the history is looking gnarly. Maybe see if you can check out latest main and then cherry pick c6aa8be and 203f85c and force push over the current branch.

@@ -466,12 +416,9 @@ export default function Swap(): ReactElement {
priceImpact={quote?.priceDetails?.priceImpact}
isPriceDetailsLoading={isLoadingPriceDetails}
showPriceDetails
// FIXME: Merge master asset list with account balances.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this no longer relevant?

Copy link
Author

Choose a reason for hiding this comment

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

yes. its been fixed

@@ -357,8 +313,6 @@ export default function Swap(): ReactElement {
sellAsset,
buyAsset,
gasPrice:
// Let's use the gas price from 0x API for Optimism
// to avoid problems with gas price on Optimism Bedrock.
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels relevant still.

Copy link
Author

Choose a reason for hiding this comment

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

ill add it back in.

@Ernesto-tha-great
Copy link
Author

@Shadowfiend

All done now.

Copy link
Collaborator

@hyphenized hyphenized left a comment

Choose a reason for hiding this comment

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

This doesn't seem to be auto refreshing quotes anymore?

@Ernesto-tha-great
Copy link
Author

This doesn't seem to be auto refreshing quotes anymore?

yes. we removed the auto refresh from the frontend so its being handled on the backend.

@hyphenized
Copy link
Collaborator

This doesn't seem to be auto refreshing quotes anymore?

yes. we removed the auto refresh from the frontend so its being handled on the backend.

Okay I see that the front end code for auto refresh was removed but I don't see anything in the backend handling that?

@Ernesto-tha-great
Copy link
Author

This doesn't seem to be auto refreshing quotes anymore?

yes. we removed the auto refresh from the frontend so its being handled on the backend.

Okay I see that the front end code for auto refresh was removed but I don't see anything in the backend handling that?

@hyphenized @Shadowfiend
Take a look now if this is better. I have resolved the auto refresh to be handled in the hook (swap.ts) every 10 sec.

@Ernesto-tha-great
Copy link
Author

@hyphenized @Shadowfiend bumping this up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants