mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Enhance approval screen title logic (#15406)
This commit is contained in:
parent
d484f107c0
commit
fb191c865b
@ -33,6 +33,10 @@ import {
|
|||||||
ERC20,
|
ERC20,
|
||||||
ERC721,
|
ERC721,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
|
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 = {
|
||||||
@ -462,31 +466,12 @@ export default class ConfirmApproveContent extends Component {
|
|||||||
userAddress,
|
userAddress,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { t } = this.context;
|
const { t } = this.context;
|
||||||
|
const useBlockExplorer =
|
||||||
|
rpcPrefs?.blockExplorerUrl ||
|
||||||
|
[...TEST_CHAINS, MAINNET_CHAIN_ID].includes(chainId);
|
||||||
|
|
||||||
let titleTokenDescription = t('token');
|
let titleTokenDescription = t('token');
|
||||||
if (rpcPrefs?.blockExplorerUrl || chainId) {
|
const tokenIdWrapped = tokenId ? ` (#${tokenId})` : '';
|
||||||
const unknownTokenBlockExplorerLink = getTokenTrackerLink(
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
assetStandard === ERC20 ||
|
assetStandard === ERC20 ||
|
||||||
(tokenSymbol && !tokenId && !isSetApproveForAll)
|
(tokenSymbol && !tokenId && !isSetApproveForAll)
|
||||||
@ -499,11 +484,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,
|
||||||
@ -512,24 +500,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() {
|
||||||
@ -631,7 +633,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">
|
||||||
|
@ -39,11 +39,12 @@ 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).toStrictEqual(
|
||||||
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…
Reference in New Issue
Block a user