Skip to content

Commit 1f2d683

Browse files
Set up headless task when using StripeProvider
1 parent acd79e2 commit 1f2d683

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/components/StripeProvider.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ const appInfo: AppInfo = {
2727
partnerId: shouldAttributeExpo() ? EXPO_PARTNER_ID : undefined,
2828
};
2929

30+
let didRegisterHeadlessTask = false;
31+
3032
export const initStripe = async (params: InitStripeParams): Promise<void> => {
3133
// On Android when the activity is paused, JS timers are paused,
3234
// which causes network requests to hang indefinitely on new arch.
3335
// To work around this, we register a headless task that will keep
3436
// the JS runtime running while the Stripe UI is opened.
3537
// This task is started and stopped by the native module.
36-
if (Platform.OS === 'android') {
38+
if (Platform.OS === 'android' && !didRegisterHeadlessTask) {
3739
function stripeHeadlessTask() {
3840
return new Promise<void>(() => {});
3941
}
@@ -42,6 +44,7 @@ export const initStripe = async (params: InitStripeParams): Promise<void> => {
4244
'StripeKeepJsAwakeTask',
4345
() => stripeHeadlessTask
4446
);
47+
didRegisterHeadlessTask = true;
4548
}
4649

4750
const extendedParams: InitialiseParams = { ...params, appInfo };
@@ -83,18 +86,16 @@ export function StripeProvider({
8386
}
8487
const initializeStripe = async () => {
8588
if (isAndroid) {
86-
await NativeStripeSdk.initialise({
89+
await initStripe({
8790
publishableKey,
88-
appInfo,
8991
stripeAccountId,
9092
threeDSecureParams,
9193
urlScheme,
9294
setReturnUrlSchemeOnAndroid,
9395
});
9496
} else {
95-
await NativeStripeSdk.initialise({
97+
await initStripe({
9698
publishableKey,
97-
appInfo,
9899
stripeAccountId,
99100
threeDSecureParams,
100101
merchantIdentifier,

0 commit comments

Comments
 (0)