Skip to content

Commit

Permalink
fix: React example SDR
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 17, 2020
1 parent 3e73872 commit b741e72
Show file tree
Hide file tree
Showing 4 changed files with 867 additions and 311 deletions.
27 changes: 14 additions & 13 deletions examples/react-graphql/client/src/components/Request/Request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import * as queries from '../../gql/queries'
const S = require('sugar/string')

interface Props {
sender: Types.Identity
receiver: Types.Identity
from: Types.Identity
to: Types.Identity
threadId: string
sdr: any
close: () => void
Expand All @@ -25,7 +25,8 @@ interface ValidationState {
}
}

const Component: React.FC<Props> = ({ sdr, sender, receiver, threadId, close }) => {
const Component: React.FC<Props> = ({ sdr, from, to, threadId, close }) => {
console.log({ sdr, from, to, threadId, close })
const [sending, updateSending] = useState<boolean>(false)
const [selected, updateSelected] = useState<ValidationState>({})
const [formValid, setValid] = useState(true)
Expand Down Expand Up @@ -72,7 +73,7 @@ const Component: React.FC<Props> = ({ sdr, sender, receiver, threadId, close })
sendMessageDidCommAlpha1({
variables: {
data: {
to: sender.did,
to: from.did,
from: appState.defaultDid,
type: 'jwt',
body: response.signPresentationJwt.raw,
Expand All @@ -93,7 +94,7 @@ const Component: React.FC<Props> = ({ sdr, sender, receiver, threadId, close })
variables: {
data: {
issuer: appState.defaultDid,
audience: sender.did,
audience: from.did,
tag: threadId,
context: ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation'],
Expand Down Expand Up @@ -143,7 +144,7 @@ const Component: React.FC<Props> = ({ sdr, sender, receiver, threadId, close })
const isSelected = (jwt: string, claimtype: string): Boolean => {
return selected[claimtype] && selected[claimtype].jwt === jwt
}
console.log({ sender })
console.log({ from })
return (
<Box borderRadius={5} overflow={'hidden'} border={1} borderColor={'#333333'} bg={'#222222'}>
<Box
Expand All @@ -154,13 +155,13 @@ const Component: React.FC<Props> = ({ sdr, sender, receiver, threadId, close })
flex={1}
py={4}
>
<Avatar size={60} did={sender.did} source={sender.profileImage} type={'circle'} />
<Avatar size={60} did={from.did} source={from.profileImage} type={'circle'} />
<Heading as={'h3'} mt={2}>
{sender.shortId}
{from.shortId}
</Heading>
</Box>
<Box bg={'#1b1b1b'} p={3}>
<Text>Share your data with {sender.shortId}</Text>
<Text>Share your data with {from.shortId}</Text>
</Box>
{sdr.map((requestItem: any) => {
return (
Expand All @@ -174,17 +175,17 @@ const Component: React.FC<Props> = ({ sdr, sender, receiver, threadId, close })
<Text>{requestItem.reason}</Text>
</Box>
<Box pt={3}>
{requestItem.vc.map((credential: any) => {
{requestItem.credentials.map((credential: any) => {
return (
<Credential
selected={isSelected(credential.jwt, requestItem.claimType)}
selected={isSelected(credential.raw, requestItem.claimType)}
key={credential.hash}
{...credential}
onClick={() => onSelectItem(credential.hash, credential.jwt, requestItem.claimType)}
onClick={() => onSelectItem(credential.hash, credential.raw, requestItem.claimType)}
/>
)
})}
{requestItem.vc.length === 0 && (
{requestItem.credentials.length === 0 && (
<Text>
Cannot find a credential for <b>{S.String.titleize(requestItem.claimType)}</b>
</Text>
Expand Down
6 changes: 1 addition & 5 deletions examples/react-graphql/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { JwtMessageHandler } from 'daf-did-jwt'
import { DIDCommActionHandler, DIDCommMessageHandler, DIDCommGql } from 'daf-did-comm'
import { W3cMessageHandler, W3cActionHandler, W3cGql } from 'daf-w3c'
import { SdrMessageHandler, SdrActionHandler, SdrGql } from 'daf-selective-disclosure'
import { TrustGraphServiceController, TrustGraphGql, TrustGraphActionHandler } from 'daf-trust-graph'
import { UrlMessageHandler } from 'daf-url'
import * as DafEthrDid from 'daf-ethr-did'
import * as DafLibSodium from 'daf-libsodium'
import { DafResolver } from 'daf-resolver'
import { ApolloServer } from 'apollo-server'
import merge from 'lodash.merge'
import ws from 'ws'
import { createConnection } from 'typeorm'

const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand All @@ -34,9 +31,8 @@ const identityProviders = [
}),
]

const messageHandler = new UrlMessageHandler()
const messageHandler = new DIDCommMessageHandler()
messageHandler
.setNext(new DIDCommMessageHandler())
.setNext(new JwtMessageHandler())
.setNext(new W3cMessageHandler())
.setNext(new SdrMessageHandler())
Expand Down
7 changes: 4 additions & 3 deletions examples/react-graphql/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/lodash.merge": "^4.6.6",
"apollo-server": "^2.9.16",
"daf-core": "../../../packages/daf-core",
"daf-did-comm": "../../../packages/daf-did-comm",
"daf-did-jwt": "../../../packages/daf-did-jwt",
"daf-ethr-did": "../../../packages/daf-ethr-did",
"daf-libsodium": "../../../packages/daf-libsodium",
"daf-resolver": "../../../packages/daf-resolver",
"daf-trust-graph": "../../../packages/daf-trust-graph",
"daf-selective-disclosure": "../../../packages/daf-selective-disclosure",
"daf-w3c": "../../../packages/daf-w3c",
"graphql": "^14.5.8",
"lodash.merge": "^4.6.2",
"typeorm": "^0.2.24",
"ws": "^7.2.1"
"sqlite3": "^4.1.1",
"typeorm": "^0.2.24"
},
"devDependencies": {
"ts-node": "^8.6.2",
Expand Down
Loading

0 comments on commit b741e72

Please sign in to comment.