Skip to content

Commit d832799

Browse files
Fix: Remove verification status step during initialization
1 parent 992a04b commit d832799

File tree

8 files changed

+38
-79
lines changed

8 files changed

+38
-79
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@
8383
],
8484
"dependencies": {
8585
"pubsub-js": "^1.9.4",
86-
"@sirenapp/js-sdk": "^1.1.0"
86+
"@sirenapp/js-sdk": "^1.2.3"
8787
}
8888
}

src/components/sirenInbox.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ const {
2121
events,
2222
TOKEN_VERIFICATION_PENDING,
2323
MAXIMUM_ITEMS_PER_FETCH,
24-
VerificationStatus,
25-
EventType,
26-
errorMap
24+
EventType
2725
} = Constants;
2826
const { applyTheme, isNonEmptyArray, updateNotifications } = CommonUtils;
2927

@@ -105,7 +103,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
105103
itemsPerFetch > MAXIMUM_ITEMS_PER_FETCH ? MAXIMUM_ITEMS_PER_FETCH : itemsPerFetch
106104
);
107105

108-
const { siren, verificationStatus, id } = useSirenContext();
106+
const { siren, id } = useSirenContext();
109107

110108
const { deleteById, deleteByDate, markAllAsViewed } = useSiren();
111109

@@ -130,15 +128,10 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
130128

131129
useEffect(() => {
132130
// Initialize Siren SDK and start polling notifications
133-
if (verificationStatus === VerificationStatus.SUCCESS && siren) {
131+
if (siren)
134132
initialize();
135-
} else if(verificationStatus === VerificationStatus.FAILED) {
136-
setIsError(true);
137-
setIsLoading(false);
138-
setNotifications([]);
139-
if (onError) onError(errorMap.INVALID_CREDENTIALS);
140-
}
141-
}, [siren, verificationStatus]);
133+
134+
}, [siren]);
142135

143136
useEffect(() => {
144137
if (eventListenerData) {
@@ -193,8 +186,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
193186
if (isNonEmptyArray(allNotifications))
194187
notificationParams.start = allNotifications[0].createdAt;
195188

196-
if (verificationStatus === VerificationStatus.SUCCESS)
197-
siren?.startRealTimeFetch({eventType: EventType.NOTIFICATION, params: notificationParams});
189+
siren?.startRealTimeFetch({eventType: EventType.NOTIFICATION, params: notificationParams});
198190
}
199191
};
200192

@@ -283,8 +275,8 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
283275
if (isNonEmptyArray(allNotifications))
284276
notificationParams.start = allNotifications[0].createdAt;
285277

286-
if (verificationStatus === VerificationStatus.SUCCESS)
287-
siren?.startRealTimeFetch({eventType: EventType.NOTIFICATION, params:notificationParams});
278+
279+
siren?.startRealTimeFetch({eventType: EventType.NOTIFICATION, params:notificationParams});
288280
} catch (err) {
289281
setIsLoading(false);
290282
setIsError(true);

src/components/sirenInboxIcon.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@ import { useSirenContext } from './sirenProvider';
88
import type { SirenInboxIconProps } from '../types';
99
import { CommonUtils, Constants } from '../utils';
1010

11-
const {
12-
ThemeMode,
13-
defaultBadgeStyle,
14-
eventTypes,
15-
events,
16-
defaultStyles,
17-
EventType,
18-
VerificationStatus,
19-
errorMap
20-
} = Constants;
11+
const { ThemeMode, defaultBadgeStyle, eventTypes, events, defaultStyles, EventType } = Constants;
2112
const { logger } = CommonUtils;
2213

2314
/**
@@ -51,7 +42,7 @@ const SirenInboxIcon = (props: SirenInboxIconProps) => {
5142
onError = () => null
5243
} = props;
5344

54-
const { siren, verificationStatus, id } = useSirenContext();
45+
const { siren, id } = useSirenContext();
5546

5647
const [unviewedCount, seUnviewedCount] = useState<number>(0);
5748

@@ -88,10 +79,8 @@ const SirenInboxIcon = (props: SirenInboxIconProps) => {
8879
}, []);
8980

9081
useEffect(() => {
91-
if (verificationStatus !== VerificationStatus.PENDING && siren) initialize();
92-
else if (verificationStatus === VerificationStatus.FAILED && onError)
93-
onError(errorMap.MISSING_PARAMETER);
94-
}, [siren, verificationStatus]);
82+
if (siren) initialize();
83+
}, [siren]);
9584

9685
useEffect(() => {
9786
if (unviewedCount > 0) logger.info(`unviewed notification count : ${unviewedCount}`);
@@ -103,7 +92,7 @@ const SirenInboxIcon = (props: SirenInboxIconProps) => {
10392
const unViewed: UnviewedCountReturnResponse | null =
10493
await siren.fetchUnviewedNotificationsCount();
10594

106-
siren.startRealTimeFetch({eventType: EventType.UNVIEWED_COUNT});
95+
siren.startRealTimeFetch({ eventType: EventType.UNVIEWED_COUNT });
10796
if (unViewed?.data) seUnviewedCount(unViewed.data?.unviewedCount || 0);
10897
if (unViewed?.error) onError(unViewed?.error);
10998
}

src/components/sirenProvider.tsx

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ import {
1717
eventTypes,
1818
IN_APP_RECIPIENT_UNAUTHENTICATED,
1919
MAXIMUM_RETRY_COUNT,
20-
VerificationStatus,
2120
EventType
2221
} from '../utils/constants';
2322
import { useSiren } from '../utils';
2423

2524
type SirenContextProp = {
2625
siren: Siren | null;
27-
verificationStatus: VerificationStatus;
2826
id: string;
2927
};
3028

@@ -35,7 +33,6 @@ interface SirenProvider {
3533

3634
export const SirenContext = createContext<SirenContextProp>({
3735
siren: null,
38-
verificationStatus: VerificationStatus.PENDING,
3936
id: ''
4037
});
4138

@@ -45,7 +42,6 @@ export const SirenContext = createContext<SirenContextProp>({
4542
* @example
4643
* const {
4744
* siren,
48-
* verificationStatus
4945
* } = useSirenContext();
5046
*
5147
* @returns {SirenContextProp} The Siren notifications context.
@@ -56,7 +52,7 @@ export const useSirenContext = (): SirenContextProp => useContext(SirenContext);
5652
* Provides a React context for Siren notifications, making Siren SDK functionality
5753
* available throughout your React application.
5854
*
59-
* `SirenProvider` initializes the Siren SDK with given configuration and manages the state for siren and verificationStatus.
55+
* `SirenProvider` initializes the Siren SDK with given configuration and manages the state for siren.
6056
*
6157
* @component
6258
* @example
@@ -80,17 +76,12 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
8076

8177
const [id] = useState(generateUniqueId());
8278
const [siren, setSiren] = useState<Siren | null>(null);
83-
const [verificationStatus, setVerificationStatus] = useState<VerificationStatus>(
84-
VerificationStatus.PENDING
85-
);
8679

8780
useEffect(() => {
8881
if (config?.recipientId && config?.userToken) {
8982
stopRealTimeFetch();
9083
sendResetDataEvents();
9184
initialize();
92-
} else {
93-
setVerificationStatus(VerificationStatus.FAILED);
9485
}
9586
}, [config]);
9687

@@ -108,7 +99,10 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
10899
};
109100

110101
PubSub.publish(`${events.NOTIFICATION_COUNT_EVENT}${id}`, JSON.stringify(updateCountPayload));
111-
PubSub.publish(`${events.NOTIFICATION_LIST_EVENT}${id}`, JSON.stringify(updateNotificationPayload));
102+
PubSub.publish(
103+
`${events.NOTIFICATION_LIST_EVENT}${id}`,
104+
JSON.stringify(updateNotificationPayload)
105+
);
112106
};
113107

114108
const onNewNotificationEvent = (responseData: NotificationDataType[]) => {
@@ -135,14 +129,11 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
135129

136130
if (Array.isArray(responseData) && isNonEmptyArray(responseData))
137131
onNewNotificationEvent(responseData);
138-
139132
};
140133
const handleUnviewedCountEvent = (response: UnviewedCountApiResponse) => {
141134
const responseData = response?.data;
142135

143-
if (responseData && 'totalUnviewed' in responseData)
144-
onTotalUnviewedCountEvent(response);
145-
136+
if (responseData && 'totalUnviewed' in responseData) onTotalUnviewedCountEvent(response);
146137
};
147138
const onEventReceive = (
148139
response: NotificationsApiResponse | UnviewedCountApiResponse = {},
@@ -157,11 +148,8 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
157148
break;
158149
}
159150
};
160-
const onStatusChange = (status: VerificationStatus) => {
161-
setVerificationStatus(status);
162-
};
163151

164-
const actionCallbacks = { onEventReceive, onStatusChange };
152+
const actionCallbacks = { onEventReceive };
165153

166154
const getDataParams = () => {
167155
return {
@@ -173,11 +161,7 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
173161
};
174162

175163
const retryVerification = (error: SirenErrorType) => {
176-
if (
177-
error.Code === IN_APP_RECIPIENT_UNAUTHENTICATED &&
178-
retryCount < MAXIMUM_RETRY_COUNT &&
179-
verificationStatus === VerificationStatus.FAILED
180-
)
164+
if (error.Code === IN_APP_RECIPIENT_UNAUTHENTICATED && retryCount < MAXIMUM_RETRY_COUNT)
181165
setTimeout(() => {
182166
initialize();
183167
retryCount++;
@@ -188,7 +172,6 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
188172

189173
// Function to initialize the Siren SDK and fetch notifications
190174
const initialize = (): void => {
191-
setVerificationStatus(VerificationStatus.PENDING);
192175
const dataParams: InitConfigType = getDataParams();
193176
const siren = new Siren(dataParams);
194177

@@ -199,8 +182,7 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
199182
<SirenContext.Provider
200183
value={{
201184
id,
202-
siren,
203-
verificationStatus
185+
siren
204186
}}
205187
>
206188
{children}

src/utils/sirenHook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const useSiren = () => {
2727

2828
const markAsReadByDate = async (untilDate: string) => {
2929
if (siren && untilDate) {
30-
const response = await siren?.markAsReadByDate(untilDate);
30+
const response = await siren?.markAsReadByDate({startDate: untilDate});
3131

3232
if (response?.data) {
3333
const payload = { action: eventTypes.MARK_ALL_AS_READ };
@@ -62,7 +62,7 @@ const useSiren = () => {
6262

6363
const deleteByDate = async (untilDate: string) => {
6464
if (siren && untilDate) {
65-
const response = await siren.deleteByDate(untilDate);
65+
const response = await siren.deleteByDate({startDate: untilDate});
6666

6767
if (response?.data) {
6868
const payload = { action: eventTypes.DELETE_ALL_ITEM };

tests/components/sirenNotificationIcon.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { Siren } from '@sirenapp/js-sdk';
66
import { SirenInboxIcon } from '../../src';
77
import type { Theme } from '../../src/types';
88
import * as sirenProvider from '../../src/components/sirenProvider';
9-
import {VerificationStatus} from '../../src/utils/constants'
109

1110
const UnviewedCountReturnResponse = {
1211
data: {
@@ -39,7 +38,6 @@ describe('SirenInboxIcon', () => {
3938
deleteById: jest.fn(),
4039
deleteByDate: jest.fn(),
4140
markAllAsViewed: jest.fn(),
42-
verifyToken: jest.fn(),
4341
fetchUnviewedNotificationsCount: jest.fn(async () => UnviewedCountReturnResponse),
4442
fetchAllNotifications: jest.fn(),
4543
startRealTimeFetch: jest.fn(),
@@ -48,7 +46,7 @@ describe('SirenInboxIcon', () => {
4846

4947
jest.spyOn(sirenProvider, 'useSirenContext').mockReturnValue({
5048
siren: mockSiren as Siren,
51-
verificationStatus: VerificationStatus.PENDING
49+
id: ''
5250
});
5351

5452
it('renders without crashing', () => {

tests/utils/sirenHook.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Siren } from '@sirenapp/js-sdk';
22

33
import { useSiren } from '../../src';
44
import * as sirenProvider from '../../src/components/sirenProvider';
5-
import {VerificationStatus} from '../../src/utils/constants'
65

76
const Response = {
87
data: {
@@ -78,7 +77,6 @@ describe('useSiren hook', () => {
7877
deleteById: jest.fn(async () => ActionResponse),
7978
deleteByDate: jest.fn(async () => ActionResponse),
8079
markAllAsViewed: jest.fn(async () => MarkAsViewedResponse),
81-
verifyToken: jest.fn(),
8280
fetchUnviewedNotificationsCount: jest.fn(),
8381
fetchAllNotifications: jest.fn(),
8482
startRealTimeFetch: jest.fn(),
@@ -90,7 +88,7 @@ describe('useSiren hook', () => {
9088
// Mock useSirenContext
9189
jest.spyOn(sirenProvider, 'useSirenContext').mockReturnValue({
9290
siren: mockSiren as Siren,
93-
verificationStatus: VerificationStatus.SUCCESS
91+
id: ''
9492
});
9593

9694
const { markAsReadById } = useSiren();
@@ -103,7 +101,7 @@ describe('useSiren hook', () => {
103101
it('should call siren.markAsReadByDate and update notifications list when siren exists and untilDate is provided', async () => {
104102
jest.spyOn(sirenProvider, 'useSirenContext').mockReturnValue({
105103
siren: mockSiren as Siren,
106-
verificationStatus: VerificationStatus.SUCCESS
104+
id: ''
107105
});
108106

109107
const { markAsReadByDate } = useSiren();
@@ -118,7 +116,7 @@ describe('useSiren hook', () => {
118116

119117
jest.spyOn(sirenProvider, 'useSirenContext').mockReturnValue({
120118
siren: mockSiren as Siren,
121-
verificationStatus: VerificationStatus.SUCCESS
119+
id: ''
122120
});
123121

124122
const { deleteById } = useSiren();
@@ -132,7 +130,7 @@ describe('useSiren hook', () => {
132130

133131
jest.spyOn(sirenProvider, 'useSirenContext').mockReturnValue({
134132
siren: mockSiren as Siren,
135-
verificationStatus: VerificationStatus.SUCCESS
133+
id: ''
136134
});
137135

138136
const { deleteByDate } = useSiren();
@@ -147,7 +145,7 @@ describe('useSiren hook', () => {
147145

148146
jest.spyOn(sirenProvider, 'useSirenContext').mockReturnValue({
149147
siren: mockSiren as Siren,
150-
verificationStatus: VerificationStatus.SUCCESS
148+
id: ''
151149
});
152150

153151
const { markAllAsViewed } = useSiren();

0 commit comments

Comments
 (0)