@dubsdotapp/expo 0.2.60 → 0.2.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dubsdotapp/expo",
3
- "version": "0.2.60",
3
+ "version": "0.2.61",
4
4
  "description": "React Native SDK for the Dubs betting platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -42,17 +42,6 @@ export function usePushNotifications(): PushNotificationStatus {
42
42
  }
43
43
  }, []);
44
44
 
45
- // Check existing permission on mount so UI reflects current state
46
- useEffect(() => {
47
- const Notifications = getNotificationsModule();
48
- if (!Notifications) return;
49
- Notifications.getPermissionsAsync()
50
- .then(({ status }: { status: string }) => {
51
- if (status === 'granted') setHasPermission(true);
52
- })
53
- .catch(() => {});
54
- }, [getNotificationsModule]);
55
-
56
45
  const getDeviceName = useCallback((): string | null => {
57
46
  try {
58
47
  const Device = require('expo-device');
@@ -153,21 +142,29 @@ export function usePushNotifications(): PushNotificationStatus {
153
142
  const { status } = await Notifications.getPermissionsAsync();
154
143
  if (status !== 'granted') return;
155
144
 
156
- setHasPermission(true);
157
-
158
145
  const tokenResult = await Notifications.getExpoPushTokenAsync();
159
146
  const token = tokenResult.data;
160
- setExpoPushToken(token);
161
147
 
162
- // Re-register silently
148
+ // Register with server — only mark as enabled if this succeeds
163
149
  await registerTokenWithServer(token);
150
+ setExpoPushToken(token);
151
+ setHasPermission(true);
164
152
  setupAndroidChannels(Notifications);
165
153
  } catch (err) {
166
- // Silent failurethis is a background restore
154
+ // Server registration failed don't show as enabled
155
+ setHasPermission(false);
167
156
  console.log('[usePushNotifications] Restore skipped:', err instanceof Error ? err.message : err);
168
157
  }
169
158
  }, [getNotificationsModule, registerTokenWithServer, setupAndroidChannels]);
170
159
 
160
+ // On mount, restore push state only if token is actually registered server-side
161
+ const didMount = useRef(false);
162
+ useEffect(() => {
163
+ if (didMount.current) return;
164
+ didMount.current = true;
165
+ restoreIfGranted();
166
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
167
+
171
168
  return {
172
169
  hasPermission,
173
170
  expoPushToken,