diff --git a/examples/react-graphql/client/.env b/examples/react-graphql/client/.env new file mode 100644 index 000000000..7d910f148 --- /dev/null +++ b/examples/react-graphql/client/.env @@ -0,0 +1 @@ +SKIP_PREFLIGHT_CHECK=true \ No newline at end of file diff --git a/examples/react-graphql/client/src/components/Credential/CredentialList.tsx b/examples/react-graphql/client/src/components/Credential/CredentialList.tsx new file mode 100644 index 000000000..1eea8fb46 --- /dev/null +++ b/examples/react-graphql/client/src/components/Credential/CredentialList.tsx @@ -0,0 +1,40 @@ +import React from 'react' +import * as Types from '../../types' +import Credential from './Credential' +import { Box, Heading, Text } from 'rimble-ui' +import './Credential.css' +import * as queries from '../../gql/queries' +import { useQuery } from 'react-apollo' +import { useParams } from 'react-router-dom' + +const S = require('sugar/string') + +interface Props {} + +const Component: React.FC = ({}) => { + const { id } = useParams() + const { data } = useQuery(queries.credentials, { variables: { id } }) + + return ( + + + Credentials + + {data && + data.credentials && + data.credentials.map((credential: any) => { + return ( + + ) + })} + + ) +} + +export default Component diff --git a/examples/react-graphql/client/src/gql/mutations.ts b/examples/react-graphql/client/src/gql/mutations.ts index d60e962d5..d2f87d169 100644 --- a/examples/react-graphql/client/src/gql/mutations.ts +++ b/examples/react-graphql/client/src/gql/mutations.ts @@ -15,8 +15,8 @@ export const deleteIdentity = gql` ` export const signCredentialJwt = gql` - mutation signCredentialJwt($data: SignCredentialInput!) { - signCredentialJwt(data: $data) { + mutation signCredentialJwt($data: SignCredentialInput!, $save: Boolean) { + signCredentialJwt(data: $data, save: $save) { raw } } diff --git a/examples/react-graphql/client/src/gql/queries.ts b/examples/react-graphql/client/src/gql/queries.ts index 28a9b01e0..ee5b54856 100644 --- a/examples/react-graphql/client/src/gql/queries.ts +++ b/examples/react-graphql/client/src/gql/queries.ts @@ -25,6 +25,29 @@ export const credential = gql` } ` +export const credentials = gql` + query credentials($id: String!) { + credentials(input: { where: [{ column: subject, value: [$id] }] }) { + hash + subject { + did + shortId: shortDid + } + issuer { + did + shortId: shortDid + } + issuanceDate + type + claims { + hash + type + value + } + } + } +` + export const identity = gql` query identity($did: String!) { identity(did: $did) { diff --git a/examples/react-graphql/client/src/layout/Layout.tsx b/examples/react-graphql/client/src/layout/Layout.tsx index af9b1f842..033e2ef73 100644 --- a/examples/react-graphql/client/src/layout/Layout.tsx +++ b/examples/react-graphql/client/src/layout/Layout.tsx @@ -15,6 +15,7 @@ import SidePanel from './SidePanel' import NavigationLeft from './NavigationLeft' import Credential from '../components/Credential/Credential' +import CredentialList from '../components/Credential/CredentialList' import RequestDetail from '../components/Request/Request' import Settings from '../views/Settings/Settings' @@ -73,9 +74,15 @@ const Dashboard: React.FC = () => { */} + + + + + + { const { loading, data } = useQuery(queries.allIdentities) - + const history = useHistory() + const { url } = useRouteMatch() + const [highlightedIdentity, highlightIdentity] = useState() console.log(data?.identities) + const showIdentityDetail = (did: string) => { + highlightIdentity(did) + + history.push(`${url}/user/${did}`) + } + return ( {/* */} @@ -22,6 +31,7 @@ const Component = () => { {data?.identities?.map((id: Types.Identity) => { return ( showIdentityDetail(id.did)} className={'identity_row'} key={id.did} mb={2} diff --git a/examples/react-graphql/client/src/views/Identity/IdentitiyManager.tsx b/examples/react-graphql/client/src/views/Identity/IdentitiyManager.tsx index 4eb38cadf..3bf3fd07d 100644 --- a/examples/react-graphql/client/src/views/Identity/IdentitiyManager.tsx +++ b/examples/react-graphql/client/src/views/Identity/IdentitiyManager.tsx @@ -12,7 +12,7 @@ import { AppContext } from '../../context/AppProvider' const Component = () => { const history = useHistory() const { url } = useRouteMatch() - const [highlightedIdentity, highlightIdentity] = useState() + const [highlightedIdentity, highlightIdentity] = useState() const { appState, setDefaultDid } = useContext(AppContext) const { defaultDid } = appState const { data: managedIdentitiesData } = useQuery(queries.managedIdentities) diff --git a/examples/react-graphql/client/src/views/Issue/Issue.tsx b/examples/react-graphql/client/src/views/Issue/Issue.tsx index c4cb53dc6..4ee8bb7f4 100644 --- a/examples/react-graphql/client/src/views/Issue/Issue.tsx +++ b/examples/react-graphql/client/src/views/Issue/Issue.tsx @@ -1,5 +1,5 @@ import React, { useState, useContext } from 'react' -import { Box, Button, Field, Text, Form, Flex, Input, Loader, ToastMessage } from 'rimble-ui' +import { Box, Button, Field, Text, Form, Flex, Input, Loader, ToastMessage, QR } from 'rimble-ui' import Page from '../../layout/Page' import Panel from '../../components/Panel/Panel' import { AppContext } from '../../context/AppProvider' @@ -19,6 +19,7 @@ const Component = () => { const [receiver, setReceiver] = useState('did:web:uport.me') const [claimType, setClaimType] = useState('name') const [claimValue, setClaimValue] = useState('Alice') + const [signedVC, setSignedVC] = useState(null) const [signVc] = useMutation(mutations.signCredentialJwt) const [sendMessageDidCommAlpha1] = useMutation(mutations.sendMessageDidCommAlpha1, { refetchQueries: [ @@ -29,8 +30,8 @@ const Component = () => { ], }) - const send = async () => { - setIsSending(true) + const signVC = async (e: any) => { + e.preventDefault() try { const credentialSubject: any = {} @@ -45,18 +46,31 @@ const Component = () => { type: ['VerifiableCredential'], credentialSubject, }, + save: true, }, }) + setSignedVC(data.signCredentialJwt.raw) + } catch (e) {} + } + + const send = async (e: any) => { + e.preventDefault() + + if (!signedVC) { + return + } - console.log(data) + setIsSending(true) + try { + console.log(signedVC) const { data: dataSend } = await sendMessageDidCommAlpha1({ variables: { data: { from: appState.defaultDid, to: receiver, type: 'jwt', - body: data.signCredentialJwt.raw, + body: signedVC, }, }, }) @@ -71,16 +85,11 @@ const Component = () => { setIsSending(false) } - const handleSubmit = (e: any) => { - e.preventDefault() - send() - } - return ( -
+ {appState.defaultDid} @@ -130,8 +139,25 @@ const Component = () => { + {signedVC && ( + + + + )} + - {isSending ? : } + {isSending ? ( + + ) : ( + + + + + )}