Skip to content

Commit

Permalink
fix: decrypt content
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Nov 6, 2024
1 parent 7a42fde commit 41b4299
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions pages/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import Screen from "~/components/Screen";
import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";

import { Nip47Notification } from "@getalby/sdk/dist/NWCClient";
import * as Device from "expo-device";
import * as ExpoNotifications from "expo-notifications";
import { useAppStore } from "~/lib/state/appStore";


ExpoNotifications.setNotificationHandler({
handleNotification: async (notification) => {
Expand All @@ -15,17 +18,39 @@ ExpoNotifications.setNotificationHandler({
if (!notification.request.content.data.isLocal) {
console.log("🏠️ Local notification", notification.request.content);

Check failure on line 19 in pages/Notifications.tsx

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

ExpoNotifications.scheduleNotificationAsync({
content: {
title: 'Decrypted content',
body: "test",
data: {
...notification.request.content.data,
isLocal: true,
}
},
trigger: null
});
const encryptedData = notification.request.content.data.content;
const nwcClient = useAppStore.getState().nwcClient!;

try {
console.log("🔴", encryptedData, nwcClient?.secret);

Check failure on line 25 in pages/Notifications.tsx

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement
const decryptedContent = await nwcClient.decrypt(
nwcClient?.walletPubkey!,
encryptedData,
);
console.log("🔓️ decrypted data", decryptedContent);

Check failure on line 30 in pages/Notifications.tsx

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement
const nip47Notification = JSON.parse(decryptedContent) as Nip47Notification;
console.log("deserialized", nip47Notification);

Check failure on line 32 in pages/Notifications.tsx

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

if (nip47Notification.notification_type === "payment_received") {
ExpoNotifications.scheduleNotificationAsync({
content: {
title: `You just received ${Math.floor(nip47Notification.notification.amount / 1000)} sats`,
body: nip47Notification.notification.description,
data: {
...notification.request.content.data,
isLocal: true,
}
},
trigger: null
});
}



} catch (e) {
console.error("Failed to parse decrypted event content", e);
return;
}
}

return {
Expand Down

0 comments on commit 41b4299

Please sign in to comment.