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

fix(prepare-transactions): add throwOnSpendTokenAmountExceedsBalance option #4442

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

jeanregisser
Copy link
Member

Description

I realized a bit too late that the changes in #4432 broke the swap flow where we want to prepare transactions when the spend amount is greater than the balance.
This is because we want users to be able to try any amount to see the quote (and associated fee).

Test plan

  • Updated tests

Related issues

  • N/A

Backwards compatibility

Yes

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Merging #4442 (b2f2471) into main (b31dfd0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4442   +/-   ##
=======================================
  Coverage   85.08%   85.08%           
=======================================
  Files         711      711           
  Lines       26386    26389    +3     
  Branches     3574     3577    +3     
=======================================
+ Hits        22450    22453    +3     
  Misses       3873     3873           
  Partials       63       63           
Files Coverage Δ
src/swap/useSwapQuote.ts 92.40% <ø> (ø)
src/viem/prepareTransactions.ts 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b31dfd0...b2f2471. Read the comment docs.

Copy link
Contributor

@cajubelt cajubelt left a comment

Choose a reason for hiding this comment

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

to avoid the code smell of a boolean parameter, another way of doing this would be to throw a specific error type and swallow that error type in useSwapQuote

@jeanregisser
Copy link
Member Author

to avoid the code smell of a boolean parameter, another way of doing this would be to throw a specific error type and swallow that error type in useSwapQuote

Yes, here at least I could go with a named option, not the worst, though in general yes I agree we should avoid them.
I thought about exposing another function like prepareTransactionsWithoutCheckingSpendBalance or something. But preferred the option for now. Can revisit later of course.

@jeanregisser jeanregisser enabled auto-merge (squash) November 7, 2023 17:21
@jeanregisser jeanregisser merged commit 41eae07 into main Nov 7, 2023
15 checks passed
@jeanregisser jeanregisser deleted the jeanregisser/fix-error-swap-higher-balance branch November 7, 2023 18:40
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