Skip to content

Commit

Permalink
only add custom tokens if not in mainnet (#2470)
Browse files Browse the repository at this point in the history
* checkchainid

* tests
  • Loading branch information
estebanmino authored Apr 26, 2021
1 parent b4c82e6 commit 57ba915
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
28 changes: 21 additions & 7 deletions app/components/Views/AddAsset/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand All @@ -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 = {
Expand All @@ -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() {
Expand Down Expand Up @@ -74,11 +80,13 @@ export default class AddAsset extends PureComponent {
<SafeAreaView style={styles.wrapper} testID={`add-${assetType}-screen`}>
{assetType === 'token' ? (
<ScrollableTabView renderTabBar={this.renderTabBar}>
<SearchTokenAutocomplete
navigation={navigation}
tabLabel={strings('add_asset.search_token')}
testID={'tab-search-token'}
/>
{NetworksChainId.mainnet === this.props.chainId && (
<SearchTokenAutocomplete
navigation={navigation}
tabLabel={strings('add_asset.search_token')}
testID={'tab-search-token'}
/>
)}
<AddCustomToken
navigation={navigation}
tabLabel={strings('add_asset.custom_token')}
Expand All @@ -96,3 +104,9 @@ export default class AddAsset extends PureComponent {
);
};
}

const mapStateToProps = state => ({
chainId: state.engine.backgroundState.NetworkController.provider.chainId
});

export default connect(mapStateToProps)(AddAsset);
21 changes: 19 additions & 2 deletions app/components/Views/AddAsset/index.test.js
Original file line number Diff line number Diff line change
@@ -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(<AddAsset navigation={{ state: { params: { assetType: 'token' } } }} />);
expect(wrapper).toMatchSnapshot();
const initialState = {
engine: {
backgroundState: {
NetworkController: {
provider: {
chainId: '1'
}
}
}
}
};

const wrapper = shallow(<AddAsset navigation={{ state: { params: { assetType: 'token' } } }} />, {
context: { store: mockStore(initialState) }
});
expect(wrapper.dive()).toMatchSnapshot();
});
});

0 comments on commit 57ba915

Please sign in to comment.