fix: handle claims with invalid names

This commit is contained in:
Sean Yesmunt 2019-07-11 15:03:31 -04:00
parent 75ff0a9cf0
commit 68dd41cbbc
3 changed files with 17 additions and 10 deletions

View file

@ -61,9 +61,16 @@ function ClaimPreview(props: Props) {
} = props;
const haventFetched = claim === undefined;
const abandoned = !isResolvingUri && !claim && !placeholder;
const { isChannel } = parseURI(uri);
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
let isValid;
try {
parseURI(uri);
isValid = true;
} catch (e) {
isValid = false;
}
const isChannel = isValid ? parseURI(uri).isChannel : false;
let shouldHide = abandoned || (!claimIsMine && obscureNsfw && nsfw);
// This will be replaced once blocking is done at the wallet server level
@ -90,7 +97,7 @@ function ClaimPreview(props: Props) {
}
useEffect(() => {
if (!isResolvingUri && haventFetched && uri) {
if (isValid && !isResolvingUri && haventFetched && uri) {
resolveUri(uri);
}
}, [isResolvingUri, uri, resolveUri, haventFetched]);
@ -118,7 +125,7 @@ function ClaimPreview(props: Props) {
onContextMenu={handleContextMenu}
className={classnames('claim-preview', {
'claim-preview--large': type === 'large',
'claim-preview--visited': hasVisitedUri,
'claim-preview--visited': !isChannel && hasVisitedUri,
'claim-preview--pending': pending,
})}
>

View file

@ -44,10 +44,12 @@ class TransactionListItem extends React.PureComponent<Props> {
const { amount, claim_id: claimId, claim_name: name, date, fee, txid, type } = transaction;
// Ensure the claim name exists and is valid
let uri;
let claimName = name;
if (claimName) {
try {
({ claimName } = parseURI(name));
}
uri = buildURI({ claimName: claimName, claimId });
} catch (e) {}
const dateFormat = {
month: 'short',
@ -72,9 +74,7 @@ class TransactionListItem extends React.PureComponent<Props> {
</td>
<td className="table__item--actionable">
{reward && <span>{reward.reward_title}</span>}
{claimName && claimId && (
<Button button="link" navigate={buildURI({ claimName: claimName, claimId })} label={claimName} />
)}
{uri ? <Button button="link" navigate={uri} label={claimName} /> : claimName}
</td>
<td>

View file

@ -6646,9 +6646,9 @@ lazy-val@^1.0.3, lazy-val@^1.0.4:
yargs "^13.2.2"
zstd-codec "^0.1.1"
lbry-redux@lbryio/lbry-redux#15e36688fb762b0b424a837de0f5a405b05463a2:
lbry-redux@lbryio/lbry-redux#87e01209f56cb3326c12ffc114072c48f72c1a3e:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/15e36688fb762b0b424a837de0f5a405b05463a2"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/87e01209f56cb3326c12ffc114072c48f72c1a3e"
dependencies:
proxy-polyfill "0.1.6"
reselect "^3.0.0"