bancorprotocol / carbon-app

https://app.carbondefi.xyz
MIT License
26 stars 20 forks source link

[TRADE] Pressing 'Enter' on token select modal with invalid search triggers onTradePairSelect error #1355

Closed tiagofilipenunes closed 3 months ago

tiagofilipenunes commented 3 months ago

Issue detected on Sentry:

https://bprotocol-foundation.sentry.io/issues/4554127820/?project=4505074572197888&query=is%3Aunresolved+issue.category%3Aerror&referrer=issue-stream&sort=user&statsPeriod=30d&stream_index=5

TypeError 
onTradePairSelect(src/components/trade/useTradePairs)

Level: Error
Cannot read properties of undefined (reading 'baseToken')

This error comes from useModalTradeTokenList.tsx handleSelect which runs the onClick defined in useTradePairs and passed in ModalTradeTokenList via the data prop. Because there is no check that tradePair is valid, when pressing 'Enter' with an invalid search, there is an error.

Steps to reproduce:

  1. Go to trade page
  2. Open trade token selection modal
  3. Type a combination of keys that yields no result, e.g. '13143124132'
  4. Press 'Enter', see the error in the console

Expected

  1. Go to trade page
  2. Open trade token selection modal
  3. Type a combination of keys that yields no result, e.g. '13143124132'
  4. Press 'Enter', nothing happens, modal is not closed