@@ -26,6 +26,12 @@ public class ExpoIapModule: Module {
26
26
private var purchaseUpdatedSub : Subscription ?
27
27
private var purchaseErrorSub : Subscription ?
28
28
private var promotedProductSub : Subscription ?
29
+
30
+ // Helper to safely remove a listener and nil out the reference
31
+ private func removeListener( _ sub: inout Subscription ? ) {
32
+ if let s = sub { OpenIapModule . shared. removeListener ( s) }
33
+ sub = nil
34
+ }
29
35
30
36
nonisolated public func definition( ) -> ModuleDefinition {
31
37
Name ( " ExpoIap " )
@@ -407,10 +413,12 @@ public class ExpoIapModule: Module {
407
413
Task { @MainActor in
408
414
guard let self else { return }
409
415
logDebug ( " ❌ Purchase error callback - sending error event " )
416
+ // Use OpenIapPurchaseError alias for clarity/parity
417
+ let err : OpenIapPurchaseError = error
410
418
let errorData : [ String : Any ? ] = [
411
- " code " : error . code,
412
- " message " : error . message,
413
- " productId " : error . productId
419
+ " code " : err . code,
420
+ " message " : err . message,
421
+ " productId " : err . productId,
414
422
]
415
423
self . sendEvent ( OpenIapEvent . PurchaseError, errorData)
416
424
}
@@ -428,12 +436,9 @@ public class ExpoIapModule: Module {
428
436
@MainActor
429
437
private func cleanupStore( ) async {
430
438
logDebug ( " Cleaning up listeners and ending connection " )
431
- if let sub = purchaseUpdatedSub { OpenIapModule . shared. removeListener ( sub) }
432
- if let sub = purchaseErrorSub { OpenIapModule . shared. removeListener ( sub) }
433
- if let sub = promotedProductSub { OpenIapModule . shared. removeListener ( sub) }
434
- purchaseUpdatedSub = nil
435
- purchaseErrorSub = nil
436
- promotedProductSub = nil
439
+ removeListener ( & purchaseUpdatedSub)
440
+ removeListener ( & purchaseErrorSub)
441
+ removeListener ( & promotedProductSub)
437
442
_ = try ? await OpenIapModule . shared. endConnection ( )
438
443
}
439
444
0 commit comments