@dubsdotapp/expo 0.2.65 → 0.2.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.plugin.js +53 -38
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +12 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +0 -3
- package/src/hooks/usePushNotifications.ts +18 -17
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export const DEFAULT_BASE_URL = 'https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1';
|
|
2
2
|
|
|
3
|
-
/** Expo project ID for the Dubs platform push notification infrastructure. */
|
|
4
|
-
export const DUBS_EXPO_PROJECT_ID = 'aaca4fc9-64be-46b2-9be2-4175cb0f59a2';
|
|
5
|
-
|
|
6
3
|
export const DEFAULT_RPC_URL = 'https://api.mainnet-beta.solana.com';
|
|
7
4
|
|
|
8
5
|
export type DubsNetwork = 'devnet' | 'mainnet-beta';
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { useState, useCallback, useRef, useMemo, useEffect } from 'react';
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
3
|
import { useDubs } from '../provider';
|
|
4
|
-
import { DUBS_EXPO_PROJECT_ID } from '../constants';
|
|
5
4
|
|
|
6
5
|
export interface PushNotificationStatus {
|
|
7
6
|
/** Whether push notifications are enabled in the SDK configuration */
|
|
8
7
|
enabled: boolean;
|
|
9
8
|
/** Whether notification permission has been granted */
|
|
10
9
|
hasPermission: boolean;
|
|
11
|
-
/** The
|
|
10
|
+
/** The push token (native FCM/APNs), if registered */
|
|
11
|
+
pushToken: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use pushToken instead. Kept for backwards compatibility.
|
|
14
|
+
*/
|
|
12
15
|
expoPushToken: string | null;
|
|
13
16
|
/** Whether a registration operation is in progress */
|
|
14
17
|
loading: boolean;
|
|
@@ -32,7 +35,7 @@ export function usePushNotifications(): PushNotificationStatus {
|
|
|
32
35
|
const { client, appName, pushEnabled } = useDubs();
|
|
33
36
|
const channelId = useMemo(() => appName.toLowerCase().replace(/[^a-z0-9-]/g, ''), [appName]);
|
|
34
37
|
const [hasPermission, setHasPermission] = useState(false);
|
|
35
|
-
const [
|
|
38
|
+
const [pushToken, setPushToken] = useState<string | null>(null);
|
|
36
39
|
const [loading, setLoading] = useState(false);
|
|
37
40
|
const [error, setError] = useState<Error | null>(null);
|
|
38
41
|
const registering = useRef(false);
|
|
@@ -104,12 +107,10 @@ export function usePushNotifications(): PushNotificationStatus {
|
|
|
104
107
|
|
|
105
108
|
setHasPermission(true);
|
|
106
109
|
|
|
107
|
-
// Get
|
|
108
|
-
const tokenResult = await Notifications.
|
|
109
|
-
projectId: DUBS_EXPO_PROJECT_ID,
|
|
110
|
-
});
|
|
110
|
+
// Get native device push token (FCM on Android, APNs on iOS)
|
|
111
|
+
const tokenResult = await Notifications.getDevicePushTokenAsync();
|
|
111
112
|
const token = tokenResult.data;
|
|
112
|
-
|
|
113
|
+
setPushToken(token);
|
|
113
114
|
|
|
114
115
|
// Register with server
|
|
115
116
|
await registerTokenWithServer(token);
|
|
@@ -131,14 +132,14 @@ export function usePushNotifications(): PushNotificationStatus {
|
|
|
131
132
|
}, [getNotificationsModule, registerTokenWithServer, setupAndroidChannels]);
|
|
132
133
|
|
|
133
134
|
const unregister = useCallback(async () => {
|
|
134
|
-
if (!
|
|
135
|
+
if (!pushToken) return;
|
|
135
136
|
try {
|
|
136
|
-
await client.unregisterPushToken(
|
|
137
|
-
|
|
137
|
+
await client.unregisterPushToken(pushToken);
|
|
138
|
+
setPushToken(null);
|
|
138
139
|
} catch (err) {
|
|
139
140
|
console.error('[usePushNotifications] Unregister error:', err);
|
|
140
141
|
}
|
|
141
|
-
}, [client,
|
|
142
|
+
}, [client, pushToken]);
|
|
142
143
|
|
|
143
144
|
const restoreIfGranted = useCallback(async () => {
|
|
144
145
|
if (!pushEnabled) return;
|
|
@@ -149,14 +150,13 @@ export function usePushNotifications(): PushNotificationStatus {
|
|
|
149
150
|
const { status } = await Notifications.getPermissionsAsync();
|
|
150
151
|
if (status !== 'granted') return;
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
153
|
+
// Get native device push token (FCM on Android, APNs on iOS)
|
|
154
|
+
const tokenResult = await Notifications.getDevicePushTokenAsync();
|
|
155
155
|
const token = tokenResult.data;
|
|
156
156
|
|
|
157
157
|
// Register with server — only mark as enabled if this succeeds
|
|
158
158
|
await registerTokenWithServer(token);
|
|
159
|
-
|
|
159
|
+
setPushToken(token);
|
|
160
160
|
setHasPermission(true);
|
|
161
161
|
setupAndroidChannels(Notifications);
|
|
162
162
|
} catch (err) {
|
|
@@ -177,7 +177,8 @@ export function usePushNotifications(): PushNotificationStatus {
|
|
|
177
177
|
return {
|
|
178
178
|
enabled: pushEnabled,
|
|
179
179
|
hasPermission,
|
|
180
|
-
|
|
180
|
+
pushToken,
|
|
181
|
+
expoPushToken: pushToken, // backwards compat
|
|
181
182
|
loading,
|
|
182
183
|
error,
|
|
183
184
|
register,
|