fetchNotifications
The fetchNotifications
function is a utility that fetches user notifications from the EFP API. It supports different time intervals for filtering notifications and includes pagination support.
Usage
const notifications = await fetchNotifications('0x123...', 'month')
Parameters
Parameter | Type | Description |
---|---|---|
userAddress | string | The Ethereum address of the user |
interval | 'hour' | 'day' | 'week' | 'month' | 'all' | Time interval for filtering notifications |
Returns
notifications: [
{
action: "follow"
tag: null
updated_at: string
// ... other notification properties
}
]
Features
- Fetches up to 1000 notifications per request
- Supports different time intervals:
hour
: Last hourday
: Last 24 hoursweek
: Last 7 daysmonth
: Last 30 daysall
: All notifications
- Returns notifications sorted by most recent first
Example
import { fetchNotifications } from 'ethereum-identity-kit'
async function getNotifications(address) {
try {
const response = await fetchNotifications(address, 'month')
if (!response) {
console.log('No notifications found')
return
}
console.log(`Found ${response.notifications.length} notifications`)
return response.notifications
} catch (error) {
console.error('Error fetching notifications:', error)
}
}
The function returns
null
if no userAddress
is provided or if the request fails.⚠️
Make sure to handle the case when the API request fails or returns no data. The function will return null
in such
cases.