use fragment to update cache instead of direct write
This commit is contained in:
parent
69bf7a2b45
commit
36fe68fb86
|
@ -18,7 +18,7 @@ import { toBN } from '../../utils/conversions'
|
|||
import { getTokenLabel, getTokenByAddress } from '../../utils/currencies'
|
||||
import MediaView from '../base/MediaView'
|
||||
import StatusTextField from '../base/TextField'
|
||||
import { getProfileById } from './queries'
|
||||
import { getProfileById, pledgeLifetimeReceived } from './queries'
|
||||
import styles from './styles/FundProject'
|
||||
import Loading from '../base/Loading'
|
||||
import BreadCrumb from '../base/BreadCrumb'
|
||||
|
@ -36,8 +36,17 @@ const addProjectSucessMsg = response => {
|
|||
return `Project created with ID of ${idProject}, will redirect to your new project page in a few seconds`
|
||||
}
|
||||
const optimisticUpdate = (client, pledgesInfo, weiAmount) => {
|
||||
const { __typename } = pledgesInfo
|
||||
const updatedLifetimeReceived = toBN(weiAmount).add(toBN(pledgesInfo.lifetimeReceived)).toString()
|
||||
client.writeData({ data: { [`PledgesInfo:${pledgesInfo.id}`]: {...pledgesInfo, lifetimeReceived: updatedLifetimeReceived } } })
|
||||
const id = `${__typename}:${pledgesInfo.id}`
|
||||
client.writeFragment({
|
||||
id,
|
||||
fragment: pledgeLifetimeReceived,
|
||||
data: {
|
||||
lifetimeReceived: updatedLifetimeReceived,
|
||||
__typename
|
||||
}
|
||||
})
|
||||
}
|
||||
const SubmissionSection = ({ classes, projectData, projectId, profileData, startPolling, client }) => {
|
||||
const { account, enableEthereum, openSnackBar, prices } = useContext(FundingContext)
|
||||
|
@ -78,7 +87,7 @@ const SubmissionSection = ({ classes, projectData, projectId, profileData, start
|
|||
openSnackBar('success', 'Funding Confirmed')
|
||||
})
|
||||
.catch(e => {
|
||||
openSnackBar('error', 'An error has occured with the transaction')
|
||||
openSnackBar('error', 'An error has occured')
|
||||
console.log({e})
|
||||
})
|
||||
.finally(() => {
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
import { gql } from 'apollo-boost'
|
||||
|
||||
export const pledgeLifetimeReceived = gql`
|
||||
fragment PledgeLifetimeReceived on PledgesInfo {
|
||||
lifetimeReceived
|
||||
}
|
||||
`
|
||||
export const pledgesInfosFields = gql`
|
||||
${pledgeLifetimeReceived}
|
||||
fragment PledgesInfoFields on PledgesInfo {
|
||||
id
|
||||
...PledgeLifetimeReceived
|
||||
token
|
||||
}
|
||||
`
|
||||
|
||||
export const getProfileById = gql`
|
||||
${pledgesInfosFields}
|
||||
|
||||
query Profile($id: ID!) {
|
||||
profile(id: $id) {
|
||||
id
|
||||
|
@ -12,10 +28,7 @@ query Profile($id: ID!) {
|
|||
name
|
||||
creationTime
|
||||
pledgesInfos {
|
||||
id
|
||||
token
|
||||
lifetimeReceived
|
||||
balance
|
||||
...PledgesInfoFields
|
||||
}
|
||||
projectInfo {
|
||||
id
|
||||
|
@ -36,6 +49,8 @@ query Profile($id: ID!) {
|
|||
}
|
||||
`
|
||||
export const getProjects = gql`
|
||||
${pledgesInfosFields}
|
||||
|
||||
query Projects($type: String! = "PROJECT"){
|
||||
profiles(first: 5, where: {type: $type, projectInfo_not: null}) {
|
||||
id
|
||||
|
@ -55,9 +70,7 @@ query Projects($type: String! = "PROJECT"){
|
|||
goal
|
||||
}
|
||||
pledgesInfos{
|
||||
id
|
||||
lifetimeReceived
|
||||
token
|
||||
...PledgesInfoFields
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue