Skip to content

Commit

Permalink
chore: add comments and organize code
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 21, 2025
1 parent 57b7567 commit fb64bcf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ yarn-error.*
# typescript
*.tsbuildinfo

ios
android
/ios
/android

google-services.json
6 changes: 3 additions & 3 deletions app.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import withMessagingServicePlugin from "./plugins/withMessageServicePlugin";
import withMessagingServicePlugin from "./plugins/android/withMessageServicePlugin";

export default ({ config }) => {
return {
Expand All @@ -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",
},
],
[
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions lib/walletInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
101 changes: 51 additions & 50 deletions services/Notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fb64bcf

Please sign in to comment.