From 65f662fbf4f633c9d62fc4bf254b851e6dbf26a5 Mon Sep 17 00:00:00 2001 From: aman035 Date: Mon, 8 Jul 2024 19:06:32 +0530 Subject: [PATCH] chore: fix dnode dapp --- .../tests/lib/notification/channel.test.ts | 7 +++--- .../src/components/Notification.tsx | 2 +- .../dnode-dapp/src/components/SearchBar.tsx | 5 +++- .../dnode-dapp/src/pages/pushscan/index.tsx | 24 ++++++++++++------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/dnode/tests/lib/notification/channel.test.ts b/packages/dnode/tests/lib/notification/channel.test.ts index 0075e5f71..951ca83ef 100644 --- a/packages/dnode/tests/lib/notification/channel.test.ts +++ b/packages/dnode/tests/lib/notification/channel.test.ts @@ -133,10 +133,11 @@ describe('PushAPI.channel functionality', () => { it('With signer : broadcast : Should send notification with title and body', async () => { const res = await userAlice.channel.send(['*'], { notification: { - title: 'test', - body: 'test', + title: 'Testing new notif', + body: 'test new notif', }, }); + console.log(res); expect(res.status).to.equal(200); }); @@ -155,7 +156,7 @@ describe('PushAPI.channel functionality', () => { it('With signer : targeted : Should send notification with title and body', async () => { const res = await userAlice.channel.send( - ['eip155:11155111:0x93A829d16DE51745Db0530A0F8E8A9B8CA5370E5'], + ['eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'], { notification: { title: 'hi', diff --git a/packages/examples/dnode-dapp/src/components/Notification.tsx b/packages/examples/dnode-dapp/src/components/Notification.tsx index e5954a8df..7b4386c20 100644 --- a/packages/examples/dnode-dapp/src/components/Notification.tsx +++ b/packages/examples/dnode-dapp/src/components/Notification.tsx @@ -20,7 +20,7 @@ const SendNotification: React.FC = () => { if (isConnected && walletClient.data && channel === '') { try { const channelInfo = await getChannelInfo(walletClient.data); - if (channelInfo !== null) { + if (channelInfo !== null && channelInfo.processed == 1) { setAllowNotification(true); setChannel(channelInfo.channel); setErrorMessage(''); // Clear error message if the channel is found diff --git a/packages/examples/dnode-dapp/src/components/SearchBar.tsx b/packages/examples/dnode-dapp/src/components/SearchBar.tsx index 936a1530d..59122e9ef 100644 --- a/packages/examples/dnode-dapp/src/components/SearchBar.tsx +++ b/packages/examples/dnode-dapp/src/components/SearchBar.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'; import { useRouter } from 'next/router'; +import { getCheckSumAddress } from '../utils'; const SearchBar: React.FC = () => { const [searchTerm, setSearchTerm] = useState(''); @@ -9,7 +10,9 @@ const SearchBar: React.FC = () => { const handleSearch = () => { if (searchTerm.trim()) { // Navigate to the search results page - router.push(`/pushscan/${encodeURIComponent(searchTerm.trim())}`); + router.push( + `/pushscan/${encodeURIComponent(getCheckSumAddress(searchTerm.trim()))}` + ); } }; diff --git a/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx b/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx index 16e6ae7af..d3bc1278e 100644 --- a/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx +++ b/packages/examples/dnode-dapp/src/pages/pushscan/index.tsx @@ -4,6 +4,8 @@ import { useState, useEffect } from 'react'; import SearchBar from '../../components/SearchBar'; import { useRouter } from 'next/router'; import Link from 'next/link'; +import { getRecentTransactionAccounts } from '../../utils/push'; +import { getCheckSumAddress } from '../../utils'; export default function Explorer() { const [page, setPage] = useState(1); @@ -32,19 +34,25 @@ export default function Explorer() { const router = useRouter(); const handleClick = (address: string) => { - router.push(`/pushscan/${address}`); + router.push(`/pushscan/${getCheckSumAddress(address)}`); }; useEffect(() => { // Fetch initial stats and latest blocks const fetchData = async () => { - // TODO: Fetch all address notif - // const statsData = await fetchNetworkStats(); - // const latestBlocksData = await fetchLatestBlocks(30); - // setStats(statsData); - // setLatestBlocks(latestBlocksData); + const recipients = await getRecentTransactionAccounts(); + console.log(recipients); + // setLatestNotifications(recipients); }; + + // Polling function + const intervalId = setInterval(fetchData, 30000); // 30000 ms = 30 seconds + + // Fetch data immediately on component mount fetchData(); + + // Clear interval on component unmount + return () => clearInterval(intervalId); }, []); return ( @@ -94,14 +102,14 @@ export default function Explorer() { Previous Page )} - {page * size < total && ( + {/* {page * size < total && ( - )} + )} */} );