Skip to content

Commit

Permalink
feat(case-details-card): save justifications
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras authored and satello committed May 28, 2019
1 parent 93ea85b commit 55bb6aa
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.development
@@ -1 +1,2 @@
REACT_APP_PATCH_USER_SETTINGS_URL=https://8aoprv935h.execute-api.us-east-2.amazonaws.com/staging/user-settings
REACT_APP_PUT_JUSTIFICATIONS_URL=https://8aoprv935h.execute-api.us-east-2.amazonaws.com/staging/justifications
1 change: 1 addition & 0 deletions .env.production
@@ -1 +1,2 @@
REACT_APP_PATCH_USER_SETTINGS_URL=https://hgyxlve79a.execute-api.us-east-2.amazonaws.com/production/user-settings
REACT_APP_PUT_JUSTIFICATIONS_URL=https://hgyxlve79a.execute-api.us-east-2.amazonaws.com/production/justifications
2 changes: 2 additions & 0 deletions netlify.toml
Expand Up @@ -16,10 +16,12 @@
REACT_APP_WEB3_FALLBACK_URL='wss://mainnet.infura.io/ws'
REACT_APP_DRAW_EVENT_LISTENER_BLOCK_NUMBER='7303699'
REACT_APP_PATCH_USER_SETTINGS_URL='https://8aoprv935h.execute-api.us-east-2.amazonaws.com/staging/user-settings'
REACT_APP_PUT_JUSTIFICATIONS_URL='https://8aoprv935h.execute-api.us-east-2.amazonaws.com/staging/justifications'

[context.production.environment]
REACT_APP_CONTEXT='production'
REACT_APP_PATCH_USER_SETTINGS_URL='https://hgyxlve79a.execute-api.us-east-2.amazonaws.com/production/user-settings'
REACT_APP_PUT_JUSTIFICATIONS_URL='https://hgyxlve79a.execute-api.us-east-2.amazonaws.com/production/justifications'

[[redirects]]
from = "/*"
Expand Down
64 changes: 61 additions & 3 deletions src/components/case-details-card.js
Expand Up @@ -11,6 +11,7 @@ import PropTypes from 'prop-types'
import ReactMarkdown from 'react-markdown'
import styled from 'styled-components/macro'
import { useDataloader } from '../bootstrap/dataloader'
import web3DeriveAccount from '../temp/web3-derive-account'
import web3Salt from '../temp/web3-salt'

const StyledCard = styled(Card)`
Expand Down Expand Up @@ -314,7 +315,7 @@ const CaseDetailsCard = ({ ID }) => {
)
)
)
else
else {
sendVote(
ID,
votesData.voteIDs,
Expand All @@ -329,6 +330,62 @@ const CaseDetailsCard = ({ ID }) => {
)
: 0
)
const derivedAccount = await web3DeriveAccount(
drizzle.web3,
drizzleState.account,
'Kleros Court Secret'
)
const votes = {
IDs: votesData.voteIDs,
appeal: dispute2.votesLengths.length - 1,
disputeID: ID,
justification
}
if (
(await (await fetch(process.env.REACT_APP_PUT_JUSTIFICATIONS_URL, {
body: JSON.stringify({
payload: {
address: drizzleState.account,
signature: derivedAccount.sign(JSON.stringify(votes)).signature,
votes
}
}),
headers: { 'Content-Type': 'application/json' },
method: 'PUT'
})).json()).error
) {
const settings = {
derivedAccountAddressForJustifications: {
S: derivedAccount.address
}
}
await (await fetch(process.env.REACT_APP_PATCH_USER_SETTINGS_URL, {
body: JSON.stringify({
payload: {
address: drizzleState.account,
settings,
signature: await drizzle.web3.eth.personal.sign(
JSON.stringify(settings),
drizzleState.account
)
}
}),
headers: { 'Content-Type': 'application/json' },
method: 'PATCH'
})).json()
await (await fetch(process.env.REACT_APP_PUT_JUSTIFICATIONS_URL, {
body: JSON.stringify({
payload: {
address: drizzleState.account,
signature: derivedAccount.sign(JSON.stringify(votes)).signature,
votes
}
}),
headers: { 'Content-Type': 'application/json' },
method: 'PUT'
})).json()
}
}
},
[
dispute && dispute.period,
Expand All @@ -337,7 +394,8 @@ const CaseDetailsCard = ({ ID }) => {
drizzle.web3,
drizzleState.account,
dispute2 && dispute2.votesLengths.length,
subcourts && subcourts[subcourts.length - 1].hiddenVotes
subcourts && subcourts[subcourts.length - 1].hiddenVotes,
justification
]
)
const metaEvidenceActions = useMemo(() => {
Expand Down Expand Up @@ -412,7 +470,7 @@ const CaseDetailsCard = ({ ID }) => {
]) ||
'Unknown Choice'
}".`}
{votesData.canVote && (
{votesData.canVote && dispute.period === '2' && (
<StyledInputTextArea
onChange={onJustificationChange}
placeholder="Justify your vote here..."
Expand Down

0 comments on commit 55bb6aa

Please sign in to comment.