Skip to content

Commit a4f0944

Browse files
committed
Ensure smart contract interactions are properly represented on the confirm screen (#15446)
* Ensure smart contract interactions are properly represented on the confirm screen * Fix unit tests * Code cleanup * Cleanup * Code cleanup * Fix test
1 parent 1073b4a commit a4f0944

File tree

7 files changed

+57
-17
lines changed

7 files changed

+57
-17
lines changed

app/scripts/controllers/transactions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const VALID_UNAPPROVED_TRANSACTION_TYPES = [
7474
TRANSACTION_TYPES.SIMPLE_SEND,
7575
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
7676
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM,
77+
TRANSACTION_TYPES.CONTRACT_INTERACTION,
7778
];
7879

7980
/**

ui/components/app/user-preferenced-currency-display/user-preferenced-currency-display.component.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default function UserPreferencedCurrencyDisplay({
1313
showEthLogo,
1414
type,
1515
showFiat,
16+
showCurrencySuffix,
1617
...restProps
1718
}) {
1819
const { currency, numberOfDecimals } = useUserPreferencedCurrency(type, {
@@ -43,6 +44,7 @@ export default function UserPreferencedCurrencyDisplay({
4344
data-testid={dataTestId}
4445
numberOfDecimals={numberOfDecimals}
4546
prefixComponent={prefixComponent}
47+
suffix={showCurrencySuffix && !showEthLogo && currency}
4648
/>
4749
);
4850
}
@@ -68,4 +70,5 @@ UserPreferencedCurrencyDisplay.propTypes = {
6870
PropTypes.number,
6971
]),
7072
showFiat: PropTypes.bool,
73+
showCurrencySuffix: PropTypes.bool,
7174
};

ui/ducks/send/send.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
1919
KNOWN_RECIPIENT_ADDRESS_WARNING,
2020
NEGATIVE_ETH_ERROR,
21+
RECIPIENT_TYPES,
2122
} from '../../pages/send/send.constants';
2223

2324
import {
@@ -82,14 +83,18 @@ import {
8283
getTokens,
8384
getUnapprovedTxs,
8485
} from '../metamask/metamask';
86+
import {
87+
isSmartContractAddress,
88+
sumHexes,
89+
} from '../../helpers/utils/transactions.util';
8590

8691
import { resetEnsResolution } from '../ens';
8792
import {
8893
isBurnAddress,
8994
isValidHexAddress,
9095
toChecksumHexAddress,
9196
} from '../../../shared/modules/hexstring-utils';
92-
import { sumHexes } from '../../helpers/utils/transactions.util';
97+
9398
import fetchEstimatedL1Fee from '../../helpers/utils/optimism/fetchEstimatedL1Fee';
9499

95100
import { TOKEN_STANDARDS, ETH } from '../../helpers/constants/common';
@@ -383,6 +388,7 @@ export const draftTransactionInitialState = {
383388
error: null,
384389
nickname: '',
385390
warning: null,
391+
type: '',
386392
recipientWarningAcknowledged: false,
387393
},
388394
status: SEND_STATUSES.VALID,
@@ -1172,6 +1178,12 @@ const slice = createSlice({
11721178
draftTransaction.recipient.warning = action.payload;
11731179
},
11741180

1181+
updateRecipientType: (state, action) => {
1182+
const draftTransaction =
1183+
state.draftTransactions[state.currentTransactionUUID];
1184+
draftTransaction.recipient.type = action.payload;
1185+
},
1186+
11751187
updateDraftTransactionStatus: (state, action) => {
11761188
const draftTransaction =
11771189
state.draftTransactions[state.currentTransactionUUID];
@@ -1876,19 +1888,24 @@ export function updateRecipientUserInput(userInput) {
18761888
const inputIsValidHexAddress = isValidHexAddress(userInput);
18771889
let isProbablyAnAssetContract = false;
18781890
if (inputIsValidHexAddress) {
1879-
const { symbol, decimals } = getTokenMetadata(userInput, tokenMap) || {};
1891+
const smartContractAddress = await isSmartContractAddress(userInput);
1892+
if (smartContractAddress) {
1893+
dispatch(actions.updateRecipientType(RECIPIENT_TYPES.SMART_CONTRACT));
1894+
const { symbol, decimals } =
1895+
getTokenMetadata(userInput, tokenMap) || {};
18801896

1881-
isProbablyAnAssetContract = symbol && decimals !== undefined;
1897+
isProbablyAnAssetContract = symbol && decimals !== undefined;
18821898

1883-
if (!isProbablyAnAssetContract) {
1884-
try {
1885-
const { standard } = await getTokenStandardAndDetails(
1886-
userInput,
1887-
sendingAddress,
1888-
);
1889-
isProbablyAnAssetContract = Boolean(standard);
1890-
} catch (e) {
1891-
console.log(e);
1899+
if (!isProbablyAnAssetContract) {
1900+
try {
1901+
const { standard } = await getTokenStandardAndDetails(
1902+
userInput,
1903+
sendingAddress,
1904+
);
1905+
isProbablyAnAssetContract = Boolean(standard);
1906+
} catch (e) {
1907+
console.log(e);
1908+
}
18921909
}
18931910
}
18941911
}
@@ -2259,7 +2276,10 @@ export function signTransaction() {
22592276
updateTransactionGasFees(draftTransaction.id, editingTx.txParams),
22602277
);
22612278
} else {
2262-
let transactionType = TRANSACTION_TYPES.SIMPLE_SEND;
2279+
let transactionType =
2280+
draftTransaction.recipient.type === RECIPIENT_TYPES.SMART_CONTRACT
2281+
? TRANSACTION_TYPES.CONTRACT_INTERACTION
2282+
: TRANSACTION_TYPES.SIMPLE_SEND;
22632283

22642284
if (draftTransaction.asset.type !== ASSET_TYPES.NATIVE) {
22652285
transactionType =

ui/ducks/send/send.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,7 @@ describe('Send Slice', () => {
24122412
nickname: '',
24132413
warning: null,
24142414
recipientWarningAcknowledged: false,
2415+
type: '',
24152416
},
24162417
status: SEND_STATUSES.VALID,
24172418
transactionType: '0x0',
@@ -2554,6 +2555,7 @@ describe('Send Slice', () => {
25542555
error: null,
25552556
nickname: '',
25562557
warning: null,
2558+
type: '',
25572559
recipientWarningAcknowledged: false,
25582560
},
25592561
status: SEND_STATUSES.VALID,
@@ -2740,6 +2742,7 @@ describe('Send Slice', () => {
27402742
error: null,
27412743
warning: null,
27422744
nickname: '',
2745+
type: '',
27432746
recipientWarningAcknowledged: false,
27442747
},
27452748
status: SEND_STATUSES.VALID,

ui/helpers/utils/transactions.util.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ export function getLatestSubmittedTxWithNonce(
144144
}
145145

146146
export async function isSmartContractAddress(address) {
147-
const { isContractCode } = await readAddressAsContract(global.eth, address);
148-
return isContractCode;
147+
const { isContractAddress } = await readAddressAsContract(
148+
global.eth,
149+
address,
150+
);
151+
return isContractAddress;
149152
}
150153

151154
export function sumHexes(...args) {

ui/pages/confirm-transaction-base/confirm-transaction-base.component.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,20 +864,24 @@ export default class ConfirmTransactionBase extends Component {
864864
}
865865

866866
renderTitleComponent() {
867-
const { title, hexTransactionAmount } = this.props;
867+
const { title, hexTransactionAmount, txData } = this.props;
868868

869869
// Title string passed in by props takes priority
870870
if (title) {
871871
return null;
872872
}
873873

874+
const isContractInteraction =
875+
txData.type === TRANSACTION_TYPES.CONTRACT_INTERACTION;
876+
874877
return (
875878
<UserPreferencedCurrencyDisplay
876879
value={hexTransactionAmount}
877880
type={PRIMARY}
878881
showEthLogo
879882
ethLogoHeight={24}
880-
hideLabel
883+
hideLabel={!isContractInteraction}
884+
showCurrencySuffix={isContractInteraction}
881885
/>
882886
);
883887
}

ui/pages/send/send.constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ const ENS_ILLEGAL_CHARACTER = 'ensIllegalCharacter';
4747
const ENS_UNKNOWN_ERROR = 'ensUnknownError';
4848
const ENS_REGISTRATION_ERROR = 'ensRegistrationError';
4949

50+
const RECIPIENT_TYPES = {
51+
SMART_CONTRACT: 'SMART_CONTRACT',
52+
NON_CONTRACT: 'NON_CONTRACT',
53+
};
54+
5055
export {
5156
MAX_GAS_LIMIT_DEC,
5257
HIGH_FEE_WARNING_MULTIPLIER,
@@ -73,4 +78,5 @@ export {
7378
CONFUSING_ENS_ERROR,
7479
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
7580
COLLECTIBLE_TRANSFER_FROM_FUNCTION_SIGNATURE,
81+
RECIPIENT_TYPES,
7682
};

0 commit comments

Comments
 (0)