Skip to content

Commit 229d11d

Browse files
committed
chore(demo): remove E2E masking utility
1 parent 3b51fba commit 229d11d

16 files changed

Lines changed: 34 additions & 64 deletions

File tree

.github/actions/setup-demo/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ runs:
3434
echo "VITE_ONESIGNAL_APP_ID=${{ inputs.onesignal-app-id }}" > .env
3535
echo "VITE_ONESIGNAL_API_KEY=${{ inputs.onesignal-api-key }}" >> .env
3636
echo "VITE_ONESIGNAL_ANDROID_CHANNEL_ID=7ec2ece9-c538-4656-9516-1316f48a005c" >> .env
37-
echo "VITE_E2E_MODE=true" >> .env
3837
3938
- name: Install and set up demo
4039
shell: bash

examples/build.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,8 @@ examples/
274274
│ │ ├── CustomEventsSection.tsx
275275
│ │ ├── LocationSection.tsx
276276
│ │ └── LiveActivitySection.tsx
277-
│ ├── theme/
278-
│ │ └── variables.css
279-
│ └── utils/
280-
│ └── maskValue.ts # E2E_MODE bullet masking helper
277+
│ └── theme/
278+
│ └── variables.css
281279
├── android/ # Capacitor Android project
282280
└── ios/
283281
└── App/

examples/demo/.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
VITE_ONESIGNAL_APP_ID=your_onesignal_app_id
22
VITE_ONESIGNAL_API_KEY=your_rest_api_key
3-
VITE_ONESIGNAL_ANDROID_CHANNEL_ID=
4-
VITE_E2E_MODE=false
3+
VITE_ONESIGNAL_ANDROID_CHANNEL_ID=

examples/demo/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ cp .env.example .env
3131
VITE_ONESIGNAL_APP_ID=<your_app_id>
3232
VITE_ONESIGNAL_API_KEY=<your_rest_api_key>
3333
VITE_ONESIGNAL_ANDROID_CHANNEL_ID=
34-
VITE_E2E_MODE=false
3534
```
3635

3736
---

examples/demo/src/components/sections/AppSection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { IonToggle } from '@ionic/react';
22
import type { FC } from 'react';
33

4-
import { maskValue } from '../../utils/maskValue';
54
import SectionCard from '../SectionCard';
65

76
interface AppSectionProps {
@@ -24,7 +23,7 @@ const AppSection: FC<AppSectionProps> = ({
2423
<div className="kv-row">
2524
<span>App ID</span>
2625
<span className="id-value" data-testid="app_id_value">
27-
{maskValue(appId)}
26+
{appId}
2827
</span>
2928
</div>
3029
</div>

examples/demo/src/components/sections/PushSection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { IonToggle } from '@ionic/react';
22
import type { FC } from 'react';
33

4-
import { maskValue } from '../../utils/maskValue';
54
import ActionButton from '../ActionButton';
65
import SectionCard from '../SectionCard';
76

@@ -27,7 +26,7 @@ const PushSection: FC<PushSectionProps> = ({
2726
<div className="kv-row">
2827
<span>Push ID</span>
2928
<span className="id-value" data-testid="push_id_value">
30-
{maskValue(pushSubscriptionId ?? '—')}
29+
{pushSubscriptionId ?? '—'}
3130
</span>
3231
</div>
3332
<div className="divider" />

examples/demo/src/hooks/useOneSignal.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ function initOneSignal(): void {
5959
if (storedExternalUserId) {
6060
void OneSignal.login(storedExternalUserId);
6161
}
62-
63-
console.log(`OneSignal initialized with app ID: ${RESOLVED_APP_ID}`);
6462
}
6563
initOneSignal();
6664

@@ -91,6 +89,7 @@ export type UseOneSignalReturn = {
9189
consentRequired: boolean;
9290
privacyConsentGiven: boolean;
9391
externalUserId: string | undefined;
92+
oneSignalId: string | undefined;
9493
pushSubscriptionId: string | undefined;
9594
isPushEnabled: boolean;
9695
hasNotificationPermission: boolean;
@@ -151,6 +150,7 @@ export function useOneSignal(): UseOneSignalReturn {
151150
preferences.getConsentGiven(),
152151
);
153152
const [externalUserId, setExternalUserId] = useState<string | undefined>(undefined);
153+
const [oneSignalId, setOneSignalId] = useState<string | undefined>(undefined);
154154
const [pushSubscriptionId, setPushSubscriptionId] = useState<string | undefined>(undefined);
155155
const [isPushEnabled, setIsPushEnabled] = useState(false);
156156
const [hasNotificationPermission, setHasNotificationPermission] = useState(false);
@@ -208,22 +208,6 @@ export function useOneSignal(): UseOneSignalReturn {
208208

209209
const handleNotificationClick = (e: NotificationClickEvent) => {
210210
console.log(`Notification click: ${e.notification.title ?? ''}`);
211-
// Persist to localStorage so cold-start clicks are still inspectable
212-
// after the Safari Web Inspector reattaches to the WKWebView.
213-
try {
214-
const existing = JSON.parse(localStorage.getItem('lastNotificationClicks') ?? '[]');
215-
existing.push({
216-
notificationId: e.notification.notificationId,
217-
title: e.notification.title ?? null,
218-
body: e.notification.body ?? null,
219-
actionId: e.result.actionId ?? null,
220-
url: e.result.url ?? null,
221-
receivedAt: new Date().toISOString(),
222-
});
223-
localStorage.setItem('lastNotificationClicks', JSON.stringify(existing.slice(-20)));
224-
} catch (err) {
225-
console.warn('Failed to persist notification click to localStorage', err);
226-
}
227211
};
228212

229213
const handleForegroundWillDisplay = (e: NotificationWillDisplayEvent) => {
@@ -257,6 +241,8 @@ export function useOneSignal(): UseOneSignalReturn {
257241
`User changed: onesignalId=${nextOnesignalId ?? 'null'}, externalId=${event.current.externalId ?? 'null'}`,
258242
);
259243

244+
setOneSignalId(nextOnesignalId ?? undefined);
245+
260246
if (nextOnesignalId === null) return;
261247
void fetchUserDataFromApi();
262248
};
@@ -283,6 +269,7 @@ export function useOneSignal(): UseOneSignalReturn {
283269
if (cancelled) return;
284270

285271
setExternalUserId(externalId ?? preferences.getExternalUserId() ?? undefined);
272+
setOneSignalId(initialOnesignalId ?? undefined);
286273
setPushSubscriptionId(pushId ?? undefined);
287274
setIsPushEnabled(pushOptedIn);
288275
setHasNotificationPermission(hasPerm);
@@ -550,6 +537,7 @@ export function useOneSignal(): UseOneSignalReturn {
550537
consentRequired,
551538
privacyConsentGiven,
552539
externalUserId,
540+
oneSignalId,
553541
pushSubscriptionId,
554542
isPushEnabled,
555543
hasNotificationPermission,

examples/demo/src/pages/HomeScreen.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
.kv-card .kv-row .id-value {
151151
font-size: var(--font-size-body-small);
152152
font-family: monospace;
153+
user-select: all;
154+
-webkit-user-select: all;
153155
}
154156

155157
.divider {

examples/demo/src/services/OneSignalApiService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class OneSignalApiService {
8282
...extra,
8383
};
8484

85-
const maxAttempts = 3;
85+
const maxAttempts = 5;
86+
const backoffMs = (n: number) => 2_000 * 2 ** (n - 1);
8687

8788
// Retry on `invalid_player_ids` to absorb the brief race where the
8889
// subscription has been created locally but is not yet visible to the
@@ -106,7 +107,7 @@ class OneSignalApiService {
106107
const invalidIds = response.data?.errors?.invalid_player_ids;
107108
if (Array.isArray(invalidIds) && invalidIds.length > 0) {
108109
if (attempt < maxAttempts) {
109-
await new Promise((resolve) => setTimeout(resolve, 3_000 * attempt));
110+
await new Promise((resolve) => setTimeout(resolve, backoffMs(attempt)));
110111
continue;
111112
}
112113
console.error(

examples/demo/src/utils/maskValue.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)