From ed872730948d083961ef6ab5ba41ac2187bce1d4 Mon Sep 17 00:00:00 2001 From: aman035 Date: Fri, 5 Jul 2024 21:01:07 +0530 Subject: [PATCH] chore: fix dapp --- .../examples/dnode-dapp/package-lock.json | 8 +- packages/examples/dnode-dapp/package.json | 2 +- .../src/pages/pushscan/[address].tsx | 73 ++++++++++++++----- .../dnode-dapp/src/pages/pushscan/index.tsx | 2 +- .../examples/dnode-dapp/src/utils/push.ts | 5 ++ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/packages/examples/dnode-dapp/package-lock.json b/packages/examples/dnode-dapp/package-lock.json index 006de4114..75da473d7 100644 --- a/packages/examples/dnode-dapp/package-lock.json +++ b/packages/examples/dnode-dapp/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@headlessui/react": "^2.1.1", "@heroicons/react": "^2.1.4", - "@pushprotocol/dnode": "^0.0.3", + "@pushprotocol/dnode": "^0.0.4", "@rainbow-me/rainbowkit": "^2.1.3", "@tailwindcss/forms": "^0.5.7", "@tanstack/react-query": "^5.28.4", @@ -3719,9 +3719,9 @@ } }, "node_modules/@pushprotocol/dnode": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/@pushprotocol/dnode/-/dnode-0.0.3.tgz", - "integrity": "sha512-rsE1Czeb/+3lmlPIAlTw/bcM7gxZfWHcRuJQQao4YU6FbzZwD1bXY0bukgt08V73Pvp40heFCnHC7UUeaWmozg==", + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@pushprotocol/dnode/-/dnode-0.0.4.tgz", + "integrity": "sha512-qaa5RBhXQ3+eBxRDQdGsDxAeTgBl0gohojG4BzGAYKy0jDX0gp2bP8VjvY8pGHDpOC1jMyRp6cZ1cbfPXezIag==", "dependencies": { "@metamask/eth-sig-util": "^5.0.2", "buffer": "^6.0.3", diff --git a/packages/examples/dnode-dapp/package.json b/packages/examples/dnode-dapp/package.json index f96927e72..d7fb2b5ea 100644 --- a/packages/examples/dnode-dapp/package.json +++ b/packages/examples/dnode-dapp/package.json @@ -10,7 +10,7 @@ "dependencies": { "@headlessui/react": "^2.1.1", "@heroicons/react": "^2.1.4", - "@pushprotocol/dnode": "^0.0.3", + "@pushprotocol/dnode": "^0.0.4", "@rainbow-me/rainbowkit": "^2.1.3", "@tailwindcss/forms": "^0.5.7", "@tanstack/react-query": "^5.28.4", diff --git a/packages/examples/dnode-dapp/src/pages/pushscan/[address].tsx b/packages/examples/dnode-dapp/src/pages/pushscan/[address].tsx index 000fb65a6..39e97b5ee 100644 --- a/packages/examples/dnode-dapp/src/pages/pushscan/[address].tsx +++ b/packages/examples/dnode-dapp/src/pages/pushscan/[address].tsx @@ -1,32 +1,69 @@ -// pages/pushscan/[term].tsx - import { useRouter } from 'next/router'; import React, { useEffect, useState } from 'react'; +import { getAddressTrx } from '../../utils/push'; +import SearchBar from '../../components/SearchBar'; + +// Component to display the result data +const NodeResult: React.FC<{ result: any }> = ({ result }) => ( +
+

Node Result

+

Transaction Count: {result.itemCount}

+

Node Quorum Result: {result.quorumResult}

+

Last Timestamp: {result.lastTs}

+

Transactions Without Quorum Count: {result.keysWithoutQuorumCount}

+
+); + +// Component to display individual items (transactions) +const ParsedTransactionData: React.FC<{ item: any }> = ({ item }) => ( +
+
+      {JSON.stringify(item, null, 2)}
+    
+
+); const PushScan: React.FC = () => { const router = useRouter(); - const { address } = router.query; // Extract the dynamic term from the URL + const { address } = router.query; // Extract the dynamic address from the URL const [data, setData] = useState(null); // State to store fetched data or results - // useEffect(() => { - // if (term) { - // // Fetch data or perform actions based on the dynamic term - // const fetchData = async () => { - // // Replace this with your actual data fetching logic - // const response = await fetch(`/api/pushscan/${term}`); - // const result = await response.json(); - // setData(result); - // }; + useEffect(() => { + if (address) { + // Fetch data or perform actions based on the dynamic address + const fetchData = async () => { + try { + const response = await getAddressTrx(address as string); + setData(response); + } catch (error) { + console.error('Error fetching data:', error); + } + }; - // fetchData(); - // } - // }, [term]); + fetchData(); + } + }, [address]); return ( -
-

- PushScan Results for: {address} +
+ {/* Header with Search Bar */} +
+ +
+

+ PushScan Results for: {address}

+ {data && ( +
+ + {data.items.length > 0 ? ( +

Parsed Transaction Data

+ ) : null} + {data.items.map((item: any, index: number) => ( + + ))} +
+ )}
); }; diff --git a/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx b/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx index 7b834f3f1..16e6ae7af 100644 --- a/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx +++ b/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx @@ -11,7 +11,7 @@ export default function Explorer() { { address: string }[] >([ // generate 10 dummy data - { address: '0x1234567890123456789012345678901234567890' }, + { address: '0x5ac9E6205eACA2bBbA6eF716FD9AabD76326EEee' }, { address: '0x1234567890123456789012345678901234567891' }, { address: '0x1234567890123456789012345678901234567892' }, { address: '0x1234567890123456789012345678901234567893' }, diff --git a/packages/examples/dnode-dapp/src/utils/push.ts b/packages/examples/dnode-dapp/src/utils/push.ts index 17e6ebc1f..e6d2d2534 100644 --- a/packages/examples/dnode-dapp/src/utils/push.ts +++ b/packages/examples/dnode-dapp/src/utils/push.ts @@ -23,3 +23,8 @@ export const getChannelInfo = async (signer: any) => { const userAlice = await PushAPI.initialize(signer, { env }); return await userAlice.channel.info(); }; + +export const getAddressTrx = async (address: string) => { + const userAlice = await PushAPI.initialize(null, { env, account: address }); + return await userAlice.notification.list('INBOX'); +};