From cb261b03c62ca3db27726b910a449c3acada3347 Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Tue, 11 Sep 2018 19:15:16 -0300 Subject: [PATCH 1/7] Wallet tokens from AssetsController --- app/components/AddCustomAsset/index.js | 4 ++-- app/components/SearchAssetAutocomplete/index.js | 4 ++-- app/components/Wallet/index.js | 2 +- app/core/Engine.js | 4 ++++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/components/AddCustomAsset/index.js b/app/components/AddCustomAsset/index.js index 808a016e71d8..7d5155c227da 100644 --- a/app/components/AddCustomAsset/index.js +++ b/app/components/AddCustomAsset/index.js @@ -50,9 +50,9 @@ export default class AddCustomAsset extends Component { addToken = () => { if (!this.validateCustomToken()) return; - const { PreferencesController } = Engine.context; + const { AssetsController } = Engine.context; const { address, symbol, decimals } = this.state; - PreferencesController.addToken(address, symbol, decimals); + AssetsController.addToken(address, symbol, decimals); this.props.navigation.goBack(); }; diff --git a/app/components/SearchAssetAutocomplete/index.js b/app/components/SearchAssetAutocomplete/index.js index 0d66c9570f1d..aab9851e4195 100644 --- a/app/components/SearchAssetAutocomplete/index.js +++ b/app/components/SearchAssetAutocomplete/index.js @@ -44,9 +44,9 @@ export default class SearchAssetAutocomplete extends Component { }; addToken = () => { - const { PreferencesController } = Engine.context; + const { AssetsController } = Engine.context; const { address, symbol, decimals } = this.state.selectedAsset; - PreferencesController.addToken(address, symbol, decimals); + AssetsController.addToken(address, symbol, decimals); this.props.navigation.goBack(); }; diff --git a/app/components/Wallet/index.js b/app/components/Wallet/index.js index 6391bf4a5754..fd12e44b7f0b 100644 --- a/app/components/Wallet/index.js +++ b/app/components/Wallet/index.js @@ -110,7 +110,7 @@ const mapStateToProps = state => ({ currentCurrency: state.backgroundState.CurrencyRateController.currentCurrency, identities: state.backgroundState.PreferencesController.identities, selectedAddress: state.backgroundState.PreferencesController.selectedAddress, - tokens: state.backgroundState.PreferencesController.tokens + tokens: state.backgroundState.AssetsController.tokens }); export default connect(mapStateToProps)(Wallet); diff --git a/app/core/Engine.js b/app/core/Engine.js index 31aa2ba49d98..6163f1c200a8 100644 --- a/app/core/Engine.js +++ b/app/core/Engine.js @@ -1,6 +1,7 @@ import { AccountTrackerController, AddressBookController, + AssetsController, BlockHistoryController, ComposableController, CurrencyRateController, @@ -39,6 +40,7 @@ class Engine { new KeyringController({ encryptor }, initialState.KeyringController), new AccountTrackerController(), new AddressBookController(), + new AssetsController(), new BlockHistoryController(), new CurrencyRateController(), new NetworkController( @@ -122,6 +124,7 @@ export default { get state() { const { AccountTrackerController, + AssetsController, CurrencyRateController, KeyringController, NetworkController, @@ -133,6 +136,7 @@ export default { return { AccountTrackerController, + AssetsController, CurrencyRateController, KeyringController, NetworkController, From 76e559d40b4c6d427dcba546307b97f692a2d982 Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Tue, 11 Sep 2018 19:16:59 -0300 Subject: [PATCH 2/7] Update some snapshots failing --- .../AssetOverview/__snapshots__/index.test.js.snap | 12 ++++++++++++ .../SendScreen/__snapshots__/index.test.js.snap | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/components/AssetOverview/__snapshots__/index.test.js.snap b/app/components/AssetOverview/__snapshots__/index.test.js.snap index 2e15fdc6e3bd..3f9fa9195ba7 100644 --- a/app/components/AssetOverview/__snapshots__/index.test.js.snap +++ b/app/components/AssetOverview/__snapshots__/index.test.js.snap @@ -8,6 +8,18 @@ exports[`AssetOverview should render correctly 1`] = ` "#FFFFFF", ] } + end={ + Object { + "x": 0.5, + "y": 1, + } + } + start={ + Object { + "x": 0.5, + "y": 0, + } + } style={ Object { "borderBottomColor": "#CCCCCC", diff --git a/app/components/SendScreen/__snapshots__/index.test.js.snap b/app/components/SendScreen/__snapshots__/index.test.js.snap index 0e1432a7c49a..e7d05bb2ea84 100644 --- a/app/components/SendScreen/__snapshots__/index.test.js.snap +++ b/app/components/SendScreen/__snapshots__/index.test.js.snap @@ -1,3 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SendScreen should render correctly 1`] = `<[object Object] />`; \ No newline at end of file +exports[`SendScreen should render correctly 1`] = ` + + + +`; From 020b9a62d2eaf614cabb789bd8d29e7c362c06d8 Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Tue, 11 Sep 2018 21:43:03 -0300 Subject: [PATCH 3/7] wallet collectibles support --- .../AddAsset/__snapshots__/index.test.js.snap | 31 ++-- app/components/AddAsset/index.js | 41 +++-- app/components/AddAsset/index.test.js | 2 +- .../__snapshots__/index.test.js.snap | 120 ++++++++++++++ app/components/AddCustomCollectible/index.js | 151 ++++++++++++++++++ .../index.test.js | 6 +- .../__snapshots__/index.test.js.snap | 2 +- .../index.js | 4 +- .../index.test.js | 6 +- .../__snapshots__/index.test.js.snap | 2 + app/components/Collectibles/index.js | 63 ++++---- .../__snapshots__/index.test.js.snap | 2 +- .../index.js | 2 +- .../SearchTokenAutocomplete/index.test.js | 10 ++ app/components/Tokens/index.js | 2 +- app/components/Wallet/index.js | 21 ++- locales/en.json | 11 ++ locales/es.json | 15 +- package.json | 2 +- 19 files changed, 401 insertions(+), 92 deletions(-) create mode 100644 app/components/AddCustomCollectible/__snapshots__/index.test.js.snap create mode 100644 app/components/AddCustomCollectible/index.js rename app/components/{SearchAssetAutocomplete => AddCustomCollectible}/index.test.js (50%) rename app/components/{AddCustomAsset => AddCustomToken}/__snapshots__/index.test.js.snap (98%) rename app/components/{AddCustomAsset => AddCustomToken}/index.js (97%) rename app/components/{AddCustomAsset => AddCustomToken}/index.test.js (56%) rename app/components/{SearchAssetAutocomplete => SearchTokenAutocomplete}/__snapshots__/index.test.js.snap (90%) rename app/components/{SearchAssetAutocomplete => SearchTokenAutocomplete}/index.js (96%) create mode 100644 app/components/SearchTokenAutocomplete/index.test.js diff --git a/app/components/AddAsset/__snapshots__/index.test.js.snap b/app/components/AddAsset/__snapshots__/index.test.js.snap index 7b73091946a5..8297a3948309 100644 --- a/app/components/AddAsset/__snapshots__/index.test.js.snap +++ b/app/components/AddAsset/__snapshots__/index.test.js.snap @@ -10,26 +10,15 @@ exports[`AddAsset should render correctly 1`] = ` } testID="add-asset-screen" > - - - - + `; diff --git a/app/components/AddAsset/index.js b/app/components/AddAsset/index.js index 2d633ec88844..8026327a5bff 100644 --- a/app/components/AddAsset/index.js +++ b/app/components/AddAsset/index.js @@ -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: { @@ -66,21 +67,31 @@ export default class AddAsset extends Component { } render() { - const { navigation } = this.props; + const { + navigation: { + state: { params } + }, + navigation + } = this.props; + return ( - - - - + {params === 'tokens' ? ( + + + + + ) : ( + + )} ); } diff --git a/app/components/AddAsset/index.test.js b/app/components/AddAsset/index.test.js index 752d634d9e29..7a41c88ae412 100644 --- a/app/components/AddAsset/index.test.js +++ b/app/components/AddAsset/index.test.js @@ -4,7 +4,7 @@ import AddAsset from './'; describe('AddAsset', () => { it('should render correctly', () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/app/components/AddCustomCollectible/__snapshots__/index.test.js.snap b/app/components/AddCustomCollectible/__snapshots__/index.test.js.snap new file mode 100644 index 000000000000..c13c5293a0a2 --- /dev/null +++ b/app/components/AddCustomCollectible/__snapshots__/index.test.js.snap @@ -0,0 +1,120 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AddCustomCollectible should render correctly 1`] = ` + + + + + Collectible Address + + + + + + + Collectible Identifier + + + + + + +`; diff --git a/app/components/AddCustomCollectible/index.js b/app/components/AddCustomCollectible/index.js new file mode 100644 index 000000000000..6f9c4839c28a --- /dev/null +++ b/app/components/AddCustomCollectible/index.js @@ -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 ( + + + + {strings('collectible.collectible_address')} + + {this.state.warningAddress} + + + {strings('collectible.collectible_token_id')} + + {this.state.warningTokenId} + + + + ); + } +} diff --git a/app/components/SearchAssetAutocomplete/index.test.js b/app/components/AddCustomCollectible/index.test.js similarity index 50% rename from app/components/SearchAssetAutocomplete/index.test.js rename to app/components/AddCustomCollectible/index.test.js index 042153e9676d..a9cca6c7dfb2 100644 --- a/app/components/SearchAssetAutocomplete/index.test.js +++ b/app/components/AddCustomCollectible/index.test.js @@ -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(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/app/components/AddCustomAsset/__snapshots__/index.test.js.snap b/app/components/AddCustomToken/__snapshots__/index.test.js.snap similarity index 98% rename from app/components/AddCustomAsset/__snapshots__/index.test.js.snap rename to app/components/AddCustomToken/__snapshots__/index.test.js.snap index be13ccd57275..03cc411b4e18 100644 --- a/app/components/AddCustomAsset/__snapshots__/index.test.js.snap +++ b/app/components/AddCustomToken/__snapshots__/index.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AddCustomAsset should render correctly 1`] = ` +exports[`AddCustomToken should render correctly 1`] = ` { +describe('AddCustomToken', () => { it('should render correctly', () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/app/components/Collectibles/__snapshots__/index.test.js.snap b/app/components/Collectibles/__snapshots__/index.test.js.snap index 1befbeab8540..6499ccde8544 100644 --- a/app/components/Collectibles/__snapshots__/index.test.js.snap +++ b/app/components/Collectibles/__snapshots__/index.test.js.snap @@ -38,6 +38,7 @@ exports[`Collectibles should render correctly 1`] = ` { - this.props.navigation.navigate('Asset', asset); - }; - renderList() { return this.props.assets.map(asset => ( - this.onItemPress(asset)} // eslint-disable-line - style={styles.itemWrapper} - key={`asset-${asset.symbol}`} - > - - + + + {asset.image ? ( + + ) : ( + + )} - - {asset.balance} {asset.symbol} + {asset.name} + + {strings('collectible.collectible_token_id')}: {asset.tokenId} - ${asset.balanceFiat} USD - - - )); } + goToAddCollectible = () => { + this.props.navigation.push('AddAsset', 'collectibles'); + }; + render() { return ( {this.props.assets && this.props.assets.length ? this.renderList() : this.renderEmpty()} - + {strings('wallet.add_collectibles')} diff --git a/app/components/SearchAssetAutocomplete/__snapshots__/index.test.js.snap b/app/components/SearchTokenAutocomplete/__snapshots__/index.test.js.snap similarity index 90% rename from app/components/SearchAssetAutocomplete/__snapshots__/index.test.js.snap rename to app/components/SearchTokenAutocomplete/__snapshots__/index.test.js.snap index ca9acbcc0371..60f970581af6 100644 --- a/app/components/SearchAssetAutocomplete/__snapshots__/index.test.js.snap +++ b/app/components/SearchTokenAutocomplete/__snapshots__/index.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SearchAssetAutocomplete should render correctly 1`] = ` +exports[`SearchTokenAutocomplete should render correctly 1`] = ` { + it('should render correctly', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/app/components/Tokens/index.js b/app/components/Tokens/index.js index c528eb6c709b..843dcac92328 100644 --- a/app/components/Tokens/index.js +++ b/app/components/Tokens/index.js @@ -125,7 +125,7 @@ export default class Tokens extends Component { } goToAddToken = () => { - this.props.navigation.push('AddAsset'); + this.props.navigation.push('AddAsset', 'tokens'); }; render() { diff --git a/app/components/Wallet/index.js b/app/components/Wallet/index.js index fd12e44b7f0b..c037ae2c7a4d 100644 --- a/app/components/Wallet/index.js +++ b/app/components/Wallet/index.js @@ -64,7 +64,11 @@ class Wallet extends Component { /** * An array that represents the user tokens */ - tokens: PropTypes.array + tokens: PropTypes.array, + /** + * An array that represents the user collectibles + */ + collectibles: PropTypes.array }; renderTabBar() { @@ -81,7 +85,15 @@ class Wallet extends Component { } render() { - const { accounts, conversionRate, currentCurrency, identities, selectedAddress, tokens } = this.props; + const { + accounts, + conversionRate, + currentCurrency, + identities, + selectedAddress, + tokens, + collectibles + } = this.props; const account = { address: selectedAddress, ...identities[selectedAddress], ...accounts[selectedAddress] }; return ( @@ -96,7 +108,7 @@ class Wallet extends Component { @@ -110,7 +122,8 @@ const mapStateToProps = state => ({ currentCurrency: state.backgroundState.CurrencyRateController.currentCurrency, identities: state.backgroundState.PreferencesController.identities, selectedAddress: state.backgroundState.PreferencesController.selectedAddress, - tokens: state.backgroundState.AssetsController.tokens + tokens: state.backgroundState.AssetsController.tokens, + collectibles: state.backgroundState.AssetsController.collectibles }); export default connect(mapStateToProps)(Wallet); diff --git a/locales/en.json b/locales/en.json index e7d8547e0d18..3d927a2718d3 100644 --- a/locales/en.json +++ b/locales/en.json @@ -44,6 +44,10 @@ "tokens": { "cancel_add_token": "CANCEL", "add_token": "ADD TOKEN" + }, + "collectibles": { + "cancel_add_collectible": "CANCEL", + "add_collectible": "ADD COLLECTIBLE" } }, "token": { @@ -57,6 +61,13 @@ "decimals_cant_be_empty": "Token decimals can't be empty.", "select_token": "Select Token" }, + "collectible": { + "collectible_address": "Collectible Address", + "collectible_token_id": "Collectible Identifier", + "address_must_be_valid": "Collectible address must be a valid address.", + "address_cant_be_empty": "Collectible address can't be empty.", + "token_id_cant_be_empty": "Collectible identifier can't be empty." + }, "transfer": { "title": "Transfer", "send": "SEND", diff --git a/locales/es.json b/locales/es.json index abc112a3f5b7..238a801ee13c 100644 --- a/locales/es.json +++ b/locales/es.json @@ -44,6 +44,10 @@ "tokens": { "cancel_add_token": "CANCELAR", "add_token": "AGREGAR TOKEN" + }, + "collectibles": { + "cancel_add_collectible": "CANCELAR", + "add_collectible": "AGREGAR COLECCIONABLE" } }, "token": { @@ -51,12 +55,19 @@ "token_address": "Dirección del Token", "token_precision": "Token de Precisión", "search_tokens_placeholder": "Buscar Tokens", - "address_cant_be_empty": "Dirección del token no puede estar vacío.", + "address_cant_be_empty": "Dirección del token no puede estar vacía.", "address_must_be_valid": "Dirección del token debe ser válida.", "symbol_cant_be_empty": "Símbolo del token no puede estar vacío.", - "decimals_cant_be_empty": "Precisión del token no puede estar vacío.", + "decimals_cant_be_empty": "Precisión del token no puede estar vacía.", "select_token": "Seleccionar Token" }, + "collectible": { + "collectible_address": "Dirección del Coleccionable", + "collectible_token_id": "Identificador del Coleccionable", + "address_must_be_valid": "Dirección del coleccionable debe ser válida.", + "address_cant_be_empty": "Dirección del coleccionable no puede estar vacía.", + "token_id_cant_be_empty": "Identificador del coleccionable no puede estar vacío." + }, "transfer": { "title": "Transferir", "send": "ENVIAR", diff --git a/package.json b/package.json index c1fb52a49398..f3e8425b82cd 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "ethereumjs-util": "^5.2.0", "ethjs-unit": "^0.1.6", "events": "^3.0.0", - "eth-contract-metadata": "github:MetaMask/eth-contract-metadata#master", + "eth-contract-metadata": "github:estebanmino/eth-contract-metadata#master", "fuse.js": "^3.2.0", "gaba": "^1.0.0-beta.33", "prop-types": "^15.6.2", From 24865666ac2fbdda7c5da745821cce5e126b98cf Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Wed, 19 Sep 2018 11:44:29 -0300 Subject: [PATCH 4/7] update GABA version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f3e8425b82cd..831e60f3a7e2 100644 --- a/package.json +++ b/package.json @@ -45,12 +45,12 @@ "base-64": "^0.1.0", "buffer": "^4.9.1", "eth-block-tracker": "github:MetaMask/eth-block-tracker#3.0.1-subscription-fix", + "eth-contract-metadata": "github:estebanmino/eth-contract-metadata#master", "ethereumjs-util": "^5.2.0", "ethjs-unit": "^0.1.6", "events": "^3.0.0", - "eth-contract-metadata": "github:estebanmino/eth-contract-metadata#master", "fuse.js": "^3.2.0", - "gaba": "^1.0.0-beta.33", + "gaba": "^1.0.0-beta.36", "prop-types": "^15.6.2", "react": "16.4.1", "react-native": "0.56.0", From db2aff993ae773834b65228f9cb4b3f73fcd7548 Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Wed, 19 Sep 2018 11:58:27 -0300 Subject: [PATCH 5/7] update tests on AssetsController --- .../AssetOverview/__snapshots__/index.test.js.snap | 12 ------------ .../SendScreen/__snapshots__/index.test.js.snap | 6 +----- app/core/Engine.test.js | 1 + 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/app/components/AssetOverview/__snapshots__/index.test.js.snap b/app/components/AssetOverview/__snapshots__/index.test.js.snap index 3f9fa9195ba7..2e15fdc6e3bd 100644 --- a/app/components/AssetOverview/__snapshots__/index.test.js.snap +++ b/app/components/AssetOverview/__snapshots__/index.test.js.snap @@ -8,18 +8,6 @@ exports[`AssetOverview should render correctly 1`] = ` "#FFFFFF", ] } - end={ - Object { - "x": 0.5, - "y": 1, - } - } - start={ - Object { - "x": 0.5, - "y": 0, - } - } style={ Object { "borderBottomColor": "#CCCCCC", diff --git a/app/components/SendScreen/__snapshots__/index.test.js.snap b/app/components/SendScreen/__snapshots__/index.test.js.snap index e7d05bb2ea84..0d00019cf8ae 100644 --- a/app/components/SendScreen/__snapshots__/index.test.js.snap +++ b/app/components/SendScreen/__snapshots__/index.test.js.snap @@ -1,7 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SendScreen should render correctly 1`] = ` - - - -`; +exports[`SendScreen should render correctly 1`] = `<[object Object] />`; diff --git a/app/core/Engine.test.js b/app/core/Engine.test.js index 0490647980ba..a6752f88a7b1 100644 --- a/app/core/Engine.test.js +++ b/app/core/Engine.test.js @@ -4,6 +4,7 @@ describe('Engine', () => { const engine = Engine.init({}); expect(engine.datamodel.context).toHaveProperty('AccountTrackerController'); expect(engine.datamodel.context).toHaveProperty('AddressBookController'); + expect(engine.datamodel.context).toHaveProperty('AssetsController'); expect(engine.datamodel.context).toHaveProperty('BlockHistoryController'); expect(engine.datamodel.context).toHaveProperty('CurrencyRateController'); expect(engine.datamodel.context).toHaveProperty('KeyringController'); From 5145f83f4466c867723a6394b0988c3a9ce4d83a Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Fri, 21 Sep 2018 12:04:27 -0300 Subject: [PATCH 6/7] Assets components decomposition --- .../AddAsset/__snapshots__/index.test.js.snap | 4 +- app/components/AddAsset/index.js | 11 +-- .../__snapshots__/index.test.js.snap | 63 +++++++++++++++ app/components/CollectibleElement/index.js | 58 +++++++++++++ .../CollectibleElement/index.test.js | 12 +++ .../__snapshots__/index.test.js.snap | 29 +++++++ app/components/CollectibleImage/index.js | 44 ++++++++++ app/components/CollectibleImage/index.test.js | 12 +++ app/components/Collectibles/index.js | 49 +---------- .../__snapshots__/index.test.js.snap | 81 +++++++++++++++++++ app/components/TokenElement/index.js | 69 ++++++++++++++++ app/components/TokenElement/index.test.js | 10 +++ .../__snapshots__/index.test.js.snap | 20 +++++ app/components/TokenImage/index.js | 36 +++++++++ app/components/TokenImage/index.test.js | 10 +++ app/components/Tokens/index.js | 55 +------------ package.json | 2 +- 17 files changed, 459 insertions(+), 106 deletions(-) create mode 100644 app/components/CollectibleElement/__snapshots__/index.test.js.snap create mode 100644 app/components/CollectibleElement/index.js create mode 100644 app/components/CollectibleElement/index.test.js create mode 100644 app/components/CollectibleImage/__snapshots__/index.test.js.snap create mode 100644 app/components/CollectibleImage/index.js create mode 100644 app/components/CollectibleImage/index.test.js create mode 100644 app/components/TokenElement/__snapshots__/index.test.js.snap create mode 100644 app/components/TokenElement/index.js create mode 100644 app/components/TokenElement/index.test.js create mode 100644 app/components/TokenImage/__snapshots__/index.test.js.snap create mode 100644 app/components/TokenImage/index.js create mode 100644 app/components/TokenImage/index.test.js diff --git a/app/components/AddAsset/__snapshots__/index.test.js.snap b/app/components/AddAsset/__snapshots__/index.test.js.snap index 8297a3948309..23360fa3308a 100644 --- a/app/components/AddAsset/__snapshots__/index.test.js.snap +++ b/app/components/AddAsset/__snapshots__/index.test.js.snap @@ -8,7 +8,7 @@ exports[`AddAsset should render correctly 1`] = ` "flex": 1, } } - testID="add-asset-screen" + testID="add-undefined-screen" > `; diff --git a/app/components/AddAsset/index.js b/app/components/AddAsset/index.js index 8026327a5bff..70f1dda0a351 100644 --- a/app/components/AddAsset/index.js +++ b/app/components/AddAsset/index.js @@ -69,14 +69,15 @@ export default class AddAsset extends Component { render() { const { navigation: { - state: { params } + state: { + params: { assetType } + } }, navigation } = this.props; - return ( - - {params === 'tokens' ? ( + + {assetType === 'token' ? ( ) : ( - + )} ); diff --git a/app/components/CollectibleElement/__snapshots__/index.test.js.snap b/app/components/CollectibleElement/__snapshots__/index.test.js.snap new file mode 100644 index 000000000000..df7e62ee3900 --- /dev/null +++ b/app/components/CollectibleElement/__snapshots__/index.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CollectibleElement should render correctly 1`] = ` + + + + + NAME + + + Collectible Identifier + : + 123 + + + +`; diff --git a/app/components/CollectibleElement/index.js b/app/components/CollectibleElement/index.js new file mode 100644 index 000000000000..1ff8ab38593d --- /dev/null +++ b/app/components/CollectibleElement/index.js @@ -0,0 +1,58 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { TouchableOpacity, StyleSheet, Text, View } from 'react-native'; +import { colors, fontStyles } from '../../styles/common'; +import { strings } from '../../../locales/i18n'; +import CollectibleImage from '../CollectibleImage'; + +const styles = StyleSheet.create({ + itemWrapper: { + flex: 1, + flexDirection: 'row', + paddingHorizontal: 15, + paddingVertical: 10, + borderBottomWidth: StyleSheet.hairlineWidth, + borderBottomColor: colors.borderColor + }, + balances: { + flex: 1 + }, + name: { + fontSize: 16, + color: colors.fontPrimary, + ...fontStyles.normal + }, + tokenId: { + fontSize: 12, + color: colors.fontPrimary, + ...fontStyles.normal + } +}); + +/** + * View that renders a list of Collectibles + * also known as ERC-721 Tokens + */ +export default class CollectibleElement extends Component { + static propTypes = { + /** + * Asset object (in this case ERC721 token) + */ + asset: PropTypes.object + }; + + render() { + const { asset } = this.props; + return ( + + + + {asset.name} + + {strings('collectible.collectible_token_id')}: {asset.tokenId} + + + + ); + } +} diff --git a/app/components/CollectibleElement/index.test.js b/app/components/CollectibleElement/index.test.js new file mode 100644 index 000000000000..7bf00279ba54 --- /dev/null +++ b/app/components/CollectibleElement/index.test.js @@ -0,0 +1,12 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import CollectibleElement from './'; + +describe('CollectibleElement', () => { + it('should render correctly', () => { + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/app/components/CollectibleImage/__snapshots__/index.test.js.snap b/app/components/CollectibleImage/__snapshots__/index.test.js.snap new file mode 100644 index 000000000000..6d6b1c1af645 --- /dev/null +++ b/app/components/CollectibleImage/__snapshots__/index.test.js.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CollectibleImage should render correctly 1`] = ` + + + +`; diff --git a/app/components/CollectibleImage/index.js b/app/components/CollectibleImage/index.js new file mode 100644 index 000000000000..d12fb886336d --- /dev/null +++ b/app/components/CollectibleImage/index.js @@ -0,0 +1,44 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { StyleSheet, View } from 'react-native'; +import Image from 'react-native-remote-svg'; +import Identicon from '../Identicon'; + +const styles = StyleSheet.create({ + imageWrapper: { + width: 50, + height: 50, + overflow: 'hidden', + borderRadius: 100, + marginRight: 20 + }, + image: { + width: 50, + height: 50 + } +}); + +/** + * View that renders an ERC-721 Token image + */ +export default class CollectibleImage extends Component { + static propTypes = { + /** + * Asset object (in this case ERC721 token) + */ + asset: PropTypes.object + }; + + render() { + const { asset } = this.props; + return ( + + {asset.image ? ( + + ) : ( + + )} + + ); + } +} diff --git a/app/components/CollectibleImage/index.test.js b/app/components/CollectibleImage/index.test.js new file mode 100644 index 000000000000..2db15e7acbc9 --- /dev/null +++ b/app/components/CollectibleImage/index.test.js @@ -0,0 +1,12 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import CollectibleImage from './'; + +describe('CollectibleImage', () => { + it('should render correctly', () => { + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/app/components/Collectibles/index.js b/app/components/Collectibles/index.js index e60983de0fc2..7a36b2ac6e7a 100644 --- a/app/components/Collectibles/index.js +++ b/app/components/Collectibles/index.js @@ -2,10 +2,9 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { ScrollView, TouchableOpacity, StyleSheet, Text, View } from 'react-native'; import Icon from 'react-native-vector-icons/Feather'; -import Image from 'react-native-remote-svg'; -import Identicon from '../Identicon'; import { colors, fontStyles } from '../../styles/common'; import { strings } from '../../../locales/i18n'; +import CollectibleElement from '../CollectibleElement'; const styles = StyleSheet.create({ wrapper: { @@ -35,32 +34,6 @@ const styles = StyleSheet.create({ color: colors.primary, textTransform: 'uppercase', ...fontStyles.normal - }, - itemWrapper: { - flex: 1, - flexDirection: 'row', - paddingHorizontal: 15, - paddingVertical: 10, - borderBottomWidth: StyleSheet.hairlineWidth, - borderBottomColor: colors.borderColor - }, - imageWrapper: { - width: 50, - height: 50, - overflow: 'hidden', - borderRadius: 100, - marginRight: 20 - }, - image: { - width: 50, - height: 50 - }, - balances: { - flex: 1 - }, - name: { - fontSize: 16, - color: colors.fontPrimary } }); @@ -90,27 +63,11 @@ export default class Collectibles extends Component { } renderList() { - return this.props.assets.map(asset => ( - - - {asset.image ? ( - - ) : ( - - )} - - - {asset.name} - - {strings('collectible.collectible_token_id')}: {asset.tokenId} - - - - )); + return this.props.assets.map(asset => ); } goToAddCollectible = () => { - this.props.navigation.push('AddAsset', 'collectibles'); + this.props.navigation.push('AddAsset', { assetType: 'collectible' }); }; render() { diff --git a/app/components/TokenElement/__snapshots__/index.test.js.snap b/app/components/TokenElement/__snapshots__/index.test.js.snap new file mode 100644 index 000000000000..8c8e81c72e18 --- /dev/null +++ b/app/components/TokenElement/__snapshots__/index.test.js.snap @@ -0,0 +1,81 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TokenElement should render correctly 1`] = ` + + + + + ABC + + + $ + USD + + + + + + +`; diff --git a/app/components/TokenElement/index.js b/app/components/TokenElement/index.js new file mode 100644 index 000000000000..d2da3cce957c --- /dev/null +++ b/app/components/TokenElement/index.js @@ -0,0 +1,69 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { TouchableOpacity, StyleSheet, Text, View } from 'react-native'; +import Icon from 'react-native-vector-icons/Feather'; +import { colors, fontStyles } from '../../styles/common'; +import TokenImage from '../TokenImage'; + +const styles = StyleSheet.create({ + itemWrapper: { + flex: 1, + flexDirection: 'row', + paddingHorizontal: 15, + paddingVertical: 10, + borderBottomWidth: StyleSheet.hairlineWidth, + borderBottomColor: colors.borderColor + }, + balances: { + flex: 1 + }, + balance: { + fontSize: 16, + color: colors.fontPrimary, + ...fontStyles.normal + }, + balanceFiat: { + fontSize: 12, + color: colors.fontSecondary, + ...fontStyles.normal + }, + arrow: { + flex: 1, + alignSelf: 'flex-end' + }, + arrowIcon: { + marginTop: 8 + } +}); + +/** + * View that renders an ERC-20 Token list element + */ +export default class TokenElement extends Component { + static propTypes = { + /** + * Callback triggered on press + */ + onPress: PropTypes.func, + /** + * Asset object (in this case ERC20 token) + */ + asset: PropTypes.object + }; + + render() { + const { onPress, asset } = this.props; + return ( + + + + {asset.symbol} + ${asset.balanceFiat} USD + + + + + + ); + } +} diff --git a/app/components/TokenElement/index.test.js b/app/components/TokenElement/index.test.js new file mode 100644 index 000000000000..7a462485c1ab --- /dev/null +++ b/app/components/TokenElement/index.test.js @@ -0,0 +1,10 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import TokenElement from './'; + +describe('TokenElement', () => { + it('should render correctly', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/app/components/TokenImage/__snapshots__/index.test.js.snap b/app/components/TokenImage/__snapshots__/index.test.js.snap new file mode 100644 index 000000000000..f0a7e80f4bf9 --- /dev/null +++ b/app/components/TokenImage/__snapshots__/index.test.js.snap @@ -0,0 +1,20 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TokenImage should render correctly 1`] = ` + + + +`; diff --git a/app/components/TokenImage/index.js b/app/components/TokenImage/index.js new file mode 100644 index 000000000000..5799d1efc507 --- /dev/null +++ b/app/components/TokenImage/index.js @@ -0,0 +1,36 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { StyleSheet, View } from 'react-native'; +import AssetIcon from '../AssetIcon'; +import Identicon from '../Identicon'; + +const styles = StyleSheet.create({ + itemLogoWrapper: { + width: 50, + height: 50, + overflow: 'hidden', + borderRadius: 100, + marginRight: 20 + } +}); + +/** + * View that renders an ERC-20 Token logo + */ +export default class TokenElement extends Component { + static propTypes = { + /** + * Asset object (in this case ERC20 token) + */ + asset: PropTypes.object + }; + + render() { + const { asset } = this.props; + return ( + + {asset.logo ? : } + + ); + } +} diff --git a/app/components/TokenImage/index.test.js b/app/components/TokenImage/index.test.js new file mode 100644 index 000000000000..d596f6179cc9 --- /dev/null +++ b/app/components/TokenImage/index.test.js @@ -0,0 +1,10 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import TokenImage from './'; + +describe('TokenImage', () => { + it('should render correctly', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/app/components/Tokens/index.js b/app/components/Tokens/index.js index 843dcac92328..2aa35b3c4163 100644 --- a/app/components/Tokens/index.js +++ b/app/components/Tokens/index.js @@ -2,11 +2,10 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { ScrollView, TouchableOpacity, StyleSheet, Text, View } from 'react-native'; import Icon from 'react-native-vector-icons/Feather'; -import AssetIcon from '../AssetIcon'; import { colors, fontStyles } from '../../styles/common'; import { strings } from '../../../locales/i18n'; import contractMap from 'eth-contract-metadata'; -import Identicon from '../Identicon'; +import TokenElement from '../TokenElement'; const styles = StyleSheet.create({ wrapper: { @@ -36,39 +35,6 @@ const styles = StyleSheet.create({ color: colors.primary, textTransform: 'uppercase', ...fontStyles.normal - }, - itemWrapper: { - flex: 1, - flexDirection: 'row', - paddingHorizontal: 15, - paddingVertical: 10, - borderBottomWidth: StyleSheet.hairlineWidth, - borderBottomColor: colors.borderColor - }, - itemLogoWrapper: { - width: 50, - height: 50, - overflow: 'hidden', - borderRadius: 100, - marginRight: 20 - }, - balances: { - flex: 1 - }, - balance: { - fontSize: 16, - color: colors.fontPrimary - }, - balanceFiat: { - fontSize: 12, - color: colors.fontSecondary - }, - arrow: { - flex: 1, - alignSelf: 'flex-end' - }, - arrowIcon: { - marginTop: 8 } }); @@ -104,28 +70,13 @@ export default class Tokens extends Component { return this.props.assets.map(asset => { asset.logo = asset.address in contractMap ? contractMap[asset.address].logo : undefined; return ( - this.onItemPress(asset)} // eslint-disable-line - style={styles.itemWrapper} - key={`asset-${asset.symbol}`} - > - - {asset.logo ? : } - - - {asset.symbol} - ${asset.balanceFiat} USD - - - - - + this.onItemPress(asset)} asset={asset} key={asset.address} /> // eslint-disable-line ); }); } goToAddToken = () => { - this.props.navigation.push('AddAsset', 'tokens'); + this.props.navigation.push('AddAsset', { assetType: 'token' }); }; render() { diff --git a/package.json b/package.json index 831e60f3a7e2..135644642cda 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "ethjs-unit": "^0.1.6", "events": "^3.0.0", "fuse.js": "^3.2.0", - "gaba": "^1.0.0-beta.36", + "gaba": "^1.0.0-beta.40", "prop-types": "^15.6.2", "react": "16.4.1", "react-native": "0.56.0", From 1c0983cc3f928204f2c345645539f0052b34301a Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Fri, 21 Sep 2018 13:40:44 -0300 Subject: [PATCH 7/7] AddAsset add assetType to snapshot test --- .../AddAsset/__snapshots__/index.test.js.snap | 49 +++++++++++++++---- app/components/AddAsset/index.test.js | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/app/components/AddAsset/__snapshots__/index.test.js.snap b/app/components/AddAsset/__snapshots__/index.test.js.snap index 23360fa3308a..ecebb983f3a9 100644 --- a/app/components/AddAsset/__snapshots__/index.test.js.snap +++ b/app/components/AddAsset/__snapshots__/index.test.js.snap @@ -8,17 +8,46 @@ exports[`AddAsset should render correctly 1`] = ` "flex": 1, } } - testID="add-undefined-screen" + testID="add-token-screen" > - + + tabLabel="SEARCH" + testID="tab-search-token" + /> + + `; diff --git a/app/components/AddAsset/index.test.js b/app/components/AddAsset/index.test.js index 7a41c88ae412..310a5389180e 100644 --- a/app/components/AddAsset/index.test.js +++ b/app/components/AddAsset/index.test.js @@ -4,7 +4,7 @@ import AddAsset from './'; describe('AddAsset', () => { it('should render correctly', () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); });