diff --git a/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx b/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx
index 61f912eab..d849e1d83 100644
--- a/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx
+++ b/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx
@@ -5,25 +5,13 @@ import SearchBar from '../../components/SearchBar';
import { useRouter } from 'next/router';
import Link from 'next/link';
import { getRecentTransactionAccounts } from '../../utils/push';
-import { getCheckSumAddress } from '../../utils';
+import { formatDate, getCheckSumAddress } from '../../utils';
export default function Explorer() {
const [page, setPage] = useState(1);
const [latestNotifications, setLatestNotifications] = useState<
- { address: string }[]
- >([
- // generate 10 dummy data
- { address: '0x5ac9E6205eACA2bBbA6eF716FD9AabD76326EEee' },
- { address: '0x1234567890123456789012345678901234567891' },
- { address: '0x1234567890123456789012345678901234567892' },
- { address: '0x1234567890123456789012345678901234567893' },
- { address: '0x1234567890123456789012345678901234567894' },
- { address: '0x1234567890123456789012345678901234567895' },
- { address: '0x1234567890123456789012345678901234567896' },
- { address: '0x1234567890123456789012345678901234567897' },
- { address: '0x1234567890123456789012345678901234567898' },
- { address: '0x1234567890123456789012345678901234567899' },
- ]);
+ { nsId: string; last_usage: string }[]
+ >([]);
const [total, setTotal] = useState(20);
const size = 10; // Hardcoded in api
@@ -41,8 +29,7 @@ export default function Explorer() {
// Fetch initial stats and latest blocks
const fetchData = async () => {
const recipients = await getRecentTransactionAccounts();
- console.log(recipients);
- // setLatestNotifications(recipients);
+ setLatestNotifications(recipients);
};
// Polling function
@@ -68,24 +55,23 @@ export default function Explorer() {
{latestNotifications.map((notification, index) => (
-
+
-
- {notification.address}
+ {notification.nsId}
- {/* {protocol.category} */}
- Maybe A TimeStamp
+ {formatDate(notification.last_usage)}
diff --git a/packages/examples/dnode-dapp/src/utils/index.ts b/packages/examples/dnode-dapp/src/utils/index.ts
index 3291260e8..69d837812 100644
--- a/packages/examples/dnode-dapp/src/utils/index.ts
+++ b/packages/examples/dnode-dapp/src/utils/index.ts
@@ -1,5 +1,6 @@
// TODO: Implement All the Fns
+import { getAddress } from 'viem';
import { Block, NetworkStats, Transaction } from '../types';
export const fetchNetworkStats = async (): Promise => {
@@ -44,3 +45,26 @@ export const fetchTransaction = async (
value: '1000',
};
};
+
+export const getCheckSumAddress = (address: string): string => {
+ const addr = address.toLowerCase();
+ try {
+ return getAddress(addr);
+ } catch (e) {
+ return addr;
+ }
+};
+
+export const formatDate = (dateString: string): string => {
+ const date = new Date(dateString);
+ if (isNaN(date.getTime())) {
+ return 'Invalid date';
+ }
+ return date.toLocaleDateString('en-US', {
+ year: 'numeric',
+ month: 'long',
+ day: 'numeric',
+ hour: '2-digit',
+ minute: '2-digit',
+ });
+};
diff --git a/packages/examples/dnode-dapp/src/utils/push.ts b/packages/examples/dnode-dapp/src/utils/push.ts
index f9477922c..b35c0cd62 100644
--- a/packages/examples/dnode-dapp/src/utils/push.ts
+++ b/packages/examples/dnode-dapp/src/utils/push.ts
@@ -1,7 +1,8 @@
import { PushAPI } from '@pushprotocol/dnode';
import { ENV } from '@pushprotocol/dnode/src/lib/constants';
+import axios from 'axios';
+import { getCheckSumAddress } from '.';
-// TODO: Change to dev or stage
const env = ENV.DEV;
export const sendNotification = async (
@@ -11,7 +12,8 @@ export const sendNotification = async (
signer: any
) => {
const userAlice = await PushAPI.initialize(signer, { env });
- return await userAlice.channel.send(recipient, {
+ const parsedRecipients = recipient.map((r) => getCheckSumAddress(r));
+ return await userAlice.channel.send(parsedRecipients, {
notification: {
title,
body,
@@ -28,3 +30,16 @@ export const getAddressTrx = async (address: string) => {
const userAlice = await PushAPI.initialize(null, { env, account: address });
return await userAlice.notification.list('INBOX');
};
+
+export const getRecentTransactionAccounts = async () => {
+ // Example with no additional data or headers
+ return await axios
+ .post('https://s1.dev.push.org/api/v1/kv/ns/all')
+ .then((response) => {
+ return response.data;
+ })
+ .catch((error) => {
+ console.error('Error:', error);
+ return [];
+ });
+};