Skip to content

Commit

Permalink
Bugfix: contract deployments (#1223)
Browse files Browse the repository at this point in the history
* allow contract deployments

* add contract icon

* smaps
  • Loading branch information
estebanmino authored Nov 22, 2019
1 parent a9882a2 commit 03faf2b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
11 changes: 9 additions & 2 deletions app/components/UI/TransactionEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ class TransactionEditor extends PureComponent {
/**
* Action that sets transaction attributes from object to a transaction
*/
setTransactionObject: PropTypes.func.isRequired
setTransactionObject: PropTypes.func.isRequired,
/**
* Whether was prompted from approval
*/
promptedFromApproval: PropTypes.bool
};

state = {
Expand Down Expand Up @@ -480,8 +484,11 @@ class TransactionEditor extends PureComponent {
validateToAddress = () => {
let error;
const {
transaction: { to }
transaction: { to },
promptedFromApproval
} = this.props;
// If it comes from a dapp it could be a contract deployment
if (promptedFromApproval && !to) return error;
!to && (error = strings('transaction.required'));
!to && this.state.toFocused && (error = strings('transaction.required'));
to && !isValidAddress(to) && (error = strings('transaction.invalid_address'));
Expand Down
11 changes: 9 additions & 2 deletions app/components/UI/TransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Analytics from '../../../core/Analytics';
import ANALYTICS_EVENT_OPTS from '../../../util/analytics';
import contractMap from 'eth-contract-metadata';
import AssetIcon from '../AssetIcon';
import FontAwesome from 'react-native-vector-icons/FontAwesome';

const FONT_SIZE = PixelRatio.get() < 2 ? 12 : 16;
const styles = StyleSheet.create({
Expand Down Expand Up @@ -208,16 +209,22 @@ class TransactionReview extends PureComponent {
</Text>
</View>
);
} else {
} else if (to) {
child = (
<Text style={[styles.addressText, styles.addressWrapper]} numberOfLines={1}>
{renderAccountName(to, identities)}
</Text>
);
} else {
child = (
<Text style={[styles.addressText, styles.addressWrapper]} numberOfLines={1}>
{strings('transactions.to_contract')}
</Text>
);
}
return (
<View style={[styles.addressGraphic, styles.toGraphic]}>
<Identicon address={to} diameter={18} />
{to ? <Identicon address={to} diameter={18} /> : <FontAwesome name="file-text-o" size={18} />}
{child}
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`Approval should render correctly 1`] = `
onCancel={[Function]}
onConfirm={[Function]}
onModeChange={[Function]}
promptedFromApproval={true}
transaction={
Object {
"assetType": undefined,
Expand Down
5 changes: 3 additions & 2 deletions app/components/Views/Approval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { getTransactionOptionsTitle } from '../../UI/Navbar';
import { colors } from '../../../styles/common';
import { newTransaction } from '../../../actions/transaction';
import { connect } from 'react-redux';
import { toChecksumAddress } from 'ethereumjs-util';
import TransactionsNotificationManager from '../../../core/TransactionsNotificationManager';
import Analytics from '../../../core/Analytics';
import ANALYTICS_EVENT_OPTS from '../../../util/analytics';
import { getTransactionReviewActionKey } from '../../../util/transactions';
import { strings } from '../../../../locales/i18n';
import { safeToChecksumAddress } from '../../../util/address';

const REVIEW = 'review';
const EDIT = 'edit';
Expand Down Expand Up @@ -212,7 +212,7 @@ class Approval extends PureComponent {
gas: BNToHex(transaction.gas),
gasPrice: BNToHex(transaction.gasPrice),
value: BNToHex(transaction.value),
to: toChecksumAddress(transaction.to)
to: safeToChecksumAddress(transaction.to)
});

/**
Expand Down Expand Up @@ -243,6 +243,7 @@ class Approval extends PureComponent {
return (
<SafeAreaView style={styles.wrapper} testID={'confirm-transaction-screen'}>
<TransactionEditor
promptedFromApproval
mode={mode}
onCancel={this.onCancel}
onConfirm={this.onConfirm}
Expand Down
4 changes: 3 additions & 1 deletion app/util/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ export async function getMethodData(data) {
* Returns wether the given address is a contract
*
* @param {string} address - Ethereum address
* @returns {boolean} - Wether the given address is a contract
* @returns {boolean} - Whether the given address is a contract
*/
export async function isSmartContractAddress(address) {
if (!address) return false;
address = toChecksumAddress(address);
// If in contract map we don't need to cache it
if (contractMap[address]) {
Expand Down Expand Up @@ -214,6 +215,7 @@ export async function isCollectibleAddress(address, tokenId) {
*/
export async function getTransactionActionKey(transaction) {
const { transaction: { data, to } = {} } = transaction;
if (!to) return CONTRACT_METHOD_DEPLOY;
let ret;
// if data in transaction try to get method data
if (data && data !== '0x') {
Expand Down

0 comments on commit 03faf2b

Please sign in to comment.