-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from wwWallet/enh/render-new-vc
Optimize Credential Display with React Context and Highlight Animation
- Loading branch information
Showing
5 changed files
with
158 additions
and
127 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,45 @@ | ||
import React, { createContext, useState, useEffect, useCallback } 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([]); | ||
const [latestCredentials, setLatestCredentials] = useState(new Set()); | ||
|
||
const getData = useCallback(async () => { | ||
try { | ||
const response = await api.get('/storage/vc'); | ||
const fetchedVcList = response.data.vc_list; | ||
const vcEntityList = await Promise.all(fetchedVcList.map(async vcEntity => { | ||
const name = await extractCredentialFriendlyName(vcEntity.credential); | ||
return { ...vcEntity, friendlyName: name }; | ||
})); | ||
vcEntityList.sort((vcA, vcB) => new Date(vcB.issuanceDate) - new Date(vcA.issuanceDate)); | ||
|
||
const latestIssuanceDate = vcEntityList[0]?.issuanceDate; | ||
const latestCreds = new Set(vcEntityList.filter(vc => vc.issuanceDate === latestIssuanceDate).map(vc => vc.id)); | ||
|
||
if (window.location.pathname.includes('/cb')) { | ||
setLatestCredentials(latestCreds); | ||
setTimeout(() => { | ||
setLatestCredentials(new Set()); | ||
}, 4000); | ||
} | ||
|
||
setVcEntityList(vcEntityList); | ||
} catch (error) { | ||
console.error('Failed to fetch data', error); | ||
} | ||
}, [api]); | ||
|
||
return ( | ||
<CredentialsContext.Provider value={{ vcEntityList, latestCredentials, getData }}> | ||
{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
Oops, something went wrong.