Merge pull request #25 from status-im/fix/projects-page

Fix projects page error
This commit is contained in:
Iuri Matias 2019-05-03 16:40:00 -04:00 committed by GitHub
commit 41a5826632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import CloudUpload from '@material-ui/icons/CloudUpload'
import { MySnackbarContentWrapper } from './base/SnackBars' import { MySnackbarContentWrapper } from './base/SnackBars'
import { captureFile } from '../utils/ipfs' import { captureFile } from '../utils/ipfs'
import ImageViewer from './image/ImageViewer' import ImageViewer from './image/ImageViewer'
import {ZERO_ADDRESS} from '../utils/address'
const { addGiver, addDelegate, addProject } = LiquidPledging.methods const { addGiver, addDelegate, addProject } = LiquidPledging.methods
const FUNDER = 'FUNDER' const FUNDER = 'FUNDER'
@ -60,7 +61,7 @@ const AddFunder = ({ appendFundProfile }) => (
const { adminType, funderName, funderDescription, commitTime } = values const { adminType, funderName, funderDescription, commitTime } = values
const account = await web3.eth.getCoinbase() const account = await web3.eth.getCoinbase()
//TODO add field for parent project //TODO add field for parent project
const args = adminType === PROJECT ? [funderName, funderDescription, account, 0, hoursToSeconds(commitTime), 0] : [funderName, funderDescription, hoursToSeconds(commitTime), 0] const args = adminType === PROJECT ? [funderName, funderDescription, account, 0, hoursToSeconds(commitTime), 0] : [funderName, funderDescription, hoursToSeconds(commitTime), ZERO_ADDRESS]
const isFunder = adminType === FUNDER const isFunder = adminType === FUNDER
const sendFn = sendFns[adminType] const sendFn = sendFns[adminType]
sendFn(...args) sendFn(...args)

View File

@ -123,8 +123,8 @@ const SubmissionSection = ({ classes, profiles, delegatePledges, projectId, open
disabled={!profiles || profiles.length === 0} disabled={!profiles || profiles.length === 0}
value={values.delegateProfile || ''} value={values.delegateProfile || ''}
> >
{profiles && profiles.map(profile => ( {profiles && profiles.map((profile, index) => (
<MenuItem style={{display: 'flex', alignItems: 'center'}} key={profile.name} value={profile}> <MenuItem style={{display: 'flex', alignItems: 'center'}} key={`profile-${index}`} value={profile}>
{profile.name} {profile.name}
</MenuItem> </MenuItem>
))} ))}

View File

@ -12,11 +12,11 @@ import CloudUpload from '@material-ui/icons/CloudUpload'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import { formatForIpfs, uploadToIpfs, formatMedia, isWeb } from '../../utils/ipfs' import { formatForIpfs, uploadToIpfs, formatMedia, isWeb } from '../../utils/ipfs'
import { FundingContext } from '../../context' import { FundingContext } from '../../context'
import {ZERO_ADDRESS} from '../../utils/address'
const { addProject } = LiquidPledging.methods const { addProject } = LiquidPledging.methods
const zeroAddress = '0x0000000000000000000000000000000000000000'
const hoursToSeconds = hours => hours * 60 * 60 const hoursToSeconds = hours => hours * 60 * 60
const helperText = 'The length of time the Project has to veto when the project delegates to another delegate and they pledge those funds to a project' const helperText = 'The length of time the Project has to veto when the project delegates to another delegate and they pledge those funds to a project'
@ -144,7 +144,7 @@ const SubmissionSection = ({ classes, history }) => {
path: '/root/manifest.json', content: Buffer.from(manifest) path: '/root/manifest.json', content: Buffer.from(manifest)
}) })
const contentHash = await uploadToIpfs(fileLists) const contentHash = await uploadToIpfs(fileLists)
const args = [title, contentHash, account, 0, hoursToSeconds(commitTime), zeroAddress] const args = [title, contentHash, account, 0, hoursToSeconds(commitTime), ZERO_ADDRESS]
addProject(...args) addProject(...args)
.estimateGas({ from: account }) .estimateGas({ from: account })
.then(async gas => { .then(async gas => {

View File

@ -62,6 +62,9 @@ async function fetchAndAddDelegateProfiles(account, setState) {
async function fetchAndAddDelegatePledges(profiles, setState) { async function fetchAndAddDelegatePledges(profiles, setState) {
const dPledges = [] const dPledges = []
if (!profiles || !profiles.length) {
return setState(dPledges)
}
profiles.forEach(profile => { profiles.forEach(profile => {
const delegatePledges = getDelegatePledgesByProfile(profile) const delegatePledges = getDelegatePledgesByProfile(profile)
dPledges.push(delegatePledges) dPledges.push(delegatePledges)
@ -82,7 +85,18 @@ export function useProfileData(profiles) {
} }
const getProjectManifest = assets => { const getProjectManifest = assets => {
return assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null if (!assets) {
return null;
}
const manifest = assets.find(a => a.name.toLowerCase() === 'manifest.json');
if (!manifest) {
return null;
}
try {
return JSON.parse(manifest.content)
} catch (e) {
return null;
}
} }
export function useProjectData(projectId, profile, projectAddedEvents) { export function useProjectData(projectId, profile, projectAddedEvents) {

View File

@ -75,6 +75,11 @@ class App extends React.Component {
this.setState({ snackbar: null }) this.setState({ snackbar: null })
} }
appendPledges = () => {
// TODO check if this is correct
getAndAddPledges()
}
render() { render() {
const { account, needsInit, lpAllowance: _lpAllowance, loading, authorizedPayments, snackbar } = this.state const { account, needsInit, lpAllowance: _lpAllowance, loading, authorizedPayments, snackbar } = this.state
const { appendFundProfile, appendPledges, transferPledgeAmounts, openSnackBar, closeSnackBar } = this const { appendFundProfile, appendPledges, transferPledgeAmounts, openSnackBar, closeSnackBar } = this

1
src/utils/address.js Normal file
View File

@ -0,0 +1 @@
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'