Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Display mailto links properly in Snaps link warning #30000

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions ui/components/app/snaps/snap-link-warning/snap-link-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,44 @@ import {
} from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';

const SnapLinkDisplay = ({ url }) => {
const parsedUrl = new URL(url);
const isHTTPS = parsedUrl.protocol === 'https:';

// If the link is HTTPS we split on the host to highlight it
if (isHTTPS) {
const urlParts = url.split(parsedUrl.host);

return (
<>
{urlParts[0]}
<b>{parsedUrl.host}</b>
{urlParts[1]}
</>
);
}

// Otherwise highlight anything beyond the protocol
const urlParts = url.split(parsedUrl.protocol);

return (
<>
{parsedUrl.protocol}
<b>{urlParts[1]}</b>
</>
);
};

SnapLinkDisplay.propTypes = {
/**
* The URL to display
*/
url: PropTypes.string,
};

export default function SnapLinkWarning({ isOpen, onClose, url }) {
const t = useI18nContext();

const parsedUrl = url && new URL(url);
const urlParts = parsedUrl && url.split(parsedUrl.host);
return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
Expand Down Expand Up @@ -85,17 +118,13 @@ export default function SnapLinkWarning({ isOpen, onClose, url }) {
paddingLeft={4}
width={BlockSize.Full}
>
{parsedUrl && (
<Text
ellipsis
style={{ overflow: 'hidden' }}
color={TextColor.primaryDefault}
>
{urlParts[0]}
<b>{parsedUrl.host}</b>
{urlParts[1]}
</Text>
)}
<Text
ellipsis
style={{ overflow: 'hidden' }}
color={TextColor.primaryDefault}
>
<SnapLinkDisplay url={url} />
</Text>
<Icon
name={IconName.Export}
color={IconColor.iconAlternative}
Expand Down
Loading