diff --git a/.gitignore b/.gitignore index d8f729d..7197148 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,7 @@ yarn-error.* # typescript *.tsbuildinfo -ios -android +/ios +/android google-services.json diff --git a/app.config.js b/app.config.js index 63342ce..32537c2 100644 --- a/app.config.js +++ b/app.config.js @@ -1,4 +1,4 @@ -import withMessagingServicePlugin from "./plugins/withMessageServicePlugin"; +import withMessagingServicePlugin from "./plugins/android/withMessageServicePlugin"; export default ({ config }) => { return { @@ -16,14 +16,14 @@ export default ({ config }) => { [ withMessagingServicePlugin, { - androidFMSFilePath: "./assets/MessagingService.kt", + androidFMSFilePath: "./assets/android/MessagingService.kt", }, ], [ "expo-notification-service-extension-plugin", { mode: "production", - iosNSEFilePath: "./assets/NotificationService.m", + iosNSEFilePath: "./assets/ios/NotificationService.m", }, ], [ diff --git a/assets/MessagingService.kt b/assets/android/MessagingService.kt similarity index 100% rename from assets/MessagingService.kt rename to assets/android/MessagingService.kt diff --git a/assets/NotificationService.m b/assets/ios/NotificationService.m similarity index 100% rename from assets/NotificationService.m rename to assets/ios/NotificationService.m diff --git a/lib/walletInfo.ts b/lib/walletInfo.ts index 4c1f361..c84b72c 100644 --- a/lib/walletInfo.ts +++ b/lib/walletInfo.ts @@ -4,6 +4,9 @@ import { SUITE_NAME } from "~/lib/constants"; let UserDefaults: any; let SharedPreferences: any; +// this is done because accessing values stored from expo-secure-store +// is quite difficult and we do not wish to complicate the notification +// service extension (ios) or messaging service (android) if (Platform.OS === "ios") { UserDefaults = require("@alevy97/react-native-userdefaults/src/ReactNativeUserDefaults.ios").default; diff --git a/plugins/withMessageServicePlugin.js b/plugins/android/withMessageServicePlugin.js similarity index 100% rename from plugins/withMessageServicePlugin.js rename to plugins/android/withMessageServicePlugin.js diff --git a/services/Notifications.ts b/services/Notifications.ts index 74355af..7226a11 100644 --- a/services/Notifications.ts +++ b/services/Notifications.ts @@ -21,62 +21,63 @@ export async function registerForPushNotificationsAsync(): Promise< }); } - if (Device.isDevice) { - const { status: existingStatus } = - await ExpoNotifications.getPermissionsAsync(); - let finalStatus = existingStatus; - if (existingStatus !== "granted") { - const { status } = await ExpoNotifications.requestPermissionsAsync(); - finalStatus = status; - } - if (finalStatus === "undetermined") { - return null; - } - if (finalStatus === "denied") { - if (existingStatus === "denied") { - errorToast(new Error("Enable app notifications in device settings")); - } - return false; - } - const projectId = - Constants?.expoConfig?.extra?.eas?.projectId ?? - Constants?.easConfig?.projectId; - if (!projectId) { - errorToast(new Error("Project ID not found")); + if (!Device.isDevice) { + errorToast("Must use physical device for push notifications"); + return false; + } + + const { status: existingStatus } = + await ExpoNotifications.getPermissionsAsync(); + let finalStatus = existingStatus; + if (existingStatus !== "granted") { + const { status } = await ExpoNotifications.requestPermissionsAsync(); + finalStatus = status; + } + if (finalStatus === "undetermined") { + return null; + } + if (finalStatus === "denied") { + if (existingStatus === "denied") { + errorToast(new Error("Enable app notifications in device settings")); } - try { - const pushToken = ( - await ExpoNotifications.getExpoPushTokenAsync({ - projectId, - }) - ).data; + return false; + } + const projectId = + Constants?.expoConfig?.extra?.eas?.projectId ?? + Constants?.easConfig?.projectId; + if (!projectId) { + errorToast(new Error("Project ID not found")); + } + try { + const pushToken = ( + await ExpoNotifications.getExpoPushTokenAsync({ + projectId, + }) + ).data; - useAppStore.getState().setExpoPushToken(pushToken); + useAppStore.getState().setExpoPushToken(pushToken); - const wallets = useAppStore.getState().wallets; + const wallets = useAppStore.getState().wallets; - for (let i = 0; i < wallets.length; i++) { - const wallet = wallets[i]; - if (!(wallet.nwcCapabilities || []).includes("notifications")) { - Toast.show({ - type: "info", - text1: `${wallet.name} does not have notifications capability`, - }); - continue; - } - await registerWalletNotifications( - wallet.nostrWalletConnectUrl ?? "", - i, - wallet.name, - ); + for (let i = 0; i < wallets.length; i++) { + const wallet = wallets[i]; + if (!(wallet.nwcCapabilities || []).includes("notifications")) { + Toast.show({ + type: "info", + text1: `${wallet.name} does not have notifications capability`, + }); + continue; } - - return true; - } catch (error) { - errorToast(error); + await registerWalletNotifications( + wallet.nostrWalletConnectUrl ?? "", + i, + wallet.name, + ); } - } else { - errorToast("Must use physical device for push notifications"); + + return true; + } catch (error) { + errorToast(error); } return false;