MetaMask / metamask-mobile

Mobile web browser providing access to websites that use the Ethereum blockchain
https://metamask.io
Other
2.04k stars 1.06k forks source link

[Bug]: Unable to fetch swaps quotes when swapping ERC20 <> Native on current main branch #10037

Open cortisiko opened 2 weeks ago

cortisiko commented 2 weeks ago

Describe the bug

There is an issue on main (latest commit hash as of this ticket is: 451dc4d610a0db9ed0453b88e8537c586b993f14) where there is an error fetching swaps quotes "There ahas been an unexpected error, please request new quotes to get latest best rate. (error: swaps-allowance-error)"

I checked prod 7.24.2 and swaps is working as expected.

Expected behavior

Swapping between Native and ERC20 should work as expected

Screenshots/Recordings

https://github.com/MetaMask/metamask-mobile/assets/12821081/61829cda-f44c-4ac4-a922-b8421d080658

Steps to reproduce

Import a wallet with multiple tokens (feel free to use the orangefox.eth to reproduce) When on mainnet, attempt to swap USDT <> Native Notice you are prompted with an error on the quotes screen

Error messages or log output

No response

Version

main

Build type

Other (please specify exactly where you obtained this build in "Additional Context" section)

Device

Samsung S22

Operating system

Android

Additional context

This only happens on main. I noticed the only PR that was merged today that touched token allowances was https://github.com/MetaMask/metamask-mobile/pull/9794

Severity

No response

vinistevam commented 1 week ago

After some investigation with @tommasini, we reproduced the issue above on the commit (fix: @metamask/swaps-controller v6 -> v9). In fetchQuotes (SwapsController.js), allowance always returns null when calling getERC20Allowance which makes fall under the condition where it searches for the approvalNeeded but it's not present in quotesArrayending up throwing the error.

infiniteflower commented 6 days ago

I have a fix potentially