This commit is contained in:
zeppi 2021-10-13 09:30:50 -04:00 committed by jessopb
parent 1981f16715
commit 6c3ed54d87
9 changed files with 18 additions and 29 deletions

View file

@ -5,7 +5,7 @@ import { NavLink, withRouter } from 'react-router-dom';
import { isEmpty } from 'util/object';
import { lazyImport } from 'util/lazyImport';
import classnames from 'classnames';
import { parseURI, isURIEqual } from 'util/lbryURI';
import { isURIEqual, isURIValid } from 'util/lbryURI';
import * as COLLECTIONS_CONSTS from 'constants/collections';
import { formatLbryUrlForWeb } from 'util/url';
import { formatClaimPreviewTitle } from 'util/formatAriaLabel';
@ -180,15 +180,8 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
</span>
);
}, [channelSubCount]);
let isValid = false;
if (uri) {
try {
parseURI(uri);
isValid = true;
} catch (e) {
isValid = false;
}
}
const isValid = uri && isURIValid(uri);
// $FlowFixMe
const isPlayable =
claim &&

View file

@ -8,6 +8,7 @@ import usePrevious from 'effects/use-previous';
type SearchOptions = {
page_size: number,
page: number,
no_totals: boolean,
any_tags: Array<string>,
channel_ids: Array<string>,

View file

@ -249,7 +249,7 @@ function CollectionForm(props: Props) {
let nameError;
if (!name && name !== undefined) {
nameError = __('A name is required for your url');
} else if (!isNameValid(name, false)) {
} else if (!isNameValid(name)) {
nameError = INVALID_NAME_ERROR;
}

View file

@ -94,7 +94,7 @@ function CommentMenuList(props: Props) {
function assignAsModerator() {
if (activeChannelClaim && authorUri) {
const { channelName, channelClaimId } = parseURI(authorUri);
commentModAddDelegate(channelClaimId, channelName, activeChannelClaim);
if (channelName && channelClaimId) commentModAddDelegate(channelClaimId, channelName, activeChannelClaim);
}
}

View file

@ -14,8 +14,9 @@ type Props = {
export default function NotificationContentChannelMenu(props: Props) {
const { uri, notificationsDisabled, doToast, doChannelSubscribe } = props;
const { claimName } = parseURI(uri);
let claimName;
const { claimName: name } = parseURI(uri);
claimName = name || '';
function handleClick() {
doChannelSubscribe({
uri,

View file

@ -43,7 +43,7 @@ function PublishFormErrors(props: Props) {
{waitForFile && <div>{__('Choose a replay file, or select None')}</div>}
{!title && <div>{__('A title is required')}</div>}
{!name && <div>{__('A URL is required')}</div>}
{!isNameValid(name, false) && INVALID_NAME_ERROR}
{name && !isNameValid(name) && INVALID_NAME_ERROR}
{!bid && <div>{__('A deposit amount is required')}</div>}
{bidError && <div>{__('Please check your deposit amount.')}</div>}
{isUploadingThumbnail && <div>{__('Please wait for thumbnail to finish uploading')}</div>}

View file

@ -165,7 +165,7 @@ function RepostCreate(props: Props) {
let repostNameError;
if (!enteredRepostName) {
repostNameError = __('A name is required');
} else if (!isNameValid(enteredRepostName, false)) {
} else if (!isNameValid(enteredRepostName)) {
repostNameError = INVALID_NAME_ERROR;
} else if (!available) {
repostNameError = __('You already have a claim with this name.');
@ -178,7 +178,7 @@ function RepostCreate(props: Props) {
}
React.useEffect(() => {
if (enteredRepostName && isNameValid(enteredRepostName, false)) {
if (enteredRepostName && isNameValid(enteredRepostName)) {
doCheckPublishNameAvailability(enteredRepostName).then((r) => setAvailable(r));
}
}, [enteredRepostName, doCheckPublishNameAvailability]);
@ -262,14 +262,14 @@ function RepostCreate(props: Props) {
} else if (entered) {
try {
const { claimName } = parseURI(entered);
return `/${claimName}`;
return claimName ? `/${claimName}` : '/';
} catch (e) {
return '/';
}
} else if (passed) {
try {
const { claimName } = parseURI(passed);
return `/${claimName}`;
return claimName ? `/${claimName}` : '/';
} catch (e) {
return '/';
}

View file

@ -605,7 +605,7 @@ export function doFetchCollectionListMine(page: number = 1, pageSize: number = 9
export function doClaimSearch(
options: {
page_size: number,
page_size?: number,
page: number,
no_totals?: boolean,
any_tags?: Array<string>,

View file

@ -1,5 +1,5 @@
// @flow
import { normalizeURI, parseURI } from 'util/lbryURI';
import { normalizeURI, parseURI, isURIValid } from 'util/lbryURI';
import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
import { createSelector } from 'reselect';
import { isClaimNsfw, filterClaims } from 'util/claim';
@ -76,11 +76,7 @@ export const makeSelectClaimForClaimId = (claimId: string) => createSelector(sel
export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) =>
createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => {
let validUri;
try {
parseURI(uri);
validUri = true;
} catch (e) {}
const validUri = isURIValid(uri);
if (validUri && byUri) {
const claimId = uri && byUri[normalizeURI(uri)];
@ -154,9 +150,7 @@ export const makeSelectClaimIsMine = (rawUri: string) => {
} catch (e) {}
return createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => {
try {
parseURI(uri);
} catch (e) {
if (!isURIValid(uri)) {
return false;
}