1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Improve handling for block explorer url host extraction (#11543)

This commit is contained in:
ryanml 2021-07-16 11:52:41 -07:00 committed by GitHub
parent ff521fe210
commit e60e371105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,15 @@ export default function AccountOptionsMenu({ anchorElement, onClose }) {
const selectedIdentity = useSelector(getSelectedIdentity);
const { address } = selectedIdentity;
const addressLink = getAccountLink(address, chainId, rpcPrefs);
const { blockExplorerUrl } = rpcPrefs;
const getBlockExplorerUrlHost = () => {
try {
return new URL(blockExplorerUrl)?.hostname;
} catch (err) {
return '';
}
};
const openFullscreenEvent = useMetricEvent({
eventOpts: {
@ -67,6 +76,7 @@ export default function AccountOptionsMenu({ anchorElement, onClose }) {
});
const isRemovable = keyring.type !== 'HD Key Tree';
const blockExplorerUrlSubTitle = getBlockExplorerUrlHost();
return (
<Menu
@ -106,9 +116,9 @@ export default function AccountOptionsMenu({ anchorElement, onClose }) {
onClose();
}}
subtitle={
rpcPrefs.blockExplorerUrl ? (
blockExplorerUrlSubTitle ? (
<span className="account-options-menu__explorer-origin">
{rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/u)[1]}
{blockExplorerUrlSubTitle}
</span>
) : null
}