Skip to content

Commit

Permalink
fix(cico): fix crash on bottom sheet when token list is empty (valora…
Browse files Browse the repository at this point in the history
…-inc#5390)

### Description

Crashes when token list is empty, which attempts to render a 0 outside
of a `<Text>` component

### Test plan

Unit tests, manually by emptying token list

### Related issues

N/A

### Backwards compatibility

Yes

### Network scalability

N/A
  • Loading branch information
satish-ravi authored and shottah committed May 15, 2024
1 parent 843a8b7 commit e161031
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/fiatExchanges/FiatExchangeCurrencyBottomSheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,20 @@ describe(FiatExchangeCurrencyBottomSheet, () => {
expect(getAllByTestId('TokenBalanceItem')[3]).toHaveTextContent('CELO')
expect(getAllByTestId('TokenBalanceItem')[4]).toHaveTextContent('ETH')
})
it('renders correctly if token list is empty', () => {
const { queryByTestId, getByTestId } = render(
<Provider store={createMockStore({ tokens: { tokenBalances: {} } })}>
<MockedNavigator
component={FiatExchangeCurrencyBottomSheet}
params={{
flow: FiatExchangeFlow.CashIn,
}}
/>
</Provider>
)
expect(queryByTestId('TokenBalanceItem')).toBeFalsy()
// asserts whether tokenList.length (0) isn't rendered, which causes a
// crash in the app
expect(getByTestId('FiatExchangeCurrencyBottomSheet')).not.toHaveTextContent('0')
})
})
2 changes: 1 addition & 1 deletion src/fiatExchanges/FiatExchangeCurrencyBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function FiatExchangeCurrencyBottomSheet({ route }: Props) {
>
{/* padding undefined to prevent android ripple bug */}
<Text style={styles.selectDigitalCurrency}>{t('sendEnterAmountScreen.selectToken')}</Text>
{tokenList.length &&
{!!tokenList.length &&
tokenList.map((tokenInfo) => {
return (
<React.Fragment key={`token-${tokenInfo.tokenId}`}>
Expand Down

0 comments on commit e161031

Please sign in to comment.