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

checkpoint: into main from release/2.3.0 @ 34d2fdd25545e73e4578200de8cbaa6396f87ab3 #2332

Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions packages/core/src/hooks/useOpenExternal.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import isElectron from 'is-electron';
import { useCallback } from 'react';
import isURL from 'validator/es/lib/isURL';

export default function useOpenExternal(): (url: string) => void {
function handleOpen(url: string) {
const handleOpen = useCallback((url: string) => {
if (!isURL(url, { protocols: ['http', 'https', 'ipfs'], require_protocol: true })) {
return;
}

if (isElectron()) {
// @ts-ignore
window.shell.openExternal(url);
return;
}

window.open(url, '_blank');
}
}, []);

return handleOpen;
}
53 changes: 27 additions & 26 deletions packages/gui/src/components/nfts/NFTDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Tooltip,
Truncate,
truncateValue,
Link,
useCurrencyCode,
} from '@chia-network/core';
import { Trans } from '@lingui/macro';
Expand Down Expand Up @@ -302,35 +301,37 @@ export default function NFTDetails(props: NFTDetailsProps) {
});
}

if (metadata?.preview_image_uris) {
const value = metadata?.preview_image_uris.map((uri: string) => (
<span>
&nbsp;
<Link href={uri} target="_blank">
{uri}
</Link>
</span>
));
rows.push({
key: 'preview_image_uris',
label: <Trans>Preview image uris</Trans>,
value,
if (Array.isArray(metadata?.preview_image_uris)) {
metadata.preview_image_uris.forEach((uri: string, i: number) => {
if (uri) {
const index = i + 1;
rows.push({
key: `preview-image-uris-${i}`,
label: <Trans>Preview image URL {index}</Trans>,
value: (
<Tooltip title={uri} copyToClipboard>
<Typography variant="body2">{uri}</Typography>
</Tooltip>
),
});
}
});
}

if (Array.isArray(metadata?.preview_video_uris)) {
const value = metadata?.preview_video_uris.map((uri: string) => (
<span>
&nbsp;
<Link target="_blank" href={uri}>
{uri}
</Link>
</span>
));
rows.push({
key: 'preview_video_uris',
label: <Trans>Preview video uris</Trans>,
value,
metadata.preview_video_uris.forEach((uri: string, i: number) => {
if (uri) {
const index = i + 1;
rows.push({
key: `preview-video-uris-${i}`,
label: <Trans>Preview video URL {index}</Trans>,
value: (
<Tooltip title={uri} copyToClipboard>
<Typography variant="body2">{uri}</Typography>
</Tooltip>
),
});
}
});
}

Expand Down
22 changes: 1 addition & 21 deletions packages/gui/src/components/nfts/NFTProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useTheme } from '@mui/material/styles';
import React, { useMemo } from 'react';
import styled from 'styled-components';

import useOpenUnsafeLink from '../../hooks/useOpenUnsafeLink';
import isRankingAttribute from '../../util/isRankingAttribute';

/* ========================================================================== */
Expand Down Expand Up @@ -34,7 +33,6 @@ export type NFTPropertiesProps = {

export function NFTProperty(props: NFTPropertyProps) {
const { attribute, size = 'regular', color = 'secondary' } = props;
const openUnsafeLink = useOpenUnsafeLink();
const theme = useTheme();
// eslint-disable-next-line @typescript-eslint/naming-convention -- Comes from API like this
const { name, trait_type, value: rawValue } = attribute;
Expand All @@ -50,24 +48,6 @@ export function NFTProperty(props: NFTPropertyProps) {
p: size === 'small' ? 1 : 2,
};

function renderValueWithUrls(val: string) {
const urlRegex = /(https?:\/\/[^\s]+)/g;
const matches = val.split(urlRegex);
if (matches.length > 1) {
return matches.map((match, index) => {
if (index % 2 === 1) {
return (
<span style={{ cursor: 'pointer', textDecoration: 'underline' }} onClick={() => openUnsafeLink(match)}>
{match}
</span>
);
}
return match !== '' ? <span>{match}</span> : null;
});
}
return val;
}

return (
<Grid xs={12} sm={6} item>
<Box {...borderStyle}>
Expand All @@ -93,7 +73,7 @@ export function NFTProperty(props: NFTPropertyProps) {
}
>
<Typography variant={size === 'small' ? 'body2' : 'h6'} color={color} noWrap>
{renderValueWithUrls(value)}
{value}
</Typography>
</Tooltip>
</Box>
Expand Down
10 changes: 8 additions & 2 deletions packages/gui/src/hooks/useOpenExternal.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import isElectron from 'is-electron';
import { useCallback } from 'react';
import isURL from 'validator/es/lib/isURL';

export default function useOpenExternal(): (url: string) => void {
function handleOpen(url: string) {
const handleOpen = useCallback((url: string) => {
if (!isURL(url, { protocols: ['http', 'https', 'ipfs'], require_protocol: true })) {
return;
}

if (isElectron()) {
// @ts-ignore
window.shell.openExternal(url);
return;
}

window.open(url, '_blank');
}
}, []);

return handleOpen;
}
Loading