Update address component on transaction data screen (#15888)

* Update address component on transaction data screen

E2E test fix

Fix tests

* Metadata accounts

* Remove test resulsts

Co-authored-by: Brad Decker <bhdecker84@gmail.com>
feature/default_network_editable
amerkadicE 2 years ago committed by GitHub
parent e7deab4b9b
commit d4ffc3a587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      test/e2e/tests/send-eth.spec.js
  2. 8
      test/e2e/tests/send-hex-address.spec.js
  3. 4
      ui/components/app/confirm-page-container/confirm-page-container-container.test.js
  4. 3
      ui/components/app/confirm-page-container/confirm-page-container.component.js
  5. 7
      ui/components/app/confirm-page-container/confirm-page-container.container.js
  6. 6
      ui/components/app/transaction-list-item-details/transaction-list-item-details.component.js
  7. 6
      ui/components/app/transaction-list-item-details/transaction-list-item-details.container.js
  8. 47
      ui/components/ui/sender-to-recipient/sender-to-recipient.component.js
  9. 14
      ui/selectors/selectors.js

@ -135,7 +135,7 @@ describe('Send ETH non-contract address with data that matches ERC20 transfer da
await driver.clickElement({ text: 'Next', tag: 'button' }); await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.clickElement({ text: '0xc42...cd28' }); await driver.clickElement({ text: 'New contract' });
const recipientAddress = await driver.findElements({ const recipientAddress = await driver.findElements({
text: '0xc427D562164062a23a5cFf596A4a3208e72Acd28', text: '0xc427D562164062a23a5cFf596A4a3208e72Acd28',

@ -57,7 +57,7 @@ describe('Send ETH to a 40 character hexadecimal address', function () {
); );
await sendTransactionListItem.click(); await sendTransactionListItem.click();
await driver.clickElement({ text: 'Activity log', tag: 'summary' }); await driver.clickElement({ text: 'Activity log', tag: 'summary' });
await driver.clickElement('.sender-to-recipient__name:nth-of-type(2)'); await driver.clickElement('[data-testid="sender-to-recipient__name"]');
// Verify address in activity log // Verify address in activity log
const publicAddress = await driver.findElement( const publicAddress = await driver.findElement(
@ -108,7 +108,7 @@ describe('Send ETH to a 40 character hexadecimal address', function () {
); );
await sendTransactionListItem.click(); await sendTransactionListItem.click();
await driver.clickElement({ text: 'Activity log', tag: 'summary' }); await driver.clickElement({ text: 'Activity log', tag: 'summary' });
await driver.clickElement('.sender-to-recipient__name:nth-of-type(2)'); await driver.clickElement('[data-testid="sender-to-recipient__name"]');
// Verify address in activity log // Verify address in activity log
const publicAddress = await driver.findElement( const publicAddress = await driver.findElement(
@ -212,7 +212,7 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
); );
await sendTransactionListItem.click(); await sendTransactionListItem.click();
await driver.clickElement({ text: 'Activity log', tag: 'summary' }); await driver.clickElement({ text: 'Activity log', tag: 'summary' });
await driver.clickElement('.sender-to-recipient__name:nth-of-type(2)'); await driver.clickElement('[data-testid="sender-to-recipient__name"]');
// Verify address in activity log // Verify address in activity log
const publicAddress = await driver.findElement( const publicAddress = await driver.findElement(
@ -302,7 +302,7 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
); );
await sendTransactionListItem.click(); await sendTransactionListItem.click();
await driver.clickElement({ text: 'Activity log', tag: 'summary' }); await driver.clickElement({ text: 'Activity log', tag: 'summary' });
await driver.clickElement('.sender-to-recipient__name:nth-of-type(2)'); await driver.clickElement('[data-testid="sender-to-recipient__name"]');
// Verify address in activity log // Verify address in activity log
const publicAddress = await driver.findElement( const publicAddress = await driver.findElement(

@ -92,7 +92,7 @@ describe('Confirm Page Container Container Test', () => {
expect(senderRecipient).toBeInTheDocument(); expect(senderRecipient).toBeInTheDocument();
}); });
it('should render recipient as address', () => { it('should render recipient as address', () => {
const recipientName = screen.queryByText(shortenAddress(props.toAddress)); const recipientName = screen.queryByText('New contract');
expect(recipientName).toBeInTheDocument(); expect(recipientName).toBeInTheDocument();
}); });
@ -118,7 +118,7 @@ describe('Confirm Page Container Container Test', () => {
describe('Contact/AddressBook name should appear in recipient header', () => { describe('Contact/AddressBook name should appear in recipient header', () => {
it('should not show add to address dialog if recipient is in contact list and should display contact name', () => { it('should not show add to address dialog if recipient is in contact list and should display contact name', () => {
const addressBookName = 'test save name'; const addressBookName = 'New contract';
const addressBook = { const addressBook = {
'0x5': { '0x5': {

@ -63,6 +63,7 @@ export default class ConfirmPageContainer extends Component {
fromName: PropTypes.string, fromName: PropTypes.string,
toAddress: PropTypes.string, toAddress: PropTypes.string,
toName: PropTypes.string, toName: PropTypes.string,
toMetadataName: PropTypes.string,
toEns: PropTypes.string, toEns: PropTypes.string,
toNickname: PropTypes.string, toNickname: PropTypes.string,
// Content // Content
@ -118,6 +119,7 @@ export default class ConfirmPageContainer extends Component {
fromName, fromName,
fromAddress, fromAddress,
toName, toName,
toMetadataName,
toEns, toEns,
toNickname, toNickname,
toAddress, toAddress,
@ -231,6 +233,7 @@ export default class ConfirmPageContainer extends Component {
senderName={fromName} senderName={fromName}
senderAddress={fromAddress} senderAddress={fromAddress}
recipientName={toName} recipientName={toName}
recipientMetadataName={toMetadataName}
recipientAddress={toAddress} recipientAddress={toAddress}
recipientEns={toEns} recipientEns={toEns}
recipientNickname={toNickname} recipientNickname={toNickname}

@ -5,6 +5,8 @@ import {
getIsBuyableChain, getIsBuyableChain,
getNetworkIdentifier, getNetworkIdentifier,
getSwapsDefaultToken, getSwapsDefaultToken,
getMetadataContractName,
getAccountName,
} from '../../../selectors'; } from '../../../selectors';
import { showModal } from '../../../store/actions'; import { showModal } from '../../../store/actions';
import ConfirmPageContainer from './confirm-page-container.component'; import ConfirmPageContainer from './confirm-page-container.component';
@ -16,11 +18,14 @@ function mapStateToProps(state, ownProps) {
const networkIdentifier = getNetworkIdentifier(state); const networkIdentifier = getNetworkIdentifier(state);
const defaultToken = getSwapsDefaultToken(state); const defaultToken = getSwapsDefaultToken(state);
const accountBalance = defaultToken.string; const accountBalance = defaultToken.string;
const toName = getAccountName(state, to);
const toMetadataName = getMetadataContractName(to);
return { return {
isBuyableChain, isBuyableChain,
contact, contact,
toName: contact?.name || ownProps.toName, toName,
toMetadataName,
isOwnedAccount: getAccountsWithLabels(state) isOwnedAccount: getAccountsWithLabels(state)
.map((accountWithLabel) => accountWithLabel.address) .map((accountWithLabel) => accountWithLabel.address)
.includes(to), .includes(to),

@ -41,6 +41,8 @@ export default class TransactionListItemDetails extends PureComponent {
onClose: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,
recipientEns: PropTypes.string, recipientEns: PropTypes.string,
recipientAddress: PropTypes.string, recipientAddress: PropTypes.string,
recipientName: PropTypes.string,
recipientMetadataName: PropTypes.string,
rpcPrefs: PropTypes.object, rpcPrefs: PropTypes.object,
senderAddress: PropTypes.string.isRequired, senderAddress: PropTypes.string.isRequired,
tryReverseResolveAddress: PropTypes.func.isRequired, tryReverseResolveAddress: PropTypes.func.isRequired,
@ -139,6 +141,8 @@ export default class TransactionListItemDetails extends PureComponent {
showRetry, showRetry,
recipientEns, recipientEns,
recipientAddress, recipientAddress,
recipientName,
recipientMetadataName,
senderAddress, senderAddress,
isEarliestNonce, isEarliestNonce,
senderNickname, senderNickname,
@ -238,6 +242,8 @@ export default class TransactionListItemDetails extends PureComponent {
recipientEns={recipientEns} recipientEns={recipientEns}
recipientAddress={recipientAddress} recipientAddress={recipientAddress}
recipientNickname={recipientNickname} recipientNickname={recipientNickname}
recipientName={recipientName}
recipientMetadataName={recipientMetadataName}
senderName={senderNickname} senderName={senderNickname}
senderAddress={senderAddress} senderAddress={senderAddress}
onRecipientClick={() => { onRecipientClick={() => {

@ -8,6 +8,8 @@ import {
getIsCustomNetwork, getIsCustomNetwork,
getRpcPrefsForCurrentProvider, getRpcPrefsForCurrentProvider,
getEnsResolutionByAddress, getEnsResolutionByAddress,
getAccountName,
getMetadataContractName,
} from '../../../selectors'; } from '../../../selectors';
import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils';
import TransactionListItemDetails from './transaction-list-item-details.component'; import TransactionListItemDetails from './transaction-list-item-details.component';
@ -20,6 +22,8 @@ const mapStateToProps = (state, ownProps) => {
recipientEns = getEnsResolutionByAddress(state, address); recipientEns = getEnsResolutionByAddress(state, address);
} }
const addressBook = getAddressBook(state); const addressBook = getAddressBook(state);
const recipientName = getAccountName(state, recipientAddress);
const recipientMetadataName = getMetadataContractName(recipientAddress);
const getNickName = (address) => { const getNickName = (address) => {
const entry = addressBook.find((contact) => { const entry = addressBook.find((contact) => {
@ -38,6 +42,8 @@ const mapStateToProps = (state, ownProps) => {
recipientNickname: recipientAddress ? getNickName(recipientAddress) : null, recipientNickname: recipientAddress ? getNickName(recipientAddress) : null,
isCustomNetwork, isCustomNetwork,
blockExplorerLinkText: getBlockExplorerLinkText(state), blockExplorerLinkText: getBlockExplorerLinkText(state),
recipientName,
recipientMetadataName,
}; };
}; };

@ -103,34 +103,69 @@ export function RecipientWithAddress({
recipientNickname, recipientNickname,
recipientEns, recipientEns,
recipientName, recipientName,
recipientMetadataName,
}) { }) {
const t = useI18nContext(); const t = useI18nContext();
const [showNicknamePopovers, setShowNicknamePopovers] = useState(false); const [showNicknamePopovers, setShowNicknamePopovers] = useState(false);
const [addressCopied, setAddressCopied] = useState(false);
let tooltipHtml = <p>{t('copiedExclamation')}</p>;
if (!addressCopied) {
tooltipHtml = addressOnly ? (
<p>{t('copyAddress')}</p>
) : (
<p>
{shortenAddress(checksummedRecipientAddress)}
<br />
{t('copyAddress')}
</p>
);
}
return ( return (
<> <>
<div <div
className="sender-to-recipient__party sender-to-recipient__party--recipient sender-to-recipient__party--recipient-with-address" className="sender-to-recipient__party sender-to-recipient__party--recipient sender-to-recipient__party--recipient-with-address"
onClick={() => { onClick={() => {
if (recipientName) {
setAddressCopied(true);
copyToClipboard(checksummedRecipientAddress);
} else {
setShowNicknamePopovers(true); setShowNicknamePopovers(true);
if (onRecipientClick) { if (onRecipientClick) {
onRecipientClick(); onRecipientClick();
} }
}
}} }}
> >
<div className="sender-to-recipient__sender-icon"> <div className="sender-to-recipient__sender-icon">
<Identicon address={checksummedRecipientAddress} diameter={24} /> <Identicon address={checksummedRecipientAddress} diameter={24} />
</div> </div>
<div className="sender-to-recipient__name"> <Tooltip
position="bottom"
disabled={!recipientName}
html={tooltipHtml}
wrapperClassName="sender-to-recipient__tooltip-wrapper"
containerClassName="sender-to-recipient__tooltip-container"
onHidden={() => setAddressCopied(false)}
>
<div
className="sender-to-recipient__name"
data-testid="sender-to-recipient__name"
>
{addressOnly {addressOnly
? recipientNickname || ? recipientName ||
recipientNickname ||
recipientMetadataName ||
recipientEns || recipientEns ||
shortenAddress(checksummedRecipientAddress) shortenAddress(checksummedRecipientAddress)
: recipientNickname || : recipientName ||
recipientNickname ||
recipientMetadataName ||
recipientEns || recipientEns ||
recipientName ||
t('newContract')} t('newContract')}
</div> </div>
</Tooltip>
</div> </div>
{showNicknamePopovers ? ( {showNicknamePopovers ? (
<NicknamePopovers <NicknamePopovers
@ -145,6 +180,7 @@ export function RecipientWithAddress({
RecipientWithAddress.propTypes = { RecipientWithAddress.propTypes = {
checksummedRecipientAddress: PropTypes.string, checksummedRecipientAddress: PropTypes.string,
recipientName: PropTypes.string, recipientName: PropTypes.string,
recipientMetadataName: PropTypes.string,
recipientEns: PropTypes.string, recipientEns: PropTypes.string,
recipientNickname: PropTypes.string, recipientNickname: PropTypes.string,
addressOnly: PropTypes.bool, addressOnly: PropTypes.bool,
@ -175,6 +211,7 @@ export default function SenderToRecipient({
senderName, senderName,
recipientNickname, recipientNickname,
recipientName, recipientName,
recipientMetadataName,
recipientEns, recipientEns,
onRecipientClick, onRecipientClick,
onSenderClick, onSenderClick,
@ -208,6 +245,7 @@ export default function SenderToRecipient({
recipientNickname={recipientNickname} recipientNickname={recipientNickname}
recipientEns={recipientEns} recipientEns={recipientEns}
recipientName={recipientName} recipientName={recipientName}
recipientMetadataName={recipientMetadataName}
/> />
) : ( ) : (
<div className="sender-to-recipient__party sender-to-recipient__party--recipient"> <div className="sender-to-recipient__party sender-to-recipient__party--recipient">
@ -228,6 +266,7 @@ SenderToRecipient.propTypes = {
senderName: PropTypes.string, senderName: PropTypes.string,
senderAddress: PropTypes.string, senderAddress: PropTypes.string,
recipientName: PropTypes.string, recipientName: PropTypes.string,
recipientMetadataName: PropTypes.string,
recipientEns: PropTypes.string, recipientEns: PropTypes.string,
recipientAddress: PropTypes.string, recipientAddress: PropTypes.string,
recipientNickname: PropTypes.string, recipientNickname: PropTypes.string,

@ -412,6 +412,20 @@ export function getAddressBookEntryOrAccountName(state, address) {
return entry && entry.name !== '' ? entry.name : address; return entry && entry.name !== '' ? entry.name : address;
} }
export function getAccountName(state, address) {
const entry = Object.values(state.metamask.identities).find((identity) =>
isEqualCaseInsensitive(identity.address, toChecksumHexAddress(address)),
);
return entry && entry.name !== '' ? entry.name : '';
}
export function getMetadataContractName(address) {
const entry = Object.values(STATIC_MAINNET_TOKEN_LIST).find((identity) =>
isEqualCaseInsensitive(identity.address, toChecksumHexAddress(address)),
);
return entry && entry.name !== '' ? entry.name : '';
}
export function accountsWithSendEtherInfoSelector(state) { export function accountsWithSendEtherInfoSelector(state) {
const accounts = getMetaMaskAccounts(state); const accounts = getMetaMaskAccounts(state);
const identities = getMetaMaskIdentities(state); const identities = getMetaMaskIdentities(state);

Loading…
Cancel
Save