Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions app/components/AddAsset/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`AddAsset should render correctly 1`] = `
"flex": 1,
}
}
testID="add-asset-screen"
testID="add-token-screen"
>
<ScrollableTabView
contentProps={Object {}}
Expand All @@ -22,11 +22,29 @@ exports[`AddAsset should render correctly 1`] = `
scrollWithoutAnimation={false}
tabBarPosition="top"
>
<SearchAssetAutocomplete
<SearchTokenAutocomplete
navigation={
Object {
"state": Object {
"params": Object {
"assetType": "token",
},
},
}
}
tabLabel="SEARCH"
testID="tab-search-token"
/>
<AddCustomAsset
<AddCustomToken
navigation={
Object {
"state": Object {
"params": Object {
"assetType": "token",
},
},
}
}
tabLabel="CUSTOM TOKEN"
testID="tab-add-custom-token"
/>
Expand Down
44 changes: 28 additions & 16 deletions app/components/AddAsset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React, { Component } from 'react';
import { View, StyleSheet } from 'react-native';
import { colors, fontStyles } from '../../styles/common';
import DefaultTabBar from 'react-native-scrollable-tab-view/DefaultTabBar';
import AddCustomAsset from '../AddCustomAsset';
import SearchAssetAutocomplete from '../SearchAssetAutocomplete';
import AddCustomToken from '../AddCustomToken';
import SearchTokenAutocomplete from '../SearchTokenAutocomplete';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import PropTypes from 'prop-types';
import { strings } from '../../../locales/i18n';
import AddCustomCollectible from '../AddCustomCollectible';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -66,21 +67,32 @@ export default class AddAsset extends Component {
}

render() {
const { navigation } = this.props;
const {
navigation: {
state: {
params: { assetType }
}
},
navigation
} = this.props;
return (
<View style={styles.wrapper} testID={'add-asset-screen'}>
<ScrollableTabView renderTabBar={this.renderTabBar}>
<SearchAssetAutocomplete
navigation={navigation}
tabLabel={strings('addAsset.search_token')}
testID={'tab-search-token'}
/>
<AddCustomAsset
navigation={navigation}
tabLabel={strings('addAsset.custom_token')}
testID={'tab-add-custom-token'}
/>
</ScrollableTabView>
<View style={styles.wrapper} testID={`add-${assetType}-screen`}>
{assetType === 'token' ? (
<ScrollableTabView renderTabBar={this.renderTabBar}>
<SearchTokenAutocomplete
navigation={navigation}
tabLabel={strings('addAsset.search_token')}
testID={'tab-search-token'}
/>
<AddCustomToken
navigation={navigation}
tabLabel={strings('addAsset.custom_token')}
testID={'tab-add-custom-token'}
/>
</ScrollableTabView>
) : (
<AddCustomCollectible navigation={navigation} testID={'add-custom-collectible'} />
)}
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/AddAsset/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AddAsset from './';

describe('AddAsset', () => {
it('should render correctly', () => {
const wrapper = shallow(<AddAsset />);
const wrapper = shallow(<AddAsset navigation={{ state: { params: { assetType: 'token' } } }} />);
expect(wrapper).toMatchSnapshot();
});
});
120 changes: 120 additions & 0 deletions app/components/AddCustomCollectible/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AddCustomCollectible should render correctly 1`] = `
<Component
style={
Object {
"backgroundColor": "#FFFFFF",
"flex": 1,
}
}
testID="add-custom-token-screen"
>
<ActionView
cancelTestID="add-custom-asset-cancel-button"
cancelText="CANCEL"
confirmButtonMode="normal"
confirmTestID="add-custom-asset-confirm-button"
confirmText="ADD COLLECTIBLE"
onCancelPress={[Function]}
onConfirmPress={[Function]}
>
<Component
style={
Object {
"padding": 20,
}
}
>
<Component
style={
Object {
"fontFamily": "Roboto",
"fontWeight": "400",
}
}
>
Collectible Address
</Component>
<TextInput
allowFontScaling={true}
onBlur={[Function]}
onChangeText={[Function]}
onSubmitEditing={[Function]}
placeholder="0x..."
style={
Object {
"borderColor": "#CCCCCC",
"borderRadius": 4,
"borderWidth": 1,
"fontFamily": "Roboto",
"fontWeight": "400",
"padding": 16,
}
}
testID="input-collectible-address"
underlineColorAndroid="transparent"
value=""
/>
<Component
style={
Object {
"color": "#FF0000",
"fontFamily": "Roboto",
"fontWeight": "400",
}
}
/>
</Component>
<Component
style={
Object {
"padding": 20,
}
}
>
<Component
style={
Object {
"fontFamily": "Roboto",
"fontWeight": "400",
}
}
>
Collectible Identifier
</Component>
<TextInput
allowFontScaling={true}
keyboardType="numeric"
onBlur={[Function]}
onChangeText={[Function]}
onSubmitEditing={[Function]}
placeholder=""
returnKeyType="done"
style={
Object {
"borderColor": "#CCCCCC",
"borderRadius": 4,
"borderWidth": 1,
"fontFamily": "Roboto",
"fontWeight": "400",
"padding": 16,
}
}
testID="input-token-decimals"
underlineColorAndroid="transparent"
value=""
/>
<Component
style={
Object {
"color": "#FF0000",
"fontFamily": "Roboto",
"fontWeight": "400",
}
}
/>
</Component>
</ActionView>
</Component>
`;
151 changes: 151 additions & 0 deletions app/components/AddCustomCollectible/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import React, { Component } from 'react';
import { Text, TextInput, View, StyleSheet } from 'react-native';
import { colors, fontStyles } from '../../styles/common';
import Engine from '../../core/Engine';
import PropTypes from 'prop-types';
import { strings } from '../../../locales/i18n';
import { isValidAddress } from 'ethereumjs-util';
import ActionView from '../ActionView';

const styles = StyleSheet.create({
wrapper: {
backgroundColor: colors.white,
flex: 1
},
rowWrapper: {
padding: 20
},
textInput: {
borderWidth: 1,
borderRadius: 4,
borderColor: colors.borderColor,
padding: 16,
...fontStyles.normal
},
warningText: {
color: colors.error,
...fontStyles.normal
}
});

/**
* Copmonent that provides ability to add custom collectibles.
*/
export default class AddCustomCollectible extends Component {
state = {
address: '',
tokenId: ''
};

static propTypes = {
/**
/* navigation object required to push new views
*/
navigation: PropTypes.object
};

addCollectible = () => {
if (!this.validateCustomCollectible()) return;
const { AssetsController } = Engine.context;
const { address, tokenId } = this.state;
AssetsController.addCollectible(address, tokenId);
this.props.navigation.goBack();
};

cancelAddCollectible = () => {
this.props.navigation.goBack();
};

onAddressChange = address => {
this.setState({ address });
};

onTokenIdChange = tokenId => {
this.setState({ tokenId });
};

validateCustomCollectibleAddress = () => {
let validated = true;
const address = this.state.address;
if (address.length === 0) {
this.setState({ warningAddress: strings('collectible.address_cant_be_empty') });
validated = false;
} else if (!isValidAddress(address)) {
this.setState({ warningAddress: strings('collectible.address_must_be_valid') });
validated = false;
} else {
this.setState({ warningAddress: `` });
}
return validated;
};

validateCustomCollectibleTokenId = () => {
let validated = true;
const tokenId = this.state.tokenId;
if (tokenId.length === 0) {
this.setState({ warningTokenId: strings('collectible.token_id_cant_be_empty') });
validated = false;
} else {
this.setState({ warningTokenId: `` });
}
return validated;
};

validateCustomCollectible = () => {
const validatedAddress = this.validateCustomCollectibleAddress();
const validatedTokenId = this.validateCustomCollectibleTokenId();
return validatedAddress && validatedTokenId;
};

assetTokenIdInput = React.createRef();

jumpToAssetTokenId = () => {
const { current } = this.assetTokenIdInput;
current && current.focus();
};

render() {
return (
<View style={styles.wrapper} testID={'add-custom-token-screen'}>
<ActionView
cancelTestID={'add-custom-asset-cancel-button'}
confirmTestID={'add-custom-asset-confirm-button'}
cancelText={strings('addAsset.collectibles.cancel_add_collectible')}
confirmText={strings('addAsset.collectibles.add_collectible')}
onCancelPress={this.cancelAddCollectible}
onConfirmPress={this.addCollectible}
>
<View style={styles.rowWrapper}>
<Text style={fontStyles.normal}>{strings('collectible.collectible_address')}</Text>
<TextInput
style={styles.textInput}
placeholder={'0x...'}
value={this.state.address}
onChangeText={this.onAddressChange}
onBlur={this.validateCustomCollectibleAddress}
testID={'input-collectible-address'}
onSubmitEditing={this.jumpToAssetTokenId}
/>
<Text style={styles.warningText}>{this.state.warningAddress}</Text>
</View>
<View style={styles.rowWrapper}>
<Text style={fontStyles.normal}>{strings('collectible.collectible_token_id')}</Text>
<TextInput
style={styles.textInput}
value={this.state.tokenId}
keyboardType="numeric"
placeholder={''}
onChangeText={this.onTokenIdChange}
onBlur={this.validateCustomCollectibleTokenId}
testID={'input-token-decimals'}
ref={this.assetTokenIdInput}
onSubmitEditing={this.addCollectible}
returnKeyType={'done'}
/>
<Text style={styles.warningText}>{this.state.warningTokenId}</Text>
</View>
</ActionView>
</View>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { shallow } from 'enzyme';
import SearchAssetAutocomplete from './';
import AddCustomCollectible from './';

describe('SearchAssetAutocomplete', () => {
describe('AddCustomCollectible', () => {
it('should render correctly', () => {
const wrapper = shallow(<SearchAssetAutocomplete />);
const wrapper = shallow(<AddCustomCollectible />);
expect(wrapper).toMatchSnapshot();
});
});
Loading