-
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.
Minor improve to handle Notfication component, make sure call get cre…
…dentials only logged in and Add animation on new credentials cards
- Loading branch information
1 parent
4c691b3
commit 6cdb869
Showing
5 changed files
with
80 additions
and
49 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 |
---|---|---|
@@ -1,41 +1,45 @@ | ||
import React, { createContext, useState, useEffect } from 'react'; | ||
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([]); | ||
|
||
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> | ||
); | ||
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()); | ||
}, 8000); // Clear the highlight after 5 seconds | ||
} | ||
|
||
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
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