getProjectAssets from ipfs
This commit is contained in:
parent
3f96c39dbf
commit
ad4e4b3799
|
@ -137,6 +137,7 @@ const AddFunder = ({ appendFundProfile }) => (
|
|||
<input
|
||||
ref={(input) => { uploadInput = input }}
|
||||
type="file"
|
||||
multiple
|
||||
onChange={
|
||||
(e) => captureFile(
|
||||
e,
|
||||
|
@ -181,14 +182,14 @@ const AddFunder = ({ appendFundProfile }) => (
|
|||
{`ADD ${buttonLabel[values.adminType]} PROFILE`}
|
||||
</Button>
|
||||
{status && status.snackbar && <Snackbar
|
||||
anchorOrigin={{
|
||||
vertical: 'bottom',
|
||||
horizontal: 'left',
|
||||
}}
|
||||
open={!!status.snackbar}
|
||||
autoHideDuration={6000}
|
||||
onClose={() => setStatus(null)}
|
||||
>
|
||||
anchorOrigin={{
|
||||
vertical: 'bottom',
|
||||
horizontal: 'left',
|
||||
}}
|
||||
open={!!status.snackbar}
|
||||
autoHideDuration={6000}
|
||||
onClose={() => setStatus(null)}
|
||||
>
|
||||
<MySnackbarContentWrapper
|
||||
onClose={() => setStatus(null)}
|
||||
variant={status.snackbar.variant}
|
||||
|
|
|
@ -19,6 +19,7 @@ import PropTypes from 'prop-types'
|
|||
import { toEther } from '../../utils/conversions'
|
||||
import { getTokenLabel } from '../../utils/currencies'
|
||||
import { timeSinceBlock } from '../../utils/dates'
|
||||
import { getFiles } from '../../utils/ipfs'
|
||||
|
||||
const styles = theme => ({
|
||||
root: {
|
||||
|
@ -129,17 +130,34 @@ async function getProjectAge(id, events, setState){
|
|||
setState(timeSinceBlock(timestamp, 'days'))
|
||||
}
|
||||
|
||||
async function getProjectAssets(hash, setState){
|
||||
getFiles(hash)
|
||||
.then((files) => {
|
||||
setState(files)
|
||||
const manifest = files[2]
|
||||
console.log({files}, JSON.parse(manifest.content))
|
||||
})
|
||||
.catch(console.log)
|
||||
}
|
||||
|
||||
function Project({ classes, match, profile, transfers, pledges, projectAddedEvents }) {
|
||||
const projectId = match.params.id
|
||||
const [projectAge, setAge] = useState(null)
|
||||
const [projectAssets, setAssets] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
getProjectAge(projectId, projectAddedEvents, setAge)
|
||||
})
|
||||
}, [projectAge])
|
||||
|
||||
useEffect(() => {
|
||||
getProjectAssets('QmZbFULchk4wKdYoHv13jkTs2Wf4NYYJ38aCFG97g97DNn', setAssets)
|
||||
}, [])
|
||||
|
||||
const received = useMemo(() => getReceivedAmount(projectId, transfers), [projectId, transfers])
|
||||
const withdrawn = useMemo(() => getWithdrawnAmount(projectId, transfers), [projectId, transfers])
|
||||
const amountsPledged = useMemo(() => getAmountsPledged(pledges), [pledges])
|
||||
const numberOfBackers = useMemo(() => getNumberOfBackers(pledges), [pledges])
|
||||
console.log({profile, projectAssets})
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<div className={classes.creator}>
|
||||
|
|
|
@ -11,20 +11,31 @@ export const captureFile = (event, cb, imgCb) => {
|
|||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
const file = event.target.files[0]
|
||||
saveToIpfs(file, cb, imgCb)
|
||||
const files = event.target.files
|
||||
const formattedFiles = formatFileList(files)
|
||||
console.log({files, formattedFiles})
|
||||
saveToIpfs(formattedFiles, cb, imgCb)
|
||||
}
|
||||
|
||||
const formatFileList = files => {
|
||||
const formattedList = []
|
||||
for (let i=0; i<files.length; i++) {
|
||||
formattedList.push(formatForIpfs(files[i]))
|
||||
}
|
||||
return formattedList
|
||||
}
|
||||
|
||||
const formatForIpfs = file => {
|
||||
const { name, type } = file
|
||||
const content = fileReaderPullStream(file)
|
||||
return [{
|
||||
return {
|
||||
path: `/root/${name}`,
|
||||
content
|
||||
}]
|
||||
}
|
||||
}
|
||||
const saveToIpfs = (file, cb, imgCb) => {
|
||||
const saveToIpfs = (files, cb, imgCb) => {
|
||||
let ipfsId
|
||||
ipfs.add(formatForIpfs(file), { progress: (prog) => console.log(`received: ${prog}`) })
|
||||
ipfs.add(files, { progress: (prog) => console.log(`received: ${prog}`) })
|
||||
.then((response) => {
|
||||
console.log(response)
|
||||
ipfsId = response[0].hash
|
||||
|
@ -41,7 +52,7 @@ export const getImageFromIpfs = async (hash, cb) => {
|
|||
};
|
||||
|
||||
export const getFromIpfs = async hash => {
|
||||
const files = await getFile(hash)
|
||||
const files = await getFiles(hash)
|
||||
const file = files.slice(-1)[0]
|
||||
const { content } = file
|
||||
const arrayBufferView = new Uint8Array(content)
|
||||
|
@ -50,7 +61,7 @@ export const getFromIpfs = async hash => {
|
|||
return { ...file, img }
|
||||
}
|
||||
|
||||
export const getFile = CID => {
|
||||
export const getFiles = CID => {
|
||||
const clean = CID.split('/').slice(-1)[0]
|
||||
return new Promise(function(resolve, reject) {
|
||||
ipfs.get(clean, function (err, files) {
|
||||
|
|
Loading…
Reference in New Issue