Pending Actions
Pending actions refer to actions within the application that have not yet received a response. For example, when a user initiates a workflow to validate a driver’s license and reaches the proof request/response screen, if the user doesn’t submit data back to the verifier, the action remains pending. These pending actions can be monitored and managed within the application.
Types of Notifications in Pending Actions
The application can use various notification types to categorize pending actions. The function formatType
provides a mapping of these types to user-friendly labels:
import { NotificationMessageType } from "@one37id/mobile-js-sdk";
const formatType = (type: string): string => {
console.log("Notification Type:", type);
switch (type) {
case NotificationMessageType.CredentialOffer:
return "Credential";
case NotificationMessageType.ProofRequest:
return "Data Request";
case NotificationMessageType.GeneralMessage:
return "Message";
case NotificationMessageType.ActionMessage:
return "Action";
case NotificationMessageType.ConnectionRequest:
return "Connection Request";
case NotificationMessageType.ProofResponse:
return "Proof Response";
default:
return "Unknown";
}
};
Notification Type Descriptions
- Credential: Indicates a credential offer, allowing the user to receive a specific credential.
- Data Request: Represents a request for data, where a verifier requests proof of specific information.
- Message: A general message notification.
- Action: Represents a custom action requiring user input.
- Connection Request: Initiates a new connection request with another user or entity.
- Proof Response: Indicates a response to a previous data request or proof verification.
Notification Object Structure
Each notification is structured as an object with the following key attributes:
{
"contact": {
"displayName": "BusinessA",
"id": "56942bf9-58c9-4d86-8f0f-00a81425646b",
"isConnected": true,
"isTrusted": true,
"logoUrl": "https://cdn.businessA.com/static/images/businessA.png"
},
"createdAt": "2024-11-05T09:02:23.763Z",
"expiryDate": "2024-11-05T09:12:28.474Z",
"fromDid": "did:web:businessA.dev-one37.id",
"id": 85,
"isRead": false,
"metadata": {
"credentials": []
},
"type": "proof-request"
}
Notification Object Fields
-
contact: Contains details about the notifying entity:
displayName
: Display name of the contact (e.g., "BusinessA").id
: Unique identifier for the contact.isConnected
: Boolean indicating if the user is connected with this contact.isTrusted
: Boolean representing if this contact is marked as trusted.logoUrl
: URL of the contact's logo.
-
createdAt: The timestamp indicating when the notification was created.
-
expiryDate: The expiration timestamp for the notification.
-
fromDid: DID (Decentralized Identifier) of the sender.
-
id: Unique identifier for the notification itself.
-
isRead: Boolean indicating if the notification has been read.
-
metadata: Contains additional metadata, including a list of credentials if applicable.
-
type: The type of notification (e.g.,
"proof-request"
), which can be mapped to a user-friendly label using theformatType
function.
Fetching Pending Actions
To retrieve pending actions (notifications) from the system, you can use a function named fetchNotifications
. This function calls the notificationManager.fetch
method, which retrieves a list of notifications based on pagination parameters:
const fetchNotifications = async () => {
const agent = await initializeAgent();
if (!agent) throw new Error("Agent not initialized");
try {
const notifications = await agent.notificationManager.fetch(1, 10);
if (notifications) setNotifications(notifications);
} catch (error) {
Alert.alert("Error", "Failed to fetch notifications.");
}
};
- Parameters: The
fetch
method accepts a page number (e.g.,1
) and a page size (e.g.,10
), allowing for paginated retrieval of notifications. - Returns: A list of notifications, which are set in the component’s state using
setNotifications
which you can display them later on in alist
.
Processing Notifications
Once a user clicks on a notification, the application processes it by calling the processNotification
function. This function utilizes the notificationManager.process
method, which triggers the presentationRequestCallback
in the callbackHandlers
object in the agent initialization .
const processNotification = async (notificationId: number) => {
const agent = await initializeAgent();
if (!agent) throw new Error("Agent not initialized");
try {
await agent.notificationManager.process(notificationId);
} catch (error) {
Alert.alert("Error", "Failed to process notification.");
}
};
- Parameter:
notificationId
(number) — The unique ID of the notification to be processed. - Effect: Triggers a pending action and the sdk triggers the
presentationRequestCallback
, which takes him to the page where the user can send the data back to the verifier.
UI Display
In the UI, these notifications can be displayed in a list
, with each item rendered based on its contact
information and type. The pending actions
label helps users identify which actions still need attention. Each notification card shows essential details like the contact’s display name, notification type, and expiry date, and clicking a notification triggers the processNotification
function.
This approach enables users to monitor and manage all outstanding actions conveniently and ensures that they are aware of any pending requests or tasks.