From 2cab766066563a7d343cf3df262647fb0c1081de Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 17:24:26 -0400 Subject: [PATCH 1/4] warning when user is sending eth or assets to known asset contract --- app/components/UI/TransactionEdit/index.js | 22 +++++++++++-- app/components/UI/TransactionEditor/index.js | 34 ++++++++++++++++++++ locales/en.json | 1 + locales/es.json | 1 + 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/app/components/UI/TransactionEdit/index.js b/app/components/UI/TransactionEdit/index.js index 75e2dee083f..ffbbb51ffa9 100644 --- a/app/components/UI/TransactionEdit/index.js +++ b/app/components/UI/TransactionEdit/index.js @@ -81,6 +81,13 @@ const styles = StyleSheet.create({ lineHeight: 12, paddingTop: 6 }, + warning: { + ...fontStyles.bold, + color: colors.warning, + fontSize: 12, + lineHeight: 12, + paddingTop: 6 + }, form: { flex: 1, padding: 16, @@ -110,6 +117,10 @@ class TransactionEdit extends Component { * List of accounts from the AccountTrackerController */ accounts: PropTypes.object, + /** + * Callback to warn if transaction to is a known contract address + */ + checkForAssetAddress: PropTypes.func, /** * react-navigation object used for switching between screens */ @@ -181,6 +192,7 @@ class TransactionEdit extends Component { amountError: '', addressError: '', toAddressError: '', + toAddressWarning: '', gasError: '', fillMax: false, ensRecipient: undefined, @@ -312,9 +324,10 @@ class TransactionEdit extends Component { updateAndValidateToAddress = async (to, ensRecipient) => { await this.props.handleUpdateToAddress(to, ensRecipient); - let { toAddressError } = this.state; + let { toAddressError, toAddressWarning } = this.state; toAddressError = toAddressError || this.props.validateToAddress(); - this.setState({ toAddressError, ensRecipient }); + toAddressWarning = toAddressWarning || this.props.checkForAssetAddress(); + this.setState({ toAddressError, toAddressWarning, ensRecipient }); }; renderAmountLabel = () => { @@ -348,7 +361,7 @@ class TransactionEdit extends Component { transaction: { value, gas, gasPrice, from, to, selectedAsset, readableValue, ensRecipient }, showHexData } = this.props; - const { gasError, toAddressError, data, accountSelectIsOpen, ethInputIsOpen } = this.state; + const { gasError, toAddressError, toAddressWarning, data, accountSelectIsOpen, ethInputIsOpen } = this.state; const totalGas = isBN(gas) && isBN(gasPrice) ? gas.mul(gasPrice) : toBN('0x0'); return ( @@ -383,6 +396,9 @@ class TransactionEdit extends Component { {strings('transaction.to')}: {toAddressError ? {toAddressError} : null} + {!toAddressError && toAddressWarning ? ( + {toAddressWarning} + ) : null} { + const { + tokens, + collectibles, + transaction: { to } + } = this.props; + const address = toChecksumAddress(to); + const contractMapToken = contractMap[address]; + if (contractMapToken) return strings('transaction.known_asset_contract'); + const tokenAddress = tokens.find(token => token.address === address); + if (tokenAddress) return strings('transaction.known_asset_contract'); + const collectibleAddress = collectibles.find(collectible => collectible.address === address); + if (collectibleAddress) return strings('transaction.known_asset_contract'); + return undefined; + }; + handleNewTxMeta = async ({ target_address, chain_id = null, // eslint-disable-line no-unused-vars @@ -472,6 +503,7 @@ class TransactionEditor extends Component { validateGas={this.validateGas} validateToAddress={this.validateToAddress} handleUpdateAsset={this.handleUpdateAsset} + checkForAssetAddress={this.checkForAssetAddress} handleUpdateReadableValue={this.handleUpdateReadableValue} /> )} @@ -491,8 +523,10 @@ class TransactionEditor extends Component { const mapStateToProps = state => ({ accounts: state.engine.backgroundState.AccountTrackerController.accounts, + collectibles: state.engine.backgroundState.AssetsController.collectibles, contractBalances: state.engine.backgroundState.TokenBalancesController.contractBalances, selectedAddress: state.engine.backgroundState.PreferencesController.selectedAddress, + tokens: state.engine.backgroundState.AssetsController.tokens, transaction: state.transaction }); diff --git a/locales/en.json b/locales/en.json index f9822eebc2a..1cd717df64a 100644 --- a/locales/en.json +++ b/locales/en.json @@ -322,6 +322,7 @@ "invalid_gas": "Invalid gas amount", "invalid_gas_price": "Invalid gas price", "invalid_collectible_ownership": "You don't own this collectible", + "known_asset_contract": "Known asset contract address", "max": "Max", "recipient_address": "Recipient Address", "required": "Required", diff --git a/locales/es.json b/locales/es.json index 9f500cf8721..b3ef67d98be 100644 --- a/locales/es.json +++ b/locales/es.json @@ -326,6 +326,7 @@ "review_function_type": "TIPO DE FUNCIÓN", "review_hex_data": "DATOS HEX ", "invalid_collectible_ownership": "No eres el dueño de este coleccionable", + "known_asset_contract": "Dirección de contrato de un activo", "conversion_not_available": "Datos de conversión no disponibles", "value_not_available": "No disponible", "rate_not_available": "Conversión no disponible", From 5e09af539d59eb57bc7fd819106dce9a83ae5aa1 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 17:26:49 -0400 Subject: [PATCH 2/4] snapshots --- app/components/UI/TransactionEditor/index.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/components/UI/TransactionEditor/index.test.js b/app/components/UI/TransactionEditor/index.test.js index b02715ee0fa..fb062d42627 100644 --- a/app/components/UI/TransactionEditor/index.test.js +++ b/app/components/UI/TransactionEditor/index.test.js @@ -19,6 +19,10 @@ describe('TransactionEditor', () => { }, PreferencesController: { selectedAddress: '0x0' + }, + AssetsController: { + tokens: [], + collectibles: [] } } } From 3d282c50dfdf046e5031558138343bbc94c6f393 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 17:36:28 -0400 Subject: [PATCH 3/4] check contract map only on mainnet --- app/components/UI/TransactionEditor/index.js | 14 +++++++++++--- locales/es.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/components/UI/TransactionEditor/index.js b/app/components/UI/TransactionEditor/index.js index b4c5a90dd5c..07e6ff4fa94 100644 --- a/app/components/UI/TransactionEditor/index.js +++ b/app/components/UI/TransactionEditor/index.js @@ -34,6 +34,10 @@ class TransactionEditor extends Component { * react-navigation object used for switching between screens */ navigation: PropTypes.object, + /** + * A string representing the network name + */ + networkType: PropTypes.string, /** * Current mode this transaction editor is in */ @@ -444,11 +448,14 @@ class TransactionEditor extends Component { const { tokens, collectibles, - transaction: { to } + transaction: { to }, + networkType } = this.props; const address = toChecksumAddress(to); - const contractMapToken = contractMap[address]; - if (contractMapToken) return strings('transaction.known_asset_contract'); + if (networkType === 'mainnet') { + const contractMapToken = contractMap[address]; + if (contractMapToken) return strings('transaction.known_asset_contract'); + } const tokenAddress = tokens.find(token => token.address === address); if (tokenAddress) return strings('transaction.known_asset_contract'); const collectibleAddress = collectibles.find(collectible => collectible.address === address); @@ -525,6 +532,7 @@ const mapStateToProps = state => ({ accounts: state.engine.backgroundState.AccountTrackerController.accounts, collectibles: state.engine.backgroundState.AssetsController.collectibles, contractBalances: state.engine.backgroundState.TokenBalancesController.contractBalances, + networkType: state.engine.backgroundState.NetworkController.provider.type, selectedAddress: state.engine.backgroundState.PreferencesController.selectedAddress, tokens: state.engine.backgroundState.AssetsController.tokens, transaction: state.transaction diff --git a/locales/es.json b/locales/es.json index b3ef67d98be..c9959ae1420 100644 --- a/locales/es.json +++ b/locales/es.json @@ -326,7 +326,7 @@ "review_function_type": "TIPO DE FUNCIÓN", "review_hex_data": "DATOS HEX ", "invalid_collectible_ownership": "No eres el dueño de este coleccionable", - "known_asset_contract": "Dirección de contrato de un activo", + "known_asset_contract": "Dirección de contrato de un activo conocido", "conversion_not_available": "Datos de conversión no disponibles", "value_not_available": "No disponible", "rate_not_available": "Conversión no disponible", From 915f006b1fb08b678ed3579f6b354ff25bde8b6c Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 17:43:11 -0400 Subject: [PATCH 4/4] test --- app/components/UI/TransactionEditor/index.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/components/UI/TransactionEditor/index.test.js b/app/components/UI/TransactionEditor/index.test.js index fb062d42627..7f3e4eb880b 100644 --- a/app/components/UI/TransactionEditor/index.test.js +++ b/app/components/UI/TransactionEditor/index.test.js @@ -23,6 +23,11 @@ describe('TransactionEditor', () => { AssetsController: { tokens: [], collectibles: [] + }, + NetworkController: { + provider: { + type: 'mainnet' + } } } }