Skip to content

Commit 5254cdb

Browse files
fix: Terminate retry verification api trigger if config changes while retrying
1 parent 4f3fa50 commit 5254cdb

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/components/sirenInbox.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
129129

130130
useEffect(() => {
131131
// Initialize Siren SDK and start polling notifications
132-
if (verificationStatus !== VerificationStatus.PENDING && siren) {
132+
if (verificationStatus === VerificationStatus.SUCCESS && siren) {
133133
initialize();
134134
} else if(verificationStatus === VerificationStatus.FAILED) {
135135
setIsError(true);
136136
setIsLoading(false);
137-
if (onError) onError(errorMap.MISSING_PARAMETER);
137+
setNotifications([]);
138+
if (onError) onError(errorMap.INVALID_CREDENTIALS);
138139
}
139140
}, [siren, verificationStatus]);
140141

src/components/sirenProvider.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
170170
};
171171

172172
const retryVerification = (error: SirenErrorType) => {
173-
if (error.Code === IN_APP_RECIPIENT_UNAUTHENTICATED && retryCount < MAXIMUM_RETRY_COUNT)
173+
if (
174+
error.Code === IN_APP_RECIPIENT_UNAUTHENTICATED &&
175+
retryCount < MAXIMUM_RETRY_COUNT &&
176+
verificationStatus === VerificationStatus.FAILED
177+
)
174178
setTimeout(() => {
175179
initialize();
176180
retryCount++;
@@ -181,6 +185,7 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
181185

182186
// Function to initialize the Siren SDK and fetch notifications
183187
const initialize = (): void => {
188+
setVerificationStatus(VerificationStatus.PENDING);
184189
const dataParams: InitConfigType = getDataParams();
185190
const siren = new Siren(dataParams);
186191

0 commit comments

Comments
 (0)