Enhance approval screen title logic (#15406)

feature/default_network_editable
Alex Donesky 2 years ago committed by Dan J Miller
parent 8b4e046ac3
commit 29c7f2227a
  1. 73
      ui/pages/confirm-approve/confirm-approve-content/confirm-approve-content.component.js
  2. 13
      ui/pages/confirm-approve/confirm-approve-content/confirm-approve-content.component.test.js
  3. 6
      ui/pages/confirm-approve/confirm-approve-content/index.scss

@ -29,6 +29,10 @@ import { ConfirmPageContainerWarning } from '../../../components/app/confirm-pag
import GasDetailsItem from '../../../components/app/gas-details-item'; import GasDetailsItem from '../../../components/app/gas-details-item';
import LedgerInstructionField from '../../../components/app/ledger-instruction-field'; import LedgerInstructionField from '../../../components/app/ledger-instruction-field';
import { ERC1155, ERC20, ERC721 } from '../../../helpers/constants/common'; import { ERC1155, ERC20, ERC721 } from '../../../helpers/constants/common';
import {
MAINNET_CHAIN_ID,
TEST_CHAINS,
} from '../../../../shared/constants/network';
export default class ConfirmApproveContent extends Component { export default class ConfirmApproveContent extends Component {
static contextTypes = { static contextTypes = {
@ -458,31 +462,12 @@ export default class ConfirmApproveContent extends Component {
userAddress, userAddress,
} = this.props; } = this.props;
const { t } = this.context; const { t } = this.context;
let titleTokenDescription = t('token'); const useBlockExplorer =
if (rpcPrefs?.blockExplorerUrl || chainId) { rpcPrefs?.blockExplorerUrl ||
const unknownTokenBlockExplorerLink = getTokenTrackerLink( [...TEST_CHAINS, MAINNET_CHAIN_ID].includes(chainId);
tokenAddress,
chainId,
null,
userAddress,
{
blockExplorerUrl: rpcPrefs?.blockExplorerUrl ?? null,
},
);
const unknownTokenLink = (
<a
href={unknownTokenBlockExplorerLink}
target="_blank"
rel="noopener noreferrer"
className="confirm-approve-content__unknown-asset"
>
{t('token')}
</a>
);
titleTokenDescription = unknownTokenLink;
}
let titleTokenDescription = t('token');
const tokenIdWrapped = tokenId ? ` (#${tokenId})` : '';
if ( if (
assetStandard === ERC20 || assetStandard === ERC20 ||
(tokenSymbol && !tokenId && !isSetApproveForAll) (tokenSymbol && !tokenId && !isSetApproveForAll)
@ -495,11 +480,14 @@ export default class ConfirmApproveContent extends Component {
(assetName && tokenId) || (assetName && tokenId) ||
(tokenSymbol && tokenId) (tokenSymbol && tokenId)
) { ) {
const tokenIdWrapped = tokenId ? ` (#${tokenId})` : '';
if (assetName || tokenSymbol) { if (assetName || tokenSymbol) {
titleTokenDescription = `${assetName ?? tokenSymbol}${tokenIdWrapped}`; titleTokenDescription = `${assetName ?? tokenSymbol}`;
} else { } else {
const unknownNFTBlockExplorerLink = getTokenTrackerLink( titleTokenDescription = t('nft');
}
if (useBlockExplorer) {
const blockExplorerLink = getTokenTrackerLink(
tokenAddress, tokenAddress,
chainId, chainId,
null, null,
@ -508,24 +496,38 @@ export default class ConfirmApproveContent extends Component {
blockExplorerUrl: rpcPrefs?.blockExplorerUrl ?? null, blockExplorerUrl: rpcPrefs?.blockExplorerUrl ?? null,
}, },
); );
const unknownNFTLink = ( const blockExplorerElement = (
<> <>
<a <a
href={unknownNFTBlockExplorerLink} href={blockExplorerLink}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="confirm-approve-content__unknown-asset" title={tokenAddress}
className="confirm-approve-content__approval-asset-link"
> >
{t('nft')} {titleTokenDescription}
</a> </a>
{tokenIdWrapped && <span>{tokenIdWrapped}</span>} {tokenIdWrapped && <span>{tokenIdWrapped}</span>}
</> </>
); );
titleTokenDescription = unknownNFTLink; return blockExplorerElement;
} }
} }
return titleTokenDescription; return (
<>
<span
className="confirm-approve-content__approval-asset-title"
onClick={() => {
copyToClipboard(tokenAddress);
}}
title={tokenAddress}
>
{titleTokenDescription}
</span>
{tokenIdWrapped && <span>{tokenIdWrapped}</span>}
</>
);
} }
renderTitle() { renderTitle() {
@ -627,7 +629,10 @@ export default class ConfirmApproveContent extends Component {
</Typography> </Typography>
</Box> </Box>
</Box> </Box>
<div className="confirm-approve-content__title"> <div
className="confirm-approve-content__title"
data-testid="confirm-approve-title"
>
{this.renderTitle()} {this.renderTitle()}
</div> </div>
<div className="confirm-approve-content__description"> <div className="confirm-approve-content__description">

@ -40,11 +40,16 @@ const props = {
describe('ConfirmApproveContent Component', () => { describe('ConfirmApproveContent Component', () => {
it('should render Confirm approve page correctly', () => { it('should render Confirm approve page correctly', () => {
const { queryByText, getByText, getAllByText } = renderComponent(props); const {
queryByText,
getByText,
getAllByText,
getByTestId,
} = renderComponent(props);
expect(queryByText('metamask.github.io')).toBeInTheDocument(); expect(queryByText('metamask.github.io')).toBeInTheDocument();
expect( expect(getByTestId('confirm-approve-title').textContent).toBe(
queryByText('Give permission to access your TST?'), ' Give permission to access your TST? ',
).toBeInTheDocument(); );
expect( expect(
queryByText( queryByText(
'By granting permission, you are allowing the following contract to access your funds', 'By granting permission, you are allowing the following contract to access your funds',

@ -9,10 +9,14 @@
padding: 0 24px 16px 24px; padding: 0 24px 16px 24px;
} }
&__unknown-asset { &__approval-asset-link {
color: var(--color-primary-default); color: var(--color-primary-default);
} }
&__approval-asset-title {
cursor: pointer;
}
&__icon-display-content { &__icon-display-content {
display: flex; display: flex;
height: 51px; height: 51px;

Loading…
Cancel
Save