From 57ba91592a3c327ba139c8cb08e491b9d0665965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Mon, 26 Apr 2021 14:47:56 -0400 Subject: [PATCH] only add custom tokens if not in mainnet (#2470) * checkchainid * tests --- app/components/Views/AddAsset/index.js | 28 +++++++++++++++------ app/components/Views/AddAsset/index.test.js | 21 ++++++++++++++-- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/components/Views/AddAsset/index.js b/app/components/Views/AddAsset/index.js index 62e03c44e88..2f9d425e8f1 100644 --- a/app/components/Views/AddAsset/index.js +++ b/app/components/Views/AddAsset/index.js @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import { SafeAreaView, StyleSheet } from 'react-native'; import { colors, fontStyles } from '../../../styles/common'; +import { connect } from 'react-redux'; import DefaultTabBar from 'react-native-scrollable-tab-view/DefaultTabBar'; import AddCustomToken from '../../UI/AddCustomToken'; import SearchTokenAutocomplete from '../../UI/SearchTokenAutocomplete'; @@ -9,6 +10,7 @@ import PropTypes from 'prop-types'; import { strings } from '../../../../locales/i18n'; import AddCustomCollectible from '../../UI/AddCustomCollectible'; import { getNetworkNavbarOptions } from '../../UI/Navbar'; +import { NetworksChainId } from '@metamask/controllers'; const styles = StyleSheet.create({ wrapper: { @@ -32,7 +34,7 @@ const styles = StyleSheet.create({ /** * PureComponent that provides ability to add assets. */ -export default class AddAsset extends PureComponent { +class AddAsset extends PureComponent { static navigationOptions = ({ navigation }) => getNetworkNavbarOptions('add_asset.title', true, navigation); state = { @@ -45,7 +47,11 @@ export default class AddAsset extends PureComponent { /** /* navigation object required to push new views */ - navigation: PropTypes.object + navigation: PropTypes.object, + /** + * Chain id + */ + chainId: PropTypes.string }; renderTabBar() { @@ -74,11 +80,13 @@ export default class AddAsset extends PureComponent { {assetType === 'token' ? ( - + {NetworksChainId.mainnet === this.props.chainId && ( + + )} ({ + chainId: state.engine.backgroundState.NetworkController.provider.chainId +}); + +export default connect(mapStateToProps)(AddAsset); diff --git a/app/components/Views/AddAsset/index.test.js b/app/components/Views/AddAsset/index.test.js index 310a5389180..a3e33019bdd 100644 --- a/app/components/Views/AddAsset/index.test.js +++ b/app/components/Views/AddAsset/index.test.js @@ -1,10 +1,27 @@ import React from 'react'; +import configureMockStore from 'redux-mock-store'; import { shallow } from 'enzyme'; import AddAsset from './'; +const mockStore = configureMockStore(); + describe('AddAsset', () => { it('should render correctly', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); + const initialState = { + engine: { + backgroundState: { + NetworkController: { + provider: { + chainId: '1' + } + } + } + } + }; + + const wrapper = shallow(, { + context: { store: mockStore(initialState) } + }); + expect(wrapper.dive()).toMatchSnapshot(); }); });