-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use usecontext for the rerender of credentials when we receive a new one
- Loading branch information
1 parent
287f722
commit 4c691b3
Showing
4 changed files
with
128 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { createContext, useState, useEffect } from 'react'; | ||
import { useApi } from '../api'; | ||
import { extractCredentialFriendlyName } from '../functions/extractCredentialFriendlyName'; | ||
|
||
const CredentialsContext = createContext(); | ||
|
||
export const CredentialsProvider = ({ children }) => { | ||
const api = useApi(); | ||
const [vcEntityList, setVcEntityList] = useState([]); | ||
|
||
useEffect(() => { | ||
const getData = async () => { | ||
const response = await api.get('/storage/vc'); | ||
const vcEntityList = await Promise.all(response.data.vc_list.map(async vcEntity => { | ||
const name = await extractCredentialFriendlyName(vcEntity.credential); | ||
return { ...vcEntity, friendlyName: name }; | ||
})); | ||
vcEntityList.sort((vcA, vcB) => vcB.issuanceDate - vcA.issuanceDate); | ||
setVcEntityList(vcEntityList); | ||
}; | ||
getData(); | ||
}, [api]); | ||
|
||
const refreshCredentials = async () => { | ||
const response = await api.get('/storage/vc'); | ||
const vcEntityList = await Promise.all(response.data.vc_list.map(async vcEntity => { | ||
const name = await extractCredentialFriendlyName(vcEntity.credential); | ||
return { ...vcEntity, friendlyName: name }; | ||
})); | ||
vcEntityList.sort((vcA, vcB) => vcB.issuanceDate - vcA.issuanceDate); | ||
setVcEntityList(vcEntityList); | ||
}; | ||
|
||
return ( | ||
<CredentialsContext.Provider value={{ vcEntityList, refreshCredentials }}> | ||
{children} | ||
</CredentialsContext.Provider> | ||
); | ||
}; | ||
|
||
export default CredentialsContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters