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
14 changes: 12 additions & 2 deletions src/components/sirenProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {

import type { SirenProviderConfigProps } from '../types';
import { isNonEmptyArray, logger } from '../utils/commonUtils';
import { events, eventTypes } from '../utils/constants';
import { events, eventTypes, TOKEN_VERIFICATION_FAILED } from '../utils/constants';

type SirenContextProp = {
siren: Siren | null;
Expand Down Expand Up @@ -66,6 +66,8 @@ export const useSirenContext = (): SirenContextProp => useContext(SirenContext);
* @param {React.ReactNode} props.children - Child components that will have access to the Siren context.
*/
const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
let retryCount = 0;

const [siren, setSiren] = useState<Siren | null>(null);

useEffect(() => {
Expand Down Expand Up @@ -121,11 +123,19 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
return {
token: config.userToken,
recipientId: config.recipientId,
onError: (error: SirenErrorType): void => logger.info(`Error : ${JSON.stringify(error)}`),
onError: retryVerification,
actionCallbacks: actionCallbacks
};
};

const retryVerification = (error: SirenErrorType) => {
if (error.Code === TOKEN_VERIFICATION_FAILED && retryCount < 3)
setTimeout(() => {
initialize();
retryCount++;
}, 5000);
};

// Function to initialize the Siren SDK and fetch notifications
const initialize = (): void => {
const dataParams: InitConfigType = getDataParams();
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const ERROR_DESCRIPTION = 'Could not load the notifications. Please refre
export const DEFAULT_WINDOW_TITLE = 'Notifications';
export const RETRY_BUTTON_LABEL = 'Retry';
export const CLEAR_ALL_LABEL = 'Clear All';
export const TOKEN_VERIFICATION_FAILED = 'TOKEN_VERIFICATION_FAILED';

export const errorMap = {
SIREN_OBJECT_NOT_FOUND: {
Expand Down