mirror of
https://github.com/status-im/liquid-funding.git
synced 2025-02-16 21:36:46 +00:00
add global snackbar and connect to back project
This commit is contained in:
parent
165bbe9d50
commit
9b0594533f
@ -1,7 +1,5 @@
|
|||||||
import React, { useContext, useState, useEffect } from 'react';
|
import React, { useContext, useState, useEffect } from 'react';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import EmbarkJS from 'Embark/EmbarkJS';
|
|
||||||
import LPVault from 'Embark/contracts/LPVault';
|
|
||||||
import LiquidPledging from 'Embark/contracts/LiquidPledging';
|
import LiquidPledging from 'Embark/contracts/LiquidPledging';
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button';
|
||||||
import TextField from '@material-ui/core/TextField';
|
import TextField from '@material-ui/core/TextField';
|
||||||
|
@ -52,7 +52,7 @@ const Title = ({ className, manifest }) => (
|
|||||||
<Divider />
|
<Divider />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
const SubmissionSection = ({ classes, profiles, delegatePledges, projectId }) => {
|
const SubmissionSection = ({ classes, profiles, delegatePledges, projectId, openSnackBar }) => {
|
||||||
return (
|
return (
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{ amount: '', delegateProfile: '', delegatePledge: '' }}
|
initialValues={{ amount: '', delegateProfile: '', delegatePledge: '' }}
|
||||||
@ -79,9 +79,11 @@ const SubmissionSection = ({ classes, profiles, delegatePledges, projectId }) =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
|
openSnackBar('error', e)
|
||||||
console.log({e})
|
console.log({e})
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
openSnackBar('success', 'project backed!')
|
||||||
resetForm()
|
resetForm()
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
@ -164,14 +166,20 @@ const SubmissionSection = ({ classes, profiles, delegatePledges, projectId }) =>
|
|||||||
|
|
||||||
function BackProject({classes, match, profile, delegates, projectAddedEvents, delegateAddedEvents}) {
|
function BackProject({classes, match, profile, delegates, projectAddedEvents, delegateAddedEvents}) {
|
||||||
const projectId = match.params.id
|
const projectId = match.params.id
|
||||||
const { projectAge, projectAssets, manifest, delegateProfiles } = useProjectData(projectId, profile, projectAddedEvents)
|
const { projectAge, projectAssets, manifest, delegateProfiles, openSnackBar } = useProjectData(projectId, profile, projectAddedEvents)
|
||||||
const delegatePledges = useProfileData(delegateProfiles)
|
const delegatePledges = useProfileData(delegateProfiles)
|
||||||
const delegateProfilesArr = delegates.map(d => d.profile.fetch())
|
const delegateProfilesArr = delegates.map(d => d.profile.fetch())
|
||||||
console.log({delegateAddedEvents, profile, delegates, delegateProfilesArr, delegateProfiles}, profile[0].delegates.fetch())
|
console.log({delegateAddedEvents, profile, delegates, delegateProfilesArr, delegateProfiles}, profile[0].delegates.fetch())
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Title className={classes.title} manifest={manifest} />
|
<Title className={classes.title} manifest={manifest} />
|
||||||
<SubmissionSection classes={classes} profiles={delegateProfiles} delegatePledges={delegatePledges} projectId={projectId} />
|
<SubmissionSection
|
||||||
|
classes={classes}
|
||||||
|
profiles={delegateProfiles}
|
||||||
|
delegatePledges={delegatePledges}
|
||||||
|
projectId={projectId}
|
||||||
|
openSnackBar={openSnackBar}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ export function useProjectData(projectId, profile, projectAddedEvents) {
|
|||||||
const [projectAssets, setAssets] = useState(null)
|
const [projectAssets, setAssets] = useState(null)
|
||||||
const [ipfsReady, setIpfsState] = useState(null)
|
const [ipfsReady, setIpfsState] = useState(null)
|
||||||
const [delegateProfiles, setDelegateProfiles] = useState(null)
|
const [delegateProfiles, setDelegateProfiles] = useState(null)
|
||||||
const { account } = useContext(FundingContext)
|
const { account, openSnackBar } = useContext(FundingContext)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ipfs.on('ready', () => { setIpfsState(true) })
|
ipfs.on('ready', () => { setIpfsState(true) })
|
||||||
@ -104,5 +104,11 @@ export function useProjectData(projectId, profile, projectAddedEvents) {
|
|||||||
|
|
||||||
const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets])
|
const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets])
|
||||||
|
|
||||||
return { projectAge, projectAssets, manifest, delegateProfiles }
|
return {
|
||||||
|
projectAge,
|
||||||
|
projectAssets,
|
||||||
|
manifest,
|
||||||
|
delegateProfiles,
|
||||||
|
openSnackBar
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
30
app/dapp.js
30
app/dapp.js
@ -3,6 +3,7 @@ import { HashRouter as Router } from 'react-router-dom'
|
|||||||
import EmbarkJS from 'Embark/EmbarkJS'
|
import EmbarkJS from 'Embark/EmbarkJS'
|
||||||
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
||||||
import web3 from 'Embark/web3'
|
import web3 from 'Embark/web3'
|
||||||
|
import Snackbar from '@material-ui/core/Snackbar'
|
||||||
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
|
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
|
||||||
import { getAuthorizedPayments } from './utils/events'
|
import { getAuthorizedPayments } from './utils/events'
|
||||||
import { FundingContext } from './context'
|
import { FundingContext } from './context'
|
||||||
@ -12,6 +13,7 @@ import { getAndAddVaultEvents } from './actions/vaultEvents'
|
|||||||
import { addFormattedProfiles } from './actions/profiles'
|
import { addFormattedProfiles } from './actions/profiles'
|
||||||
import { updateStalePledges, getAndAddPledges } from './actions/pledges'
|
import { updateStalePledges, getAndAddPledges } from './actions/pledges'
|
||||||
import { updateDelegates } from './actions/delegates'
|
import { updateDelegates } from './actions/delegates'
|
||||||
|
import { MySnackbarContentWrapper } from './components/base/SnackBars'
|
||||||
|
|
||||||
const { getNetworkType } = web3.eth.net
|
const { getNetworkType } = web3.eth.net
|
||||||
|
|
||||||
@ -62,15 +64,37 @@ class App extends React.Component {
|
|||||||
this.setState({ loading: false })
|
this.setState({ loading: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openSnackBar = (variant, message) => {
|
||||||
|
this.setState({ snackbar: { variant, message } })
|
||||||
|
}
|
||||||
|
|
||||||
|
closeSnackBar = () => {
|
||||||
|
this.setState({ snackbar: null })
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { account, needsInit, lpAllowance, loading, authorizedPayments } = this.state
|
const { account, needsInit, lpAllowance, loading, authorizedPayments, snackbar } = this.state
|
||||||
const { appendFundProfile, appendPledges, transferPledgeAmounts } = this
|
const { appendFundProfile, appendPledges, transferPledgeAmounts, openSnackBar, closeSnackBar } = this
|
||||||
const fundingContext = { appendPledges, appendFundProfile, account, transferPledgeAmounts, authorizedPayments, needsInit, initVaultAndLP, standardTokenApproval }
|
const fundingContext = { appendPledges, appendFundProfile, account, transferPledgeAmounts, authorizedPayments, needsInit, initVaultAndLP, standardTokenApproval, openSnackBar, closeSnackBar }
|
||||||
return (
|
return (
|
||||||
<FundingContext.Provider value={fundingContext}>
|
<FundingContext.Provider value={fundingContext}>
|
||||||
<Router>
|
<Router>
|
||||||
<MainCointainer loading={loading} />
|
<MainCointainer loading={loading} />
|
||||||
</Router>
|
</Router>
|
||||||
|
{snackbar && <Snackbar
|
||||||
|
anchorOrigin={{
|
||||||
|
vertical: 'bottom',
|
||||||
|
horizontal: 'center',
|
||||||
|
}}
|
||||||
|
open={snackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
onClose={closeSnackBar}
|
||||||
|
>
|
||||||
|
<MySnackbarContentWrapper
|
||||||
|
variant={snackbar && snackbar.variant}
|
||||||
|
message={snackbar && snackbar.message}
|
||||||
|
/>
|
||||||
|
</Snackbar>}
|
||||||
</FundingContext.Provider>
|
</FundingContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user