From 396bde9ecf229574ae70f9a85720e9906c4e7166 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Tue, 30 Jul 2019 13:50:31 -0400 Subject: [PATCH] explicitly pin to gateway --- src/components/projects/CreateProject.jsx | 7 ++++--- src/utils/ipfs.js | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/projects/CreateProject.jsx b/src/components/projects/CreateProject.jsx index 4966e96..4b3de7f 100644 --- a/src/components/projects/CreateProject.jsx +++ b/src/components/projects/CreateProject.jsx @@ -8,7 +8,7 @@ import Switch from '@material-ui/core/Switch' import Button from '@material-ui/core/Button' import InputAdornment from '@material-ui/core/InputAdornment' import { withStyles } from '@material-ui/core/styles' -import { uploadFilesToIpfs, formatMedia, isWeb } from '../../utils/ipfs' +import { uploadFilesToIpfs, pinToGateway, formatMedia, isWeb } from '../../utils/ipfs' import { FundingContext } from '../../context' import {ZERO_ADDRESS} from '../../utils/address' import CurrencySelect from '../base/CurrencySelect' @@ -195,7 +195,7 @@ const SubmissionSection = ({ classes, history }) => { onSubmit={async (values, { resetForm }) => { const { title, commitTime } = values const manifest = createJSON(values) - const contentHash = await uploadFilesToIpfs(uploads, manifest, true) + const contentHash = await uploadFilesToIpfs(uploads, manifest) const args = [title, contentHash, account, 0, hoursToSeconds(commitTime), ZERO_ADDRESS] addProject(...args) .estimateGas({ from: account }) @@ -203,8 +203,9 @@ const SubmissionSection = ({ classes, history }) => { addProject(...args) .send({ from: account, gas: gas + 100 }) .then(res => { - // cache locally + // upload to gateway uploadFilesToIpfs(uploads, manifest, true) + pinToGateway(contentHash) console.log({res}) openSnackBar('success', addProjectSucessMsg(res)) setTimeout(() => { diff --git a/src/utils/ipfs.js b/src/utils/ipfs.js index 3f33821..64c5583 100644 --- a/src/utils/ipfs.js +++ b/src/utils/ipfs.js @@ -98,6 +98,12 @@ export const pinToIpfs = async hash => { console.log({res}) } +export const pinToGateway = async hash => { + const cid = hash.split('/').slice(-1)[0] + const res = await ipfsHttp.pin.add(cid, { recursive: true }) + console.log({res}) +} + export const getImageFromIpfs = async (hash, cb) => { const res = await getFromIpfs(hash) cb(res)