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

Commit

Permalink
single hook to issue license
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmattgray committed Mar 27, 2022
1 parent e4c2c31 commit 15529d1
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 163 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"buffer": "^6.0.3",
"delay": "^5.0.0",
"moment": "^2.29.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
2 changes: 0 additions & 2 deletions src/components/AgentAuthority/ContentWrap/ContentWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
import ColumnLeftWrap from '../ColumnLeft/ColumnLeftWrap'
import ColumnRightWrap from '../ColumnRight/ColumnRightWrap'

import RequestProof from '../RequestProof'
import IssueLicense from '../IssueLicense'

export default function ContentWrap({ origin }) {
return (
<>
<RequestProof origin={origin} />
<IssueLicense origin={origin} />
<ColumnLeftWrap origin={origin} />
<ColumnRightWrap origin={origin} />
Expand Down
62 changes: 14 additions & 48 deletions src/components/AgentAuthority/IssueLicense/IssueLicense.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,28 @@
/**
* Polls for verified presentation proofs and issues a license, then deletes the proof
*/
import { useEffect, useState } from 'react'
import moment from 'moment'
import LicenseCredDef from '../LicenseCredDef'
import useIssueLicense from '../../../interface/hooks/use-issue-license'
import useGetLoopedPresentProofRecords from '../../../interface/hooks/use-get-looped-present-proof-records'
import usePostIssueCredentialSendOffer from '../../../interface/hooks/use-post-issue-credential-send-offer'
import useDeleteRecord from '../../../interface/hooks/use-delete-record'
import Error from '../../Common/Misc/Error'

export default function IssueLicense({ origin }) {
const [licenseCredDefId, setLicenseCredDefId] = useState('')
const [statusIssue, errorIssue, startIssueLicense] = useIssueLicense()
const [statusRecords, errorRecords, startGetRecordsHandler] =
useGetLoopedPresentProofRecords()
const [errorIssueCred, startFetchHandlerCredOffer] =
usePostIssueCredentialSendOffer()
const [errorDelete, startDeleteHandler] = useDeleteRecord()

useEffect(() => {
const sendCredOffers = (verifiedProofs) => {
if (licenseCredDefId) {
verifiedProofs.forEach((verified) => {
const {
by_format: {
pres: {
indy: {
requested_proof: { revealed_attrs: attributes },
},
},
},
} = verified
const expiry = moment().add(2, 'years').format('YYYYMMDD')

startFetchHandlerCredOffer(
origin,
verified.connection_id,
licenseCredDefId,
attributes['0_id_uuid'].raw,
attributes['0_type_uuid'].raw,
expiry,
verified.pres_request.comment,
() => {},
() => {
startDeleteHandler(
origin,
verified.pres_ex_id,
() => {},
() => {}
)
}
)
})
}
const issueLicenses = (proposals) => {
proposals.forEach((proposal) => {
if (licenseCredDefId) {
startIssueLicense(origin, proposal, licenseCredDefId)
}
})
}

const intervalIdFetch = startGetRecordsHandler(
origin,
'done',
sendCredOffers
'proposal-received',
issueLicenses
)
if (statusRecords !== 'started') clearInterval(intervalIdFetch)
return function clear() {
Expand All @@ -65,19 +31,19 @@ export default function IssueLicense({ origin }) {
}, [
origin,
statusRecords,
startFetchHandlerCredOffer,
startGetRecordsHandler,
licenseCredDefId,
startDeleteHandler,
startIssueLicense,
])
console.log(statusIssue)

return (
<>
<LicenseCredDef
origin={origin}
setLicenseCredDefId={setLicenseCredDefId}
/>
<Error errors={[errorIssueCred, errorRecords, errorDelete]} />
<Error errors={[errorRecords, errorIssue]} />
</>
)
}
56 changes: 0 additions & 56 deletions src/components/AgentAuthority/RequestProof/RequestProof.js

This file was deleted.

1 change: 0 additions & 1 deletion src/components/AgentAuthority/RequestProof/index.js

This file was deleted.

28 changes: 13 additions & 15 deletions src/interface/hooks/use-delete-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ export default function useDeleteRecord() {
const path = '/present-proof-2.0/records/'
const transformData = (retrievedData) => retrievedData
const [error, setError] = useState(null)
const onStartFetch = useCallback(
(origin, presExId, setStatus, setStoreData) => {
del(
origin,
path + presExId,
{},
setStatus,
setError,
setStoreData,
transformData
)
},
[]
)
return [error, onStartFetch]
const [status, setStatus] = useState('idle')
const onStartFetch = useCallback((origin, presExId, setStoreData) => {
del(
origin,
path + presExId,
{},
setStatus,
setError,
setStoreData,
transformData
)
}, [])
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 15529d1

Please sign in to comment.