Skip to content

Commit

Permalink
Refactor slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Jan 30, 2025
1 parent 4b26dd4 commit da0d947
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 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,12 +32,36 @@ import {
} from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';

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

const SnapLinkDisplay = ({ url }) => {

Check failure on line 35 in ui/components/app/snaps/snap-link-warning/snap-link-warning.js

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

'url' is missing in props validation
const parsedUrl = new URL(url);
const isHTTPS = parsedUrl.protocol === 'https:';
const urlParts = url.split(parsedUrl.host);

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

Check failure on line 41 in ui/components/app/snaps/snap-link-warning/snap-link-warning.js

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

'url.split' is missing in props validation

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

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

Check failure on line 53 in ui/components/app/snaps/snap-link-warning/snap-link-warning.js

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

'url.split' is missing in props validation

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

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

return (
<Modal isOpen={isOpen} onClose={onClose}>
Expand Down Expand Up @@ -92,15 +116,7 @@ export default function SnapLinkWarning({ isOpen, onClose, url }) {
style={{ overflow: 'hidden' }}
color={TextColor.primaryDefault}
>
{isHTTPS ? (
<>
{urlParts[0]}
<b>{parsedUrl.host}</b>
{urlParts[1]}
</>
) : (
url
)}
<SnapLinkDisplay url={url} />
</Text>
<Icon
name={IconName.Export}
Expand Down

0 comments on commit da0d947

Please sign in to comment.