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

feat: display a warning if the output amount changes on the confirm swap page #943

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

Ikari-Shinji-re
Copy link
Member

@Ikari-Shinji-re Ikari-Shinji-re commented Nov 12, 2024

Summary

If the user proceeds to the confirm swap page and the output amount differs from the previous quote response, or if the output amount changes when the quote refreshes on the confirm swap page and these changes meet certain criteria, we should display an appropriate warning to prevent potential loss for the user:

usdInput >= 1000 and percentageChange >= 1
usdInput >= 500 and percentageChange >= 2

In this pull request, I also removed some unused code that was previously needed for route update situations. Additionally, I worked on refactoring and cleaning up how we retrieve the USD value of the source or destination token.

How did you test this change?

To test these changes, it’s best to manipulate the quote response in the confirm swap flow, as the real scenario may not occur frequently.

Make this changes to generateQuoteWarnings function :

export function generateQuoteWarnings(params: {
  previousQuote?: SelectedQuote;
  currentQuote: SelectedQuote;
  findToken: FindToken;
  userSlippage: number;
}): QuoteWarning | null {
  const { previousQuote, findToken, userSlippage } = params;
  const currentQuote: SelectedQuote = {
    ...params.currentQuote,
    outputAmount: String(0.97 * parseFloat(previousQuote?.outputAmount ?? '0')),
  };
  ///////
  //////
 }

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Implemented a user interface (UI) change, referencing our Figma design to ensure pixel-perfect precision.

widget/embedded/src/store/quote.ts Outdated Show resolved Hide resolved
widget/embedded/src/utils/quote.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@mikasackermn mikasackermn left a comment

Choose a reason for hiding this comment

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

LGTM

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