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(swap): Non ada pair selection #2728

Merged
merged 1 commit into from
Sep 27, 2023
Merged

fix(swap): Non ada pair selection #2728

merged 1 commit into from
Sep 27, 2023

Conversation

jorbuedo
Copy link
Contributor

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 or BuyAmountChanged, 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.

@jorbuedo jorbuedo added the fix label Sep 27, 2023
@jorbuedo jorbuedo self-assigned this Sep 27, 2023
@jorbuedo
Copy link
Contributor Author

@stackchain @SorinC6 Manged to test it and it seems to work. Except for pairs that don't return pools, then it can't select a new pool (because there's none) and reuses the previous one, since selectedPool can't be undefined. Honestly, should probably allow undefined for selectedPool. Will have to refactor quite a bit of places to account for it being undefined, but not sure what else to do if the selected pair doesn't have pools.

@stackchain
Copy link
Member

@stackchain @SorinC6 Manged to test it and it seems to work. Except for pairs that don't return pools, then it can't select a new pool (because there's none) and reuses the previous one, since selectedPool can't be undefined. Honestly, should probably allow undefined for selectedPool. Will have to refactor quite a bit of places to account for it being undefined, but not sure what else to do if the selected pair doesn't have pools.

Roger, A, B and P, otherwise 0.

@stackchain stackchain added this to the 5.0.0 milestone Sep 27, 2023
@stackchain stackchain merged commit 173493b into develop Sep 27, 2023
@stackchain stackchain deleted the fix-non-ada-pair branch February 6, 2024 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants