fix(swap): Non ada pair selection #2728
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.
related: https://emurgo.atlassian.net/browse/YOMO-815
When the selection screen wants to select a new token, the only action it can perform is
SellAmountChanged
orBuyAmountChanged
, which not only serve to modify the quantity, but the tokenId as well.The reducer for those actions takes care of updating the amounts, but expects the selectedPool to be correct.
When selecting new tokens, the pool is still the old one, so the getBuyAmount/getSellAmount set the other amount to the other amount in the pool, which was always ada because we started with it in the pair.
This fix prevents calling getBuyAmount/getSellAmount if we are setting a quantity = 0, since the other one will be 0 as well. After that, the pair has changed, and the app in createOrder will pick up the change, request new pools, and update the selectedPool. Or that's the idea, I only have ada on my prod wallet. And the testnet wallet has a mocked pool list with only ada pairs, so I can't verify it works.