Skip to content

Commit

Permalink
feat(react-hooks): filter by connection id (#196)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Nadraliev <andrew.nadraliev@dsr-corporation.com>
  • Loading branch information
nadraliev committed Mar 23, 2023
1 parent 508d793 commit 11ff947
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/react-hooks/src/CredentialProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export const useCredentials = () => {
return credentialContext
}

export const useCredentialsByConnectionId = (connectionId: string): CredentialExchangeRecord[] => {
const { records: credentials } = useCredentials()
return useMemo(
() => credentials.filter((credential: CredentialExchangeRecord) => credential.connectionId === connectionId),
[credentials, connectionId]
)
}

export const useCredentialById = (id: string): CredentialExchangeRecord | undefined => {
const { records: credentials } = useCredentials()
return credentials.find((c: CredentialExchangeRecord) => c.id === id)
Expand Down
8 changes: 8 additions & 0 deletions packages/react-hooks/src/ProofProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export const useProofs = () => {
return proofContext
}

export const useProofsByConnectionId = (connectionId: string): ProofExchangeRecord[] => {
const { records: proofs } = useProofs()
return useMemo(
() => proofs.filter((proof: ProofExchangeRecord) => proof.connectionId === connectionId),
[proofs, connectionId]
)
}

export const useProofById = (id: string): ProofExchangeRecord | undefined => {
const { records: proofs } = useProofs()
return proofs.find((p: ProofExchangeRecord) => p.id === id)
Expand Down

0 comments on commit 11ff947

Please sign in to comment.