Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calls to Quasar via datastore #1760

Merged
merged 7 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/projects/app/components/Panel/FundIssues/FundIssues.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import BigNumber from 'bignumber.js'
import { useAragonApi } from '../../../api-react'
import useGithubAuth from '../../../hooks/useGithubAuth'
import { usePanelManagement } from '..'
import { computeIpfsString } from '../../../utils/ipfs-helpers'
import { toHex } from 'web3-utils'
import { IconClose } from '@aragon/ui'
import NoFunds from '../../../assets/noFunds.svg'
Expand Down Expand Up @@ -414,7 +413,13 @@ const FundIssues = ({ issues, mode }) => {
})
}

const ipfsAddresses = await computeIpfsString(issuesArray)
const issueHashArray =
await Promise.all(issuesArray.map(async issue => {
const val = new Blob([Buffer.from(JSON.stringify(issue))])
return await api.datastore('add', val).toPromise()
}))

const ipfsAddresses = issueHashArray.join('')
const repoIds = issuesArray.map(issue => toHex(issue.repoId))
const issueNumbers = issuesArray.map(issue => issue.number)
let tokenContracts = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Form, FormField, DateInput } from '../../Form'
import { useAragonApi } from '../../../api-react'
import useGithubAuth from '../../../hooks/useGithubAuth'
import { usePanelManagement } from '..'
import { ipfsAdd } from '../../../utils/ipfs-helpers'
import { toHex } from 'web3-utils'
import { issueShape } from '../../../utils/shapes.js'
import { IssueTitle } from '../PanelComponents'
Expand Down Expand Up @@ -47,7 +46,9 @@ const RequestAssignment = ({ issue }) => {
user: githubCurrentUser,
applicationDate: today.toISOString(),
}
const hash = await ipfsAdd(data)

const val = new Blob([Buffer.from(JSON.stringify(data))])
const hash = await api.datastore('add', val).toPromise()
api.requestAssignment(toHex(issue.repoId), issue.number, hash).toPromise()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import { FormField, FieldTitle } from '../../Form'
import useGithubAuth from '../../../hooks/useGithubAuth'
import { useAragonApi } from '../../../api-react'
import { usePanelManagement } from '../../Panel'
import { ipfsAdd } from '../../../utils/ipfs-helpers'
import { toHex } from 'web3-utils'
import { issueShape } from '../../../utils/shapes.js'
import { IssueTitle } from '../PanelComponents'

const ReviewApplication = ({ issue, requestIndex }) => {
const githubCurrentUser = useGithubAuth()
const {
api: { reviewApplication },
} = useAragonApi()
const { api } = useAragonApi()
const reviewApplication = api.reviewApplication
const { closePanel } = usePanelManagement()
const theme = useTheme()

Expand Down Expand Up @@ -54,7 +52,8 @@ const ReviewApplication = ({ issue, requestIndex }) => {
const review = buildReturnData(approved)
// new IPFS data is old data plus state returned from the panel
const ipfsData = issue.requestsData[index]
const requestIPFSHash = await ipfsAdd({ ...ipfsData, review })
const val = new Blob([Buffer.from(JSON.stringify({ ...ipfsData, review }))])
const requestIPFSHash = await api.datastore('add', val).toPromise()

reviewApplication(
toHex(issue.repoId),
Expand Down
9 changes: 4 additions & 5 deletions apps/projects/app/components/Panel/ReviewWork/ReviewWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ import { FormField, FieldTitle } from '../../Form'
import useGithubAuth from '../../../hooks/useGithubAuth'
import { useAragonApi } from '../../../api-react'
import { usePanelManagement } from '../../Panel'
import { ipfsAdd } from '../../../utils/ipfs-helpers'
import { toHex } from 'web3-utils'
import { issueShape } from '../../../utils/shapes.js'
import { IssueTitle } from '../PanelComponents'
import workRatings from '../../../utils/work-ratings.js'

const ReviewWork = ({ issue }) => {
const githubCurrentUser = useGithubAuth()
const {
api: { reviewSubmission },
} = useAragonApi()
const { api } = useAragonApi()
const reviewSubmission = api.reviewSubmission
const { closePanel } = usePanelManagement()
const theme = useTheme()

Expand Down Expand Up @@ -60,7 +58,8 @@ const ReviewWork = ({ issue }) => {

// new IPFS data is old data plus state returned from the panel
const ipfsData = issue.workSubmissions[issue.workSubmissions.length - 1]
const requestIPFSHash = await ipfsAdd({ ...ipfsData, review: data })
const val = new Blob([Buffer.from(JSON.stringify({ ...ipfsData, review: data }))])
const requestIPFSHash = await api.datastore('add', val).toPromise()

const total = new BN(issue.data.balance, 10)
const fulfillers = issue.data.work.fulfillers
Expand Down
4 changes: 2 additions & 2 deletions apps/projects/app/components/Panel/SubmitWork/SubmitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Form, FormField } from '../../Form'
import useGithubAuth from '../../../hooks/useGithubAuth'
import { useAragonApi } from '../../../api-react'
import { usePanelManagement } from '../../Panel'
import { ipfsAdd } from '../../../utils/ipfs-helpers'
import { issueShape } from '../../../utils/shapes.js'
import standardBounties from '../../../abi/StandardBounties.json'
import { IssueTitle } from '../PanelComponents'
Expand Down Expand Up @@ -45,7 +44,8 @@ const SubmitWork = ({ issue }) => {

closePanel()

const ipfsHash = await ipfsAdd(data)
const val = new Blob([Buffer.from(JSON.stringify(data))])
const ipfsHash = await api.datastore('add', val).toPromise()
const bountiesRegistry = await api.call('bountiesRegistry').toPromise()
const bountyContract = api.external(bountiesRegistry, standardBounties.abi)
bountyContract.fulfillBounty(
Expand Down
5 changes: 2 additions & 3 deletions apps/projects/app/store/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ipfsGet } from '../utils/ipfs-helpers'

import {
ACTION_PERFORMED,
REQUESTING_GITHUB_TOKEN,
Expand Down Expand Up @@ -167,7 +165,8 @@ export const handleEvent = async (state, action, vaultAddress, vaultContract) =>
)
if (!issue) return state

const ipfsData = await ipfsGet(_data)
const res = await app.datastore('cat', _data).toPromise()
const ipfsData = res.data

// we only care about ActionPerformed when called in ReviewSubmission
if (!ipfsData.fulfillmentId) return state
Expand Down
11 changes: 7 additions & 4 deletions apps/projects/app/store/helpers/issues.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { hexToAscii, toHex } from 'web3-utils'
import { app } from '../app'
import { ipfsGet } from '../../utils/ipfs-helpers'
import standardBounties from '../../abi/StandardBounties.json'

const assignmentRequestStatus = [ 'Unreviewed', 'Accepted', 'Rejected' ]
Expand Down Expand Up @@ -63,6 +62,7 @@ export const loadIssueData = async ({ repoId, issueNumber }) => {
}

export const loadIpfsData = async ipfsHash => {
const res = await app.datastore('cat', ipfsHash).toPromise()
const {
detailsOpen,
exp,
Expand All @@ -74,7 +74,8 @@ export const loadIpfsData = async ipfsHash => {
size,
slots,
slotsIndex,
} = await ipfsGet(ipfsHash)
} = res.data

return {
detailsOpen,
exp,
Expand Down Expand Up @@ -152,7 +153,8 @@ export const determineWorkStatus = issue => {
const getRequest = (repoId, issueNumber, applicantId) => {
return new Promise(resolve => {
app.call('getApplicant', repoId, issueNumber, applicantId).subscribe(async (response) => {
const bountyData = await ipfsGet(response.application)
const res = await app.datastore('cat', response.application).toPromise()
const bountyData = res.data
resolve({
contributorAddr: response.applicant,
status: assignmentRequestStatus[parseInt(response.status)],
Expand All @@ -176,6 +178,7 @@ const loadRequestsData = ({ repoId, issueNumber }) => {
}

export const buildSubmission = async ({ fulfillmentId, fulfillers, ipfsHash, submitter }) => {
const res = await app.datastore('cat', ipfsHash).toPromise()
const {
ack1,
ack2,
Expand All @@ -184,7 +187,7 @@ export const buildSubmission = async ({ fulfillmentId, fulfillers, ipfsHash, sub
proof,
submissionDate,
user,
} = await ipfsGet(ipfsHash)
} = res.data

return {
ack1,
Expand Down
35 changes: 0 additions & 35 deletions apps/projects/app/utils/ipfs-helpers.js

This file was deleted.