Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.


## 1.2.2

### Fixed

- Remove the verification status functionality, as verify token calls have been removed from '@sirenapp/js-sdk' to prevent issues caused by multiple calls.


## 1.2.1

### Fixed
Expand Down
7,348 changes: 2,886 additions & 4,462 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"pubsub-js": "^1.9.4",
"@sirenapp/js-sdk": "^1.2.2"
"@sirenapp/js-sdk": "^1.2.3",
"pubsub-js": "^1.9.4"
}
}
17 changes: 4 additions & 13 deletions src/components/SirenPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
mergeStyles,
updateNotifications,
} from "../utils/commonUtils";
import { DEFAULT_WINDOW_TITLE, ERROR_TEXT, errorMap, events, EventType, eventTypes, LIST_EMPTY_TEXT, Tabs, UNREAD_LIST_EMPTY_TEXT, VerificationStatus } from "../utils/constants";
import { DEFAULT_WINDOW_TITLE, ERROR_TEXT, events, EventType, eventTypes, LIST_EMPTY_TEXT, Tabs, UNREAD_LIST_EMPTY_TEXT } from "../utils/constants";
import useSiren from "../utils/sirenHook";

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
deleteByDate,
deleteById,
} = useSiren();
const { siren, verificationStatus, id } = useSirenContext();
const { siren, id } = useSirenContext();
const {hideHeader = false, hideClearAll = false, customHeader, title = DEFAULT_WINDOW_TITLE} = headerProps ?? {};
const [notifications, setNotifications] = useState<NotificationDataType[]>(
[]
Expand Down Expand Up @@ -150,21 +150,12 @@ const SirenPanel: FC<SirenPanelProps> = ({
}
}, [eventListenerData]);

const handleVerificationFailure = () => {
setIsLoading(false);
onError && onError(errorMap?.INVALID_CREDENTIALS);
setError(ERROR_TEXT);
};

useEffect(() => {
if (siren && verificationStatus === VerificationStatus.SUCCESS) {
if (siren) {
!hideBadge && siren.stopRealTimeFetch(EventType.UNVIEWED_COUNT);
fetchNotifications(true);
}
else if(verificationStatus === VerificationStatus.FAILED) {
handleVerificationFailure();
}
}, [siren, verificationStatus, hideBadge, activeTabIndex]);
}, [siren, hideBadge, activeTabIndex]);

const restartNotificationCountFetch = () => {
try {
Expand Down
30 changes: 7 additions & 23 deletions src/components/SirenProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";

import { Siren } from "@sirenapp/js-sdk";
import type {
Expand All @@ -18,12 +18,10 @@ import {
eventTypes,
IN_APP_RECIPIENT_UNAUTHENTICATED,
MAXIMUM_RETRY_COUNT,
VerificationStatus,
} from "../utils/constants";

type SirenContextProp = {
siren: Siren | null;
verificationStatus: VerificationStatus;
id: string;
};

Expand All @@ -34,7 +32,6 @@ interface SirenProvider {

export const SirenContext = createContext<SirenContextProp>({
siren: null,
verificationStatus: VerificationStatus.PENDING,
id: ''
});

Expand All @@ -44,7 +41,6 @@ export const SirenContext = createContext<SirenContextProp>({
* @example
* const {
* siren,
* verificationStatus,
* id
* } = useSirenContext();
*
Expand All @@ -56,7 +52,7 @@ export const useSirenContext = (): SirenContextProp => useContext(SirenContext);
* Provides a React context for Siren notifications, making Siren SDK functionality
* available throughout your React application.
*
* `SirenProvider` initializes the Siren SDK with given configuration and manages the state for siren and verificationStatus.
* `SirenProvider` initializes the Siren SDK with given configuration and manages the state for siren.
*
* @component
* @example
Expand All @@ -75,24 +71,17 @@ export const useSirenContext = (): SirenContextProp => useContext(SirenContext);
*/
const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
const [siren, setSiren] = useState<Siren | null>(null);
const [verificationStatus, setVerificationStatus] =
useState<VerificationStatus>(VerificationStatus.PENDING);
const shouldInitialize = useRef(true);
let retryCount = 0;


const [id] = useState(generateUniqueId());

useEffect(() => {
if (config?.recipientId && config?.userToken && shouldInitialize.current) {
shouldInitialize.current = false;
if (config?.recipientId && config?.userToken) {
stopRealTimeFetch();
sendResetDataEvents();
initialize();
}
else {
setVerificationStatus(VerificationStatus.FAILED);
}
if (retryCount > MAXIMUM_RETRY_COUNT) stopRealTimeFetch();
}, [config]);

Expand Down Expand Up @@ -146,11 +135,8 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
}
};

const onStatusChange = (status: VerificationStatus) => {
setVerificationStatus(status);
};

const actionCallbacks = { onEventReceive, onStatusChange };
const actionCallbacks = { onEventReceive };

const getDataParams = () => {
return {
Expand All @@ -163,8 +149,8 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {

const retryVerification = (error: SirenErrorType) => {
const shouldRetry = (error.Code === AUTHENTICATION_FAILED || error.Code === IN_APP_RECIPIENT_UNAUTHENTICATED) &&
retryCount < MAXIMUM_RETRY_COUNT && verificationStatus === VerificationStatus.FAILED

retryCount < MAXIMUM_RETRY_COUNT
if (shouldRetry)
setTimeout(() => {
initialize();
Expand All @@ -177,15 +163,13 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
const dataParams: InitConfigType = getDataParams();
const siren = new Siren(dataParams);

setVerificationStatus(VerificationStatus.PENDING);
setSiren(siren);
};

const contextValue = useMemo(() => ({
id,
siren,
verificationStatus,
}), [id, siren, verificationStatus]);
}), [id, siren]);

return (
<SirenContext.Provider
Expand Down
2 changes: 0 additions & 2 deletions tests/components/sirenNotificationIcon.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fireEvent, render } from "@testing-library/react";
import SirenNotificationIcon from "../../src/components/SirenNotificationIcon";
import { SirenContext } from "../../src/components/SirenProvider"; // Assuming SirenProvider exports SirenContext
import { applyTheme } from "../../src/utils/commonUtils";
import { VerificationStatus } from "../../src/utils/constants";

const mockClickFn = jest.fn();

Expand All @@ -14,7 +13,6 @@ jest.mock("../../src/styles/sirenNotificationIcon.css", () => ({}));

const mockSirenContextValue = {
siren: null,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
};

Expand Down
12 changes: 1 addition & 11 deletions tests/utils/sirenHook.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Siren } from "@sirenapp/js-sdk";

import { useSiren } from "../../src";
import * as sirenProvider from "../../src/components/SirenProvider";
import { errorMap, VerificationStatus } from "../../src/utils/constants";
import { errorMap } from "../../src/utils/constants";


// Mock the CSS files to avoid Jest error
Expand Down Expand Up @@ -91,7 +91,6 @@ describe("useSiren hook", () => {
deleteById: jest.fn(async () => ActionResponse),
deleteByDate: jest.fn(async () => ActionResponse),
markAllAsViewed: jest.fn(async () => MarkAsViewedResponse),
verifyToken: jest.fn(),
fetchUnviewedNotificationsCount: jest.fn(),
fetchAllNotifications: jest.fn(),
startRealTimeFetch: jest.fn(),
Expand All @@ -101,7 +100,6 @@ describe("useSiren hook", () => {
it("should call siren.markAsReadById and return error", async () => {
jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -127,7 +125,6 @@ describe("useSiren hook", () => {
// Mock useSirenContext
jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -147,7 +144,6 @@ describe("useSiren hook", () => {
// Mock useSirenContext
jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -163,7 +159,6 @@ describe("useSiren hook", () => {

jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -183,7 +178,6 @@ describe("useSiren hook", () => {
// Mock useSirenContext
jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -202,7 +196,6 @@ describe("useSiren hook", () => {

jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -218,7 +211,6 @@ describe("useSiren hook", () => {
// Mock useSirenContext
jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -234,7 +226,6 @@ describe("useSiren hook", () => {

jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand All @@ -253,7 +244,6 @@ describe("useSiren hook", () => {

jest.spyOn(sirenProvider, "useSirenContext").mockReturnValue({
siren: mockSirenCore as Siren,
verificationStatus: VerificationStatus.SUCCESS,
id: ''
});

Expand Down