Skip to content
Snippets Groups Projects
Commit c37af735 authored by Alexey Lunin's avatar Alexey Lunin
Browse files

Remove constant notification pulling logic and fix receiving oob messages

parent a1e52480
No related branches found
No related tags found
1 merge request!19Fix accepting oob credentials and proof
import { useEffect, useState } from 'react';
import {getNotifications, AgentNotification} from "src/utils/agentUtils";
import rootStore from "src/store/rootStore";
import {useMemo} from 'react';
import {AgentNotification} from "src/utils/agentUtils";
import {Results, useQuery} from "@realm/react";
import {useConnections, useCredentialByState, useProofByState} from "@aries-framework/react-hooks";
import Email from "../db-models/Email";
import {CredentialState, ProofState} from "@aries-framework/core";
import {ConnectionRecord} from "@aries-framework/core/build/modules/connections/repository/ConnectionRecord";
export const useAgentNotifications = (): AgentNotification[] => {
const [notifications, setNotifications] = useState<AgentNotification[]>([]);
const fetchNotifications = async () => {
const data = await getNotifications(rootStore.agentStore.agent);
setNotifications(data);
}
useEffect(() => {
const interval = setInterval(fetchNotifications, 2000);
fetchNotifications();
return () => clearInterval(interval);
}, []);
const allConnections = useConnections();
const newOffers = useCredentialByState(CredentialState.OfferReceived);
const newProofRequests = useProofByState(ProofState.RequestReceived);
const notifications = useMemo(() => {
const result: AgentNotification[] = [];
for (const offer of newOffers) {
let connection: ConnectionRecord | null = null;
if (offer.connectionId) {
connection = allConnections.records.find(p => p.id === offer.connectionId) || null;
}
result.push({ key: offer.id, credentialOffer: offer, connection: connection });
}
for (const request of newProofRequests) {
let connection: ConnectionRecord | null = null;
if (request.connectionId) {
connection = allConnections.records.find(p => p.id === request.connectionId) || null;
}
result.push({ key: request.id, proofRequest: request, connection: connection });
}
return result;
}, [newOffers, newProofRequests, allConnections]);
return notifications;
};
......
import {Agent, CredentialExchangeRecord, CredentialState, ProofExchangeRecord, ProofState} from "@aries-framework/core";
import {CredentialExchangeRecord, ProofExchangeRecord} from "@aries-framework/core";
export interface AgentNotification {
......@@ -7,44 +7,3 @@ export interface AgentNotification {
credentialOffer?: CredentialExchangeRecord;
proofRequest?: ProofExchangeRecord;
}
export const getNotifications = async (agent: Agent): Promise<AgentNotification[]> => {
const newOffers = await agent.credentials.findAllByQuery({ state: CredentialState.OfferReceived });
const newProofRequests = await agent.proofs.findAllByQuery({ state: ProofState.RequestReceived });
const rejectedIds: string[] = [];
// Declining the credential if connection is deleted
for await (const offer of newOffers) {
if (!offer.connectionId) {
await agent.credentials.declineOffer(offer.id);
rejectedIds.push(offer.id);
}
}
// Declining the proof if connection is deleted and message doesn't have ~service decorator
for await (const proof of newProofRequests) {
if (!proof.connectionId) {
await agent.proofs.declineRequest(proof.id);
rejectedIds.push(proof.id);
}
}
const notifications: AgentNotification[] = [];
const filteredOffers = newOffers.filter(p => !rejectedIds.some(rejId => rejId === p.id));
for await (const offer of filteredOffers) {
const connection = await agent.connections.getById(offer.connectionId as string);
notifications.push({ key: offer.id, credentialOffer: offer, connection: connection });
}
const filteredProofRequests = newProofRequests.filter(p => !rejectedIds.some(rejId => rejId === p.id))
for await (const request of filteredProofRequests) {
const connection = await agent.connections.getById(request.connectionId as string);
notifications.push({ key: request.id, proofRequest: request, connection: connection });
}
return notifications.sort((a, b) => {
const aCreatedAt = a.credentialOffer?.createdAt || a.proofRequest?.createdAt as Date;
const bCreatedAt = b.credentialOffer?.createdAt || b.proofRequest?.createdAt as Date;
return new Date(bCreatedAt).getTime() - new Date(aCreatedAt).getTime();
});
};
ConnectionInvitation
CredentialDetails
CredentialOffer
ListCredentials
Notifications
ProofRequest
Scan
Import Wallet Select Wallet does not work (For some reason android does not want to show file selector)
Export Wallet - Does not have access to write files
SealDetailsInfo - issue on chain component. First two steps displays as broken
App is crashed after pin change
Wallet does not work at all after pin change
SCAN issue. it should display accept connection screen, but actually it do it automatically
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment