add pulling avatar from IPFS

This commit is contained in:
Barry Gitarts 2019-04-04 11:24:33 -04:00 committed by Barry G
parent 83dc09f9ba
commit 99a57c8b92
1 changed files with 18 additions and 1 deletions

View File

@ -153,6 +153,13 @@ const formatMedia = content => {
return src return src
} }
const formatAvatar = content => {
const type = 'image/gif'
const blob = new Blob([content], {type})
const src = URL.createObjectURL(blob)
return src
}
const getMediaType = assets => { const getMediaType = assets => {
if (!assets) return false if (!assets) return false
const { media } = getProjectManifest(assets) const { media } = getProjectManifest(assets)
@ -173,6 +180,15 @@ const getMediaSrc = assets => {
} }
} }
const getAvatarSrc = assets => {
if (!assets) return null
const { avatar } = getProjectManifest(assets)
if (avatar.includes('http')) return avatar
return formatAvatar(
assets.find(a => a.name === getFile(avatar)).content
)
}
function Project({ classes, match, profile, transfers, pledges, projectAddedEvents }) { function Project({ classes, match, profile, transfers, pledges, projectAddedEvents }) {
const projectId = match.params.id const projectId = match.params.id
const { projectAge, projectAssets, manifest } = useProjectData(projectId, profile, projectAddedEvents) const { projectAge, projectAssets, manifest } = useProjectData(projectId, profile, projectAddedEvents)
@ -181,6 +197,7 @@ function Project({ classes, match, profile, transfers, pledges, projectAddedEven
const numberOfBackers = useMemo(() => getNumberOfBackers(pledges), [pledges]) const numberOfBackers = useMemo(() => getNumberOfBackers(pledges), [pledges])
const mediaType = useMemo(() => getMediaType(projectAssets), [projectAssets]) const mediaType = useMemo(() => getMediaType(projectAssets), [projectAssets])
const mediaUrl = useMemo(() => getMediaSrc(projectAssets), [projectAssets]) const mediaUrl = useMemo(() => getMediaSrc(projectAssets), [projectAssets])
const avatarUrl = useMemo(() => getAvatarSrc(projectAssets), [projectAssets])
const totalPledged = amountsPledged[0] ? amountsPledged[0][1] : 0 const totalPledged = amountsPledged[0] ? amountsPledged[0][1] : 0
const percentToGoal = manifest ? Math.min( const percentToGoal = manifest ? Math.min(
(Number(totalPledged) / Number(manifest.goal)) * 100, (Number(totalPledged) / Number(manifest.goal)) * 100,
@ -193,7 +210,7 @@ function Project({ classes, match, profile, transfers, pledges, projectAddedEven
: :
<div className={classes.root}> <div className={classes.root}>
<div className={classes.creator}> <div className={classes.creator}>
<Avatar src={manifest && manifest.avatar} /> <Avatar src={manifest && avatarUrl} />
<Typography className={classes.creatorName}>{manifest && `By ${manifest.creator}`}</Typography> <Typography className={classes.creatorName}>{manifest && `By ${manifest.creator}`}</Typography>
</div> </div>
<div> <div>