Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Issue license to holder (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Dean <[email protected]>
  • Loading branch information
jonmattgray and mattdean-digicatapult authored Mar 28, 2022
1 parent 9b74007 commit 9a2828c
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 3 deletions.
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "veritable-authority",
"version": "0.1.1",
"version": "0.1.2",
"description": "Front-end for Veritable authority",
"author": "Digital Catapult (https://www.digicatapult.org.uk/)",
"license": "Apache-2.0",
Expand All @@ -14,6 +14,7 @@
},
"dependencies": {
"buffer": "^6.0.3",
"moment": "^2.29.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-json-view": "^1.21.3",
Expand Down
3 changes: 3 additions & 0 deletions src/components/AgentAuthority/ContentWrap/ContentWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import ColumnLeftWrap from '../ColumnLeft/ColumnLeftWrap'
import ColumnRightWrap from '../ColumnRight/ColumnRightWrap'

import IssueLicense from '../IssueLicense'

export default function ContentWrap({ origin }) {
return (
<>
<IssueLicense origin={origin} />
<ColumnLeftWrap origin={origin} />
<ColumnRightWrap origin={origin} />
</>
Expand Down
88 changes: 88 additions & 0 deletions src/components/AgentAuthority/IssueLicense/IssueLicense.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { useEffect, useState } from 'react'
import { AUTHORITY_LABEL, LICENSE_SCHEMA_NAME } from '../../../utils/env.js'

import useIssueLicense from '../../../interface/hooks/use-issue-license'
import useGetLoopedPresentProofRecords from '../../../interface/hooks/use-get-looped-present-proof-records'
import useGetCredDefinitionsCreated from '../../../interface/hooks/use-get-cred-definitions-created'
import usePostSchemas from '../../../interface/hooks/use-post-schemas'
import usePostCredentialDefinitions from '../../../interface/hooks/use-post-credential-definitions'

import Error from '../../Common/Misc/Error'

export default function IssueLicense({ origin }) {
const [licenseCredDefId, setLicenseCredDefId] = useState('')
const [, errorIssue, startIssueLicense] = useIssueLicense()
const [statusRecords, errorRecords, startGetRecordsHandler] =
useGetLoopedPresentProofRecords()
const [errorDefinitionsCreated, startFetchHandlerDefinitionsCreated] =
useGetCredDefinitionsCreated()

const [errorPostSchema, startPostSchema] = usePostSchemas()
const [errorPostCredDefs, startPostCredDef] = usePostCredentialDefinitions()

useEffect(() => {
const issueLicenses = (proposals) => {
proposals.forEach((proposal) => {
if (licenseCredDefId) {
startIssueLicense(origin, proposal, licenseCredDefId)
}
})
}

const intervalIdFetch = startGetRecordsHandler(
origin,
'proposal-received',
issueLicenses
)
if (statusRecords !== 'started') clearInterval(intervalIdFetch)
return function clear() {
return clearInterval(intervalIdFetch)
}
}, [
origin,
statusRecords,
startGetRecordsHandler,
licenseCredDefId,
startIssueLicense,
])

useEffect(() => {
startFetchHandlerDefinitionsCreated(origin, (credDefIds) => {
const licenseCredDefId = credDefIds.find((credDefId) =>
credDefId.includes(LICENSE_SCHEMA_NAME)
)
if (licenseCredDefId) {
setLicenseCredDefId(licenseCredDefId)
} else {
startPostSchema(origin, LICENSE_SCHEMA_NAME, (schemaId) => {
startPostCredDef(
origin,
schemaId,
AUTHORITY_LABEL,
setLicenseCredDefId
)
})
}
})
}, [
origin,
startFetchHandlerDefinitionsCreated,
startPostSchema,
startPostCredDef,
setLicenseCredDefId,
])

return (
<>
<Error
errors={[
errorRecords,
errorIssue,
errorDefinitionsCreated,
errorPostSchema,
errorPostCredDefs,
]}
/>
</>
)
}
1 change: 1 addition & 0 deletions src/components/AgentAuthority/IssueLicense/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './IssueLicense'
23 changes: 23 additions & 0 deletions src/components/Common/Misc/Error/Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default function Error({ errors }) {
return (
<>
<div
className={`${
errors.some((error) => error != undefined) ? 'd-block' : 'd-none'
}`}
style={{
position: 'fixed',
width: '10%',
height: '10%',
inset: '0px',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
zIndex: 100,
}}
>
<div className="text-light m-2 p-2">
<small>{errors.toString()}</small>
</div>
</div>
</>
)
}
1 change: 1 addition & 0 deletions src/components/Common/Misc/Error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Error'
24 changes: 24 additions & 0 deletions src/interface/hooks/use-delete-record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* It returns a function that can be used to delete a connection.
*/
import { useCallback, useState } from 'react'
import del from '../api/helpers/del'

export default function useDeleteRecord() {
const path = '/present-proof-2.0/records/'
const transformData = (retrievedData) => retrievedData
const [error, setError] = useState(null)
const [status, setStatus] = useState('idle')
const onStartFetch = useCallback((origin, presExId, setStoreData) => {
del(
origin,
path + presExId,
{},
setStatus,
setError,
setStoreData,
transformData
)
}, [])
return [status, error, onStartFetch]
}
19 changes: 19 additions & 0 deletions src/interface/hooks/use-get-cred-definitions-created.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This function returns a function that, will fetch the credential
* definitions created by the user
*/
import { useCallback, useState } from 'react'
import get from '../api/helpers/get'

export default function useGetCredDefinitionsCreated() {
const path = '/credential-definitions/created'
const transformData = (retrievedData) =>
retrievedData.credential_definition_ids

const [error, setError] = useState(null)

const onStartFetch = useCallback((fetchOrigin, setStoreData) => {
get(fetchOrigin, path, {}, () => {}, setError, setStoreData, transformData)
}, [])
return [error, onStartFetch]
}
28 changes: 28 additions & 0 deletions src/interface/hooks/use-get-looped-present-proof-records.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* This function returns continuously the present proof records
*/
import { useCallback, useState } from 'react'
import getLooped from '../api/helpers/get-looped'
export default function useGetLoopedPresentProofRecords() {
const path = '/present-proof-2.0/records'
const transformData = (retData) => retData.results
const statusOptions = ['started', 'error', 'stopped']
const [status, setStatus] = useState(statusOptions[0])
const [error, setError] = useState(null)
const onStartFetch = useCallback((origin, state, setStoreData) => {
const params = state ? `state=${state}` : {}
const intervalId = setInterval(() => {
getLooped(
origin,
path,
params,
setStatus,
setError,
setStoreData,
transformData
)
}, 1000)
return intervalId
}, [])
return [status, error, onStartFetch]
}
24 changes: 24 additions & 0 deletions src/interface/hooks/use-get-present-proof-records.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This function returns continuously the present proof records
*/
import { useCallback, useState } from 'react'
import get from '../api/helpers/get'
export default function useGetPresentProofRecord() {
const path = '/present-proof-2.0/records'
const transformData = (retData) => retData
const statusOptions = ['started', 'error', 'stopped']
const [status, setStatus] = useState(statusOptions[0])
const [error, setError] = useState(null)
const onStartFetch = useCallback((origin, presExId, setStoreData) => {
get(
origin,
`${path}/${presExId}`,
{},
setStatus,
setError,
setStoreData,
transformData
)
}, [])
return [status, error, onStartFetch]
}
Loading

0 comments on commit 9a2828c

Please sign in to comment.