From e60e3711052bd7c28d051886245cf1ee18955123 Mon Sep 17 00:00:00 2001 From: ryanml Date: Fri, 16 Jul 2021 11:52:41 -0700 Subject: [PATCH] Improve handling for block explorer url host extraction (#11543) --- ui/components/app/menu-bar/account-options-menu.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/components/app/menu-bar/account-options-menu.js b/ui/components/app/menu-bar/account-options-menu.js index 3ae13c385..fa2d1b377 100644 --- a/ui/components/app/menu-bar/account-options-menu.js +++ b/ui/components/app/menu-bar/account-options-menu.js @@ -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 ( - {rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/u)[1]} + {blockExplorerUrlSubTitle} ) : null }