Skip to content

Commit

Permalink
Merge pull request #76 from AutarkLabs/ipfs-old-cid
Browse files Browse the repository at this point in the history
refactor(ipfs): get rid of ipfs dag to use v0 cId for state
  • Loading branch information
e18r authored Feb 4, 2020
2 parents 2cfce5b + 11e3925 commit c3eb898
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/api-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ const functions =
((appState, setAppState) => ({
addWidget: (_id, cId) => ({
toPromise: async () =>{
const widgetObj = (await ipfs.dag.get(cId)).value
const widgetObj = JSON.parse((await ipfs.object.data(cId)).toString())

setAppState({
...appState,
widgets: [ ...appState.widgets, { ...widgetObj } ],
})},
})
,
}),
setSyncing: syncing =>
setAppState({
...appState,
Expand Down
8 changes: 2 additions & 6 deletions app/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const App = ({ api, widgets, isSyncing }) => {
nextWidgets = widgets
nextWidgets[index] = widgetObject
}
const cId = (
await ipfs.dag.put(nextWidgets, { pin: true })
).toBaseEncodedString()
const cId = (await ipfs.object.put({ Data: Buffer.from(JSON.stringify(nextWidgets)), Links: [] }, { enc: 'json', pin: true })).string
api.updateContent(cId).toPromise()
setEditWidget(null)
}, [ api, widgets ])
Expand All @@ -55,9 +53,7 @@ const App = ({ api, widgets, isSyncing }) => {
}

const handleEditModeSubmit = useCallback(async () => {
const cId = (
await ipfs.dag.put(editedWidgets, { pin: true })
).toBaseEncodedString()
const cId = (await ipfs.object.put({ Data: Buffer.from(JSON.stringify(editedWidgets)), Links: [] }, { enc: 'json', pin: true })).string
api.updateContent(cId).toPromise()
setEditMode(false)
}, [ api, editedWidgets, setEditMode ])
Expand Down
33 changes: 18 additions & 15 deletions app/components/Content/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@ const EmptyMessage = ({ primary }) => (
/>
<div
css={`
color: ${theme.content};
${textStyle('title4')}
`}
color: ${theme.content};
${textStyle('title4')}
`}
>
No widgets here
No widgets here
</div>
{primary && <div
css={`
/* No aragon color defined for this */
color: #637381;
margin: ${1 * GU}px 0;
text-align: center;
${textStyle('body2')}
`}
>
Add a new widget or move an existing one to this primary column
</div>}
{
primary &&
<div
css={`
/* No aragon color defined for this */
color: #637381;
margin: ${1 * GU}px 0;
text-align: center;
${textStyle('body2')}
`}
>
Add a new widget or move an existing one to this primary column
</div>
}
</div>
</Card>
)
Expand Down
4 changes: 1 addition & 3 deletions app/components/Content/WidgetMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ const Widget = ({ id, children, type, onEditMarkdown, ...props }) => {

const onRemove = async id => {
const nextWidgets = widgets.filter(w => w.id !== id)
const cId = (
await ipfs.dag.put(nextWidgets, { pin: true })
).toBaseEncodedString()
const cId = (await ipfs.object.put({ Data: Buffer.from(JSON.stringify(nextWidgets)), Links: [] }, { enc: 'json', pin: true })).string
api.updateContent(cId).toPromise()
}

Expand Down
2 changes: 1 addition & 1 deletion app/components/Widget/Votes/Votes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import React, { useEffect, useMemo, useState } from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { BigNumber } from 'bignumber.js'
Expand Down
4 changes: 2 additions & 2 deletions app/store/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { ipfs } from '../utils/ipfs'
/// ////////////////////////////////////

export const updateContent = async cId => {
const content = (await ipfs.dag.get(cId)).value
return content
const content = (await ipfs.object.data(cId)).toString()
return JSON.parse(content)
}

0 comments on commit c3eb898

Please sign in to comment.