Skip to content

Commit 487152f

Browse files
authored
fix: Terminate retry verification api trigger if config changes while retrying
1 parent 0af3aab commit 487152f

File tree

10 files changed

+204
-86
lines changed

10 files changed

+204
-86
lines changed

package-lock.json

Lines changed: 4 additions & 4 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
@@ -84,7 +84,7 @@
8484
"typescript": "^5.3.3"
8585
},
8686
"dependencies": {
87-
"test_notification": "^1.1.0",
87+
"test_notification": "^1.1.1",
8888
"pubsub-js": "^1.9.4"
8989
}
9090
}

src/components/SirenInbox.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
debounce,
1414
} from "../utils/commonUtils";
1515
import {
16-
BadgeType,
1716
EventType,
1817
MAXIMUM_ITEMS_PER_FETCH,
1918
ThemeMode,
@@ -156,9 +155,9 @@ const SirenInbox: FC<SirenProps> = ({
156155
notificationIcon={notificationIcon}
157156
styles={styles}
158157
onIconClick={onIconClick}
159-
badgeType={isModalOpen ? BadgeType.NONE : BadgeType.DEFAULT}
160158
darkMode={darkMode}
161159
hideBadge={hideBadge}
160+
isModalOpen={isModalOpen}
162161
/>
163162
</div>
164163
)}

src/components/SirenNotificationIcon.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ const { eventTypes, events } = Constants;
2323

2424
const SirenNotificationIcon: FC<SirenNotificationButtonProps> = ({
2525
notificationIcon,
26-
badgeType,
2726
styles,
2827
onIconClick,
2928
darkMode,
3029
hideBadge,
30+
isModalOpen,
3131
}) => {
3232
const { siren } = useSirenContext();
3333

3434
const [unviewedCount, seUnviewedCount] = useState<number>(0);
35-
35+
const badgeType:BadgeType = isModalOpen ? BadgeType.NONE : BadgeType.DEFAULT;
36+
3637
const notificationCountSubscriber = async (
3738
type: string,
3839
dataString: string
@@ -57,7 +58,8 @@ const SirenNotificationIcon: FC<SirenNotificationButtonProps> = ({
5758
}, []);
5859

5960
useEffect(() => {
60-
if(!hideBadge)
61+
// Check to avoid calling getUnViewedCount when the badge is hidden and the modal is open, and when either the siren object or hideBadge state changes.
62+
if(!hideBadge && !isModalOpen)
6163
getUnViewedCount();
6264

6365
}, [siren, hideBadge]);
@@ -113,13 +115,6 @@ const SirenNotificationIcon: FC<SirenNotificationButtonProps> = ({
113115
)
114116
);
115117
}
116-
case BadgeType.DOT:
117-
return (
118-
<span
119-
className="siren-sdk-notificationIcon-badge-container"
120-
data-testid="notification-dot-badge"
121-
/>
122-
);
123118

124119
default:
125120
return null;

src/components/SirenPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
120120
!hideBadge && restartNotificationCountFetch();
121121
handleMarkNotificationsAsViewed(new Date().toISOString());
122122
};
123-
}, [hideBadge]);
123+
}, [hideBadge, siren]);
124124

125125
useEffect(() => {
126126
if (eventListenerData) {
@@ -140,7 +140,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
140140
!hideBadge && siren.stopRealTimeFetch(EventType.UNVIEWED_COUNT);
141141
fetchNotifications(true);
142142
}
143-
if(!siren && isLoading) {
143+
if(verificationStatus === VerificationStatus.FAILED) {
144144
setIsLoading(false);
145145
onError && onError(errorMap?.INVALID_CREDENTIALS);
146146
setError(ERROR_TEXT);

src/components/SirenProvider.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
events,
1717
EventType,
1818
eventTypes,
19+
IN_APP_RECIPIENT_UNAUTHENTICATED,
1920
MAXIMUM_RETRY_COUNT,
2021
VerificationStatus,
2122
} from "../utils/constants";
@@ -81,6 +82,9 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
8182
sendResetDataEvents();
8283
initialize();
8384
}
85+
else {
86+
setVerificationStatus(VerificationStatus.FAILED);
87+
}
8488
if (retryCount > MAXIMUM_RETRY_COUNT) stopRealTimeFetch();
8589
}, [config]);
8690

@@ -156,10 +160,10 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
156160
};
157161

158162
const retryVerification = (error: SirenErrorType) => {
159-
if (
160-
error.Code === AUTHENTICATION_FAILED &&
161-
retryCount < MAXIMUM_RETRY_COUNT
162-
)
163+
const shouldRetry = (error.Code === AUTHENTICATION_FAILED || error.Code === IN_APP_RECIPIENT_UNAUTHENTICATED) &&
164+
retryCount < MAXIMUM_RETRY_COUNT && verificationStatus === VerificationStatus.FAILED
165+
166+
if (shouldRetry)
163167
setTimeout(() => {
164168
initialize();
165169
retryCount++;
@@ -171,6 +175,7 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
171175
const dataParams: InitConfigType = getDataParams();
172176
const siren = new Siren(dataParams);
173177

178+
setVerificationStatus(VerificationStatus.PENDING);
174179
setSiren(siren);
175180
};
176181

src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ export type NotificationCardProps = {
6767

6868
export type SirenNotificationButtonProps = {
6969
styles: SirenStyleProps;
70-
badgeType: BadgeType;
7170
darkMode: boolean;
7271
hideBadge: boolean;
7372
notificationIcon?: JSX.Element;
7473
onIconClick: () => void;
74+
isModalOpen: boolean;
7575
};
7676
export type SirenPanelProps = Pick<
7777
SirenInboxProps,
@@ -109,8 +109,6 @@ export type LoaderProps = {
109109
hideAvatar: boolean;
110110
}
111111

112-
type BadgeType = "none" | "dot" | "default";
113-
114112
export type Theme = {
115113
dark: ThemeProps;
116114
light: ThemeProps;

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const ERROR_SUB_TEXT =
100100
export const DEFAULT_WINDOW_TITLE = "Notifications";
101101
export const RETRY_BUTTON_LABEL = "Retry";
102102
export const CLEAR_ALL_LABEL = "Clear All";
103+
export const IN_APP_RECIPIENT_UNAUTHENTICATED = "IN_APP_RECIPIENT_UNAUTHENTICATED";
103104
export const AUTHENTICATION_FAILED = 'AUTHENTICATION_FAILED';
104105
export const TOKEN_VERIFICATION_PENDING ='TOKEN_VERIFICATION_PENDING';
105106
export const MAXIMUM_RETRY_COUNT = 3;

0 commit comments

Comments
 (0)