From f3718c2f57498443b0bdc7d7a65c1d8aacd1961b Mon Sep 17 00:00:00 2001 From: aman035 Date: Sun, 7 Jul 2024 23:33:02 +0530 Subject: [PATCH] chore: fix dapp --- .../examples/dnode-dapp/package-lock.json | 8 ++--- packages/examples/dnode-dapp/package.json | 2 +- .../src/components/Notification.tsx | 31 +++++++++++++------ .../examples/dnode-dapp/src/utils/push.ts | 2 +- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/examples/dnode-dapp/package-lock.json b/packages/examples/dnode-dapp/package-lock.json index 878fff59c..cbda70b55 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.4", + "@pushprotocol/dnode": "^0.0.5", "@rainbow-me/rainbowkit": "^2.1.3", "@tailwindcss/forms": "^0.5.7", "@tanstack/react-query": "^5.28.4", @@ -3974,9 +3974,9 @@ } }, "node_modules/@pushprotocol/dnode": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/@pushprotocol/dnode/-/dnode-0.0.4.tgz", - "integrity": "sha512-qaa5RBhXQ3+eBxRDQdGsDxAeTgBl0gohojG4BzGAYKy0jDX0gp2bP8VjvY8pGHDpOC1jMyRp6cZ1cbfPXezIag==", + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/@pushprotocol/dnode/-/dnode-0.0.5.tgz", + "integrity": "sha512-cjf0+lE+GaDBiagFJlyzlvIzfYVvKEDm87LrHAhFeUs842OMh/5txjuEDn53hS1VabPe5IgYHlPclM65OXA13g==", "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 456a715b1..d265edbc0 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.4", + "@pushprotocol/dnode": "^0.0.5", "@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/components/Notification.tsx b/packages/examples/dnode-dapp/src/components/Notification.tsx index 1b6b6f2e8..e5954a8df 100644 --- a/packages/examples/dnode-dapp/src/components/Notification.tsx +++ b/packages/examples/dnode-dapp/src/components/Notification.tsx @@ -10,13 +10,14 @@ const SendNotification: React.FC = () => { const [recipient, setRecipient] = useState(['*']); // State for recipients const [allowNotification, setAllowNotification] = useState(false); const [errorMessage, setErrorMessage] = useState(''); // State for error message + const [sending, setSending] = useState(false); const { isConnected } = useAccount(); const walletClient = useWalletClient(); useEffect(() => { const checkNotificationPermission = async () => { - if (isConnected && walletClient.data) { + if (isConnected && walletClient.data && channel === '') { try { const channelInfo = await getChannelInfo(walletClient.data); if (channelInfo !== null) { @@ -76,19 +77,29 @@ const SendNotification: React.FC = () => { notificationType, recipient ); - const res = await sendNotification( - title, - body, - recipient, - walletClient.data - ); - console.log(res); + + setAllowNotification(false); + setSending(true); + try { + const res = await sendNotification( + title, + body, + recipient, + walletClient.data + ); + setAllowNotification(false); + console.log(res); + } catch (error) { + console.error(error); + } // Reset form fields if needed setTitle(''); setBody(''); setChannel(''); setNotificationType('broadcast'); setRecipient(['*']); + setSending(false); + setAllowNotification(true); }; return ( @@ -181,7 +192,7 @@ const SendNotification: React.FC = () => { > - + {/* */} @@ -222,7 +233,7 @@ const SendNotification: React.FC = () => { : 'bg-gray-300 text-gray-600 cursor-not-allowed' }`} > - Send + {sending ? 'Sending...' : 'Send'} diff --git a/packages/examples/dnode-dapp/src/utils/push.ts b/packages/examples/dnode-dapp/src/utils/push.ts index e6d2d2534..f9477922c 100644 --- a/packages/examples/dnode-dapp/src/utils/push.ts +++ b/packages/examples/dnode-dapp/src/utils/push.ts @@ -2,7 +2,7 @@ import { PushAPI } from '@pushprotocol/dnode'; import { ENV } from '@pushprotocol/dnode/src/lib/constants'; // TODO: Change to dev or stage -const env = ENV.LOCAL; +const env = ENV.DEV; export const sendNotification = async ( title: string,