Skip to content

Commit a1fe816

Browse files
committed
fix: extract performUpload to break onConfirm deadlock when OS permission is pre-granted
1 parent d2c4413 commit a1fe816

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

src/pages/Share/SubmitDetailsPage.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,20 @@ function SubmitDetailsPage({
311311
finishRequestAndNavigate(participant, receipt);
312312
};
313313

314+
// Extracted from onConfirm — re-entering onConfirm from the permission modal deadlocked when OS permission was pre-granted.
315+
const performUpload = (participant: Participant, locationPermissionGranted: boolean) => {
316+
if (!currentAttachment) {
317+
return;
318+
}
319+
readFileAsync(
320+
currentReceiptSource,
321+
currentReceiptName,
322+
(file) => onSuccess(participant, file, locationPermissionGranted),
323+
() => {},
324+
currentReceiptType,
325+
);
326+
};
327+
314328
const onConfirm = (listOfParticipants?: Participant[], gpsRequired?: boolean) => {
315329
const shouldStartLocationPermissionFlow =
316330
gpsRequired &&
@@ -322,22 +336,12 @@ function SubmitDetailsPage({
322336
setStartLocationPermissionFlow(true);
323337
return;
324338
}
325-
if (!currentAttachment) {
326-
return;
327-
}
328339

329340
const participant = listOfParticipants?.at(0) ?? selectedParticipants.at(0);
330341
if (!participant) {
331342
return;
332343
}
333-
334-
readFileAsync(
335-
currentReceiptSource,
336-
currentReceiptName,
337-
(file) => onSuccess(participant, file, shouldStartLocationPermissionFlow),
338-
() => {},
339-
currentReceiptType,
340-
);
344+
performUpload(participant, false);
341345
};
342346

343347
return (
@@ -358,13 +362,22 @@ function SubmitDetailsPage({
358362
<LocationPermissionModal
359363
startPermissionFlow={startLocationPermissionFlow}
360364
resetPermissionFlow={() => setStartLocationPermissionFlow(false)}
361-
onGrant={() => onConfirm(undefined, true)}
365+
onGrant={() => {
366+
setStartLocationPermissionFlow(false);
367+
const participant = selectedParticipants.at(0);
368+
if (!participant) {
369+
return;
370+
}
371+
navigateAfterInteraction(() => performUpload(participant, true));
372+
}}
362373
onDeny={() => {
363374
updateLastLocationPermissionPrompt();
364375
setStartLocationPermissionFlow(false);
365-
navigateAfterInteraction(() => {
366-
onConfirm(undefined, false);
367-
});
376+
const participant = selectedParticipants.at(0);
377+
if (!participant) {
378+
return;
379+
}
380+
navigateAfterInteraction(() => performUpload(participant, false));
368381
}}
369382
/>
370383
<View style={[styles.containerWithSpaceBetween, styles.pointerEventsBoxNone]}>

0 commit comments

Comments
 (0)