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; } = props;
const haventFetched = claim === undefined; const haventFetched = claim === undefined;
const abandoned = !isResolvingUri && !claim && !placeholder; const abandoned = !isResolvingUri && !claim && !placeholder;
const { isChannel } = parseURI(uri);
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0; 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); let shouldHide = abandoned || (!claimIsMine && obscureNsfw && nsfw);
// This will be replaced once blocking is done at the wallet server level // This will be replaced once blocking is done at the wallet server level
@ -90,7 +97,7 @@ function ClaimPreview(props: Props) {
} }
useEffect(() => { useEffect(() => {
if (!isResolvingUri && haventFetched && uri) { if (isValid && !isResolvingUri && haventFetched && uri) {
resolveUri(uri); resolveUri(uri);
} }
}, [isResolvingUri, uri, resolveUri, haventFetched]); }, [isResolvingUri, uri, resolveUri, haventFetched]);
@ -118,7 +125,7 @@ function ClaimPreview(props: Props) {
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className={classnames('claim-preview', { className={classnames('claim-preview', {
'claim-preview--large': type === 'large', 'claim-preview--large': type === 'large',
'claim-preview--visited': hasVisitedUri, 'claim-preview--visited': !isChannel && hasVisitedUri,
'claim-preview--pending': pending, '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; const { amount, claim_id: claimId, claim_name: name, date, fee, txid, type } = transaction;
// Ensure the claim name exists and is valid // Ensure the claim name exists and is valid
let uri;
let claimName = name; let claimName = name;
if (claimName) { try {
({ claimName } = parseURI(name)); ({ claimName } = parseURI(name));
} uri = buildURI({ claimName: claimName, claimId });
} catch (e) {}
const dateFormat = { const dateFormat = {
month: 'short', month: 'short',
@ -72,9 +74,7 @@ class TransactionListItem extends React.PureComponent<Props> {
</td> </td>
<td className="table__item--actionable"> <td className="table__item--actionable">
{reward && <span>{reward.reward_title}</span>} {reward && <span>{reward.reward_title}</span>}
{claimName && claimId && ( {uri ? <Button button="link" navigate={uri} label={claimName} /> : claimName}
<Button button="link" navigate={buildURI({ claimName: claimName, claimId })} label={claimName} />
)}
</td> </td>
<td> <td>

View file

@ -6646,9 +6646,9 @@ lazy-val@^1.0.3, lazy-val@^1.0.4:
yargs "^13.2.2" yargs "^13.2.2"
zstd-codec "^0.1.1" zstd-codec "^0.1.1"
lbry-redux@lbryio/lbry-redux#15e36688fb762b0b424a837de0f5a405b05463a2: lbry-redux@lbryio/lbry-redux#87e01209f56cb3326c12ffc114072c48f72c1a3e:
version "0.0.1" 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: dependencies:
proxy-polyfill "0.1.6" proxy-polyfill "0.1.6"
reselect "^3.0.0" reselect "^3.0.0"