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

IPFS hash to link and creator address #49

Merged
merged 5 commits into from
Mar 20, 2020
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
2 changes: 0 additions & 2 deletions app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const App = React.memo(() => {

const { appearance } = useGuiStyle()

console.log('appearance', appearance)

const handleBack = useCallback(() => {
selectDelay(-1)
}, [selectDelay])
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/DelayCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const DelayCard = React.memo(({ delay, selectDelay }) => {
</div>
<Description>
<span css="font-weight: bold;">#{delay.scriptId}:</span>{' '}
<ScriptText disabled={false} text={delay.executionDescription} />
<ScriptText text={delay.executionDescription} disabled />
</Description>
<div>
{status === STATUS.PENDING_EXECUTION ? (
Expand Down
17 changes: 16 additions & 1 deletion app/src/components/ScriptText.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import { Link } from '@aragon/ui'
import PropTypes from 'prop-types'
import { transformAddresses } from '../web3-utils'
import { transformIPFSHash, generateURI } from '../lib/ipfs-utils'
import AutoLink from './AutoLink'
import LocalIdentityBadge from './LocalIdentityBadge/LocalIdentityBadge'

Expand Down Expand Up @@ -34,7 +36,20 @@ const ScriptText = React.memo(
<LocalIdentityBadge badgeOnly={disabled} compact entity={part} />
</span>
) : (
<span key={index}>{part}</span>
<React.Fragment key={index}>
{transformIPFSHash(part, (word, isIpfsHash, i) => {
if (isIpfsHash) {
const ipfsUrl = generateURI(word)
return (
<Link href={ipfsUrl} key={i} disabled>
{ipfsUrl}{' '}
</Link>
)
}

return <span key={i}>{word}</span>
})}
</React.Fragment>
)
)}
<br />
Expand Down
14 changes: 14 additions & 0 deletions app/src/lib/ipfs-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const SPLIT_IPFS_REGEX = /(Qm[a-zA-Z0-9]{44})/
const TEST_IPFS_REGEX = /(Qm[a-zA-Z0-9]{44})/

const IPFS_ENDPOINT = 'https://ipfs.eth.aragon.network/ipfs'

export function transformIPFSHash(str, callback) {
return str
.split(SPLIT_IPFS_REGEX)
.map((part, index) => callback(part, TEST_IPFS_REGEX.test(part), index))
}

export function generateURI(hash) {
return `${IPFS_ENDPOINT}/${hash}`
}
78 changes: 59 additions & 19 deletions app/src/screens/DelayDetail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import React from 'react'
import { Bar, Box, BackButton, Countdown, GU, Split, textStyle, useTheme } from '@aragon/ui'

import {
Bar,
Box,
BackButton,
Countdown,
GU,
Split,
textStyle,
useLayout,
useTheme,
} from '@aragon/ui'
import LocalIdentityBadge from '../components/LocalIdentityBadge/LocalIdentityBadge'
import DelayActions from '../components/DelayActions'
import ScriptText from '../components/ScriptText'
import LocalLabelAppBadge from '../components/LocalIdentityBadge/LocalLabelAppBadge'
Expand All @@ -11,8 +21,9 @@ import { formatTime, toHours } from '../lib/math-utils'

const DelayDetail = React.memo(({ delay, onBack, onDelayAction }) => {
const theme = useTheme()
const { layoutName } = useLayout()

const { executionTargetData, executionDescription } = delay
const { executionTargetData, executionDescription, creator } = delay

return (
<React.Fragment>
Expand Down Expand Up @@ -43,22 +54,51 @@ const DelayDetail = React.memo(({ delay, onBack, onDelayAction }) => {
>
<span css="font-weight: bold;">Delay #{delay.scriptId}</span>
</h1>
<div>
<h2
css={`
${textStyle('label2')};
color: ${theme.surfaceContentSecondary};
margin-bottom: ${2 * GU}px;
`}
>
Description
</h2>
<div
css={`
${textStyle('body2')};
`}
>
<ScriptText text={executionDescription} />
<div
css={`
display: grid;
grid-template-columns: ${layoutName === 'large'
? '1fr minmax(300px, auto)'
: 'auto'};
grid-gap: ${layoutName === 'large' ? 5 * GU : 2.5 * GU}px;
`}
>
<div>
<h2
css={`
${textStyle('label2')};
color: ${theme.surfaceContentSecondary};
margin-bottom: ${2 * GU}px;
`}
>
Description
</h2>
<div
css={`
${textStyle('body2')};
`}
>
<ScriptText text={executionDescription} />
</div>
</div>
<div>
<h2
css={`
${textStyle('label2')};
color: ${theme.surfaceContentSecondary};
margin-bottom: ${2 * GU}px;
`}
>
Created By
</h2>
<div
css={`
display: flex;
align-items: flex-start;
`}
>
<LocalIdentityBadge entity={creator} />
</div>
</div>
</div>
<DelayActions
Expand Down
14 changes: 9 additions & 5 deletions app/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function initialize() {

async function createStore() {
return app.store(
(state, { event, returnValues, blockNumber }) => {
(state, { event, returnValues, blockNumber, transactionHash }) => {
const nextState = {
...state,
}
Expand All @@ -29,7 +29,7 @@ async function createStore() {
case 'ExecutionDelaySet':
return newExecutionDelay(nextState, returnValues)
case 'DelayedScriptStored':
return newDelayedScript(nextState, returnValues, blockNumber)
return newDelayedScript(nextState, returnValues, blockNumber, transactionHash)
case 'ExecutionPaused':
return updateDelayedScript(nextState, returnValues)
case 'ExecutionResumed':
Expand Down Expand Up @@ -72,18 +72,20 @@ function initializeState() {

async function newExecutionDelay(state, { executionDelay }) {
app.identify(`Delay ${formatTime(executionDelay)}`)

return { ...state, executionDelay }
}

async function newDelayedScript(state, { scriptId }, blockNumber) {
async function newDelayedScript(state, { scriptId }, blockNumber, transactionHash) {
const { delayedScripts = [] } = state

const { from: creator } = await app.web3Eth('getTransactionReceipt', transactionHash).toPromise()

const { timestamp } = await getBlock(blockNumber) // TODO: Move to getDelayedScript (keep in mind that updateScript also calls this function)
const delayedScript = {
...(await getDelayedScript(scriptId, blockNumber)),
timeSubmitted: marshallDate(timestamp),
totalTimePaused: 0,
creator,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also save this prop when the script is updated (e.g when the script is paused or resumed) otherwise we would lose this information.

This can be achieved at

function mergeScripts(oldScript, newScript) {
where we get the creator from oldScript

}

return {
Expand Down Expand Up @@ -185,7 +187,8 @@ async function getDelayedScript(scriptId) {
*/
function mergeScripts(oldScript, newScript) {
// We need to keep the time the script was submitted and the total time it was paused for progress bar
const { timeSubmitted, totalTimePaused, executionTime: oldExecutionTime } = oldScript || {}
const { timeSubmitted, totalTimePaused, executionTime: oldExecutionTime, creator } =
oldScript || {}

// If resumed => timePaused > 0 else timePaused = 0
const timePaused = newScript.executionTime - oldExecutionTime
Expand All @@ -194,6 +197,7 @@ function mergeScripts(oldScript, newScript) {
...newScript,
timeSubmitted,
totalTimePaused: totalTimePaused + timePaused,
creator,
}
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/web3-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000'
export function transformAddresses(str, callback) {
return str
.split(ETH_ADDRESS_SPLIT_REGEX)
.map((part, index) =>
callback(part, ETH_ADDRESS_TEST_REGEX.test(part), index)
)
.map((part, index) => callback(part, ETH_ADDRESS_TEST_REGEX.test(part), index))
}

/**
Expand Down