react-native-nami-sdk 3.0.25 → 3.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ EmitterSubscription,
5
+ } from 'react-native';
6
+ import { AccountStateAction, CustomerJourneyState } from './types';
7
+
8
+ export const { RNNamiCustomerManager } = NativeModules;
9
+
10
+ export enum NamiCustomerManagerEvents {
11
+ JourneyStateChanged = 'JourneyStateChanged',
12
+ AccountStateChanged = 'AccountStateChanged',
13
+ }
14
+
15
+ export interface INamiCustomerManager {
16
+ emitter: NativeEventEmitter;
17
+ setCustomerAttribute: (key: string, value: string) => void;
18
+ getCustomerAttribute: (key: string) => Promise<string | undefined>;
19
+ clearCustomerAttribute: (key: string) => void;
20
+ clearAllCustomerAttributes: () => void;
21
+ journeyState: () => Promise<CustomerJourneyState | undefined>;
22
+ isLoggedIn: () => Promise<boolean>;
23
+ loggedInId: () => Promise<string | undefined>;
24
+ deviceId: () => Promise<string>;
25
+ login: (customerId: string) => void;
26
+ logout: () => void;
27
+ registerJourneyStateHandler: (
28
+ callback: (journeyState: CustomerJourneyState) => void,
29
+ ) => EmitterSubscription['remove'];
30
+ registerAccountStateHandler: (
31
+ callback: (
32
+ action: AccountStateAction,
33
+ success: boolean,
34
+ error?: number,
35
+ ) => void,
36
+ ) => EmitterSubscription['remove'];
37
+ clearCustomerDataPlatformId: () => void;
38
+ setCustomerDataPlatformId: (platformId: string) => void;
39
+ setAnonymousMode: (anonymousMode: boolean) => void;
40
+ inAnonymousMode: () => Promise<boolean>;
41
+ }
42
+
43
+ export const NamiCustomerManager: INamiCustomerManager = {
44
+ ...RNNamiCustomerManager,
45
+ emitter: new NativeEventEmitter(RNNamiCustomerManager),
46
+ login: customerId => {
47
+ RNNamiCustomerManager.login(customerId);
48
+ },
49
+ logout: () => {
50
+ RNNamiCustomerManager.logout();
51
+ },
52
+ registerJourneyStateHandler: (
53
+ callback: (journeyState: CustomerJourneyState) => void,
54
+ ) => {
55
+ const subscription = NamiCustomerManager.emitter.addListener(
56
+ NamiCustomerManagerEvents.JourneyStateChanged,
57
+ callback,
58
+ );
59
+ RNNamiCustomerManager.registerJourneyStateHandler();
60
+ return () => {
61
+ if (subscription) {
62
+ subscription.remove();
63
+ }
64
+ };
65
+ },
66
+ registerAccountStateHandler: (
67
+ callback: (
68
+ action: AccountStateAction,
69
+ success: boolean,
70
+ error?: number,
71
+ ) => void,
72
+ ) => {
73
+ const subscription = NamiCustomerManager.emitter.addListener(
74
+ NamiCustomerManagerEvents.AccountStateChanged,
75
+ (body: any) => {
76
+ const action: AccountStateAction = body.action.toLowerCase();
77
+ const error: number | undefined = body.error;
78
+ const success: boolean = body.success;
79
+ callback(action, success, error);
80
+ },
81
+ );
82
+ RNNamiCustomerManager.registerAccountStateHandler();
83
+ return () => {
84
+ if (subscription) {
85
+ subscription.remove();
86
+ }
87
+ };
88
+ },
89
+ };
@@ -1,16 +1,15 @@
1
- import { EmitterSubscription } from "react-native";
2
- import { NamiPurchase } from "./NamiPurchaseManager";
3
- import { NamiSKU } from "./types";
1
+ import { EmitterSubscription } from 'react-native';
2
+ import { NamiPurchase, NamiSKU } from './types';
4
3
 
5
4
  export const NamiEntitlementManager: {
6
5
  active: () => Promise<Array<NamiEntitlement>>;
7
6
  isEntitlementActive: (label?: string) => boolean;
8
7
  refresh: (
9
- resultCallback?: (entitlements?: NamiEntitlement[]) => void
8
+ resultCallback?: (entitlements?: NamiEntitlement[]) => void,
10
9
  ) => void;
11
10
  registerActiveEntitlementsHandler: (
12
- callback: (activeEntitlements: NamiEntitlement[]) => void
13
- ) => EmitterSubscription["remove"];
11
+ callback: (activeEntitlements: NamiEntitlement[]) => void,
12
+ ) => EmitterSubscription['remove'];
14
13
  };
15
14
 
16
15
  export type NamiEntitlement = {
@@ -0,0 +1,52 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ Platform,
5
+ EmitterSubscription,
6
+ } from 'react-native';
7
+ import { NamiEntitlement } from './types';
8
+
9
+ export const { RNNamiEntitlementManager } = NativeModules;
10
+
11
+ export enum NamiEntitlementManagerEvents {
12
+ EntitlementsChanged = 'EntitlementsChanged',
13
+ }
14
+
15
+ export interface INamiEntitlementManager {
16
+ emitter: NativeEventEmitter;
17
+ active: () => Promise<Array<NamiEntitlement>>;
18
+ isEntitlementActive: (label?: string) => boolean;
19
+ refresh: (
20
+ resultCallback?: (entitlements?: NamiEntitlement[]) => void,
21
+ ) => void;
22
+ registerActiveEntitlementsHandler: (
23
+ callback: (activeEntitlements: NamiEntitlement[]) => void,
24
+ ) => EmitterSubscription['remove'];
25
+ }
26
+
27
+ export const NamiEntitlementManager: INamiEntitlementManager = {
28
+ ...RNNamiEntitlementManager,
29
+ emitter: new NativeEventEmitter(RNNamiEntitlementManager),
30
+ refresh: (resultCallback?: (entitlements?: NamiEntitlement[]) => void) => {
31
+ if (Platform.OS === 'android') {
32
+ RNNamiEntitlementManager.refresh(resultCallback ?? (() => {}));
33
+ } else {
34
+ RNNamiEntitlementManager.refresh();
35
+ }
36
+ },
37
+ registerActiveEntitlementsHandler: (
38
+ callback: (activeEntitlements: NamiEntitlement[]) => void,
39
+ ) => {
40
+ let subscription: EmitterSubscription =
41
+ NamiEntitlementManager.emitter.addListener(
42
+ NamiEntitlementManagerEvents.EntitlementsChanged,
43
+ callback,
44
+ );
45
+ RNNamiEntitlementManager.registerActiveEntitlementsHandler();
46
+ return () => {
47
+ if (subscription) {
48
+ subscription.remove();
49
+ }
50
+ };
51
+ },
52
+ };
@@ -0,0 +1,13 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ export const { NamiMLManagerBridge } = NativeModules;
4
+
5
+ export interface INamiMLManager {
6
+ coreAction: (label: string) => void;
7
+ enterCoreContent: (label: string | string[]) => void;
8
+ exitCoreContent: (label: string | string[]) => void;
9
+ }
10
+
11
+ export const NamiMLManager: INamiMLManager = {
12
+ ...NamiMLManagerBridge,
13
+ };
@@ -1,19 +1,23 @@
1
- import { EmitterSubscription } from "react-native";
2
- import { NamiSKU } from "./types";
1
+ import { EmitterSubscription } from 'react-native';
2
+ import { NamiSKU } from './types';
3
3
 
4
4
  export const NamiPaywallManager: {
5
5
  buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => void;
6
6
  buySkuCompleteAmazon: (purchaseSuccess: NamiPurchaseSuccessAmazon) => void;
7
7
  buySkuCompleteGooglePlay: (
8
- purchaseSuccess: NamiPurchaseSuccessGooglePlay
8
+ purchaseSuccess: NamiPurchaseSuccessGooglePlay,
9
9
  ) => void;
10
10
  dismiss: (animated?: boolean) => void;
11
11
  registerBuySkuHandler: (
12
- callback: (sku: NamiSKU) => void
13
- ) => EmitterSubscription["remove"];
14
- registerCloseHandler: (callback: () => void) => EmitterSubscription["remove"];
15
- registerSignInHandler: (callback: () => void) => EmitterSubscription["remove"];
16
- registerRestoreHandler: (callback: () => void) => EmitterSubscription["remove"];
12
+ callback: (sku: NamiSKU) => void,
13
+ ) => EmitterSubscription['remove'];
14
+ registerCloseHandler: (callback: () => void) => EmitterSubscription['remove'];
15
+ registerSignInHandler: (
16
+ callback: () => void,
17
+ ) => EmitterSubscription['remove'];
18
+ registerRestoreHandler: (
19
+ callback: () => void,
20
+ ) => EmitterSubscription['remove'];
17
21
  show: () => void;
18
22
  hide: () => void;
19
23
  isHidden: () => Promise<boolean>;
@@ -37,14 +41,14 @@ export type NamiPurchaseSuccessGooglePlay = {
37
41
  purchaseDate: number;
38
42
  expiresDate?: number;
39
43
  purchaseToken: string;
40
- purchaseSource: "CAMPAIGN" | "MARKETPLACE" | "UNKNOWN";
44
+ purchaseSource: 'CAMPAIGN' | 'MARKETPLACE' | 'UNKNOWN';
41
45
  };
42
46
 
43
47
  export type NamiPurchaseSuccessAmazon = {
44
48
  product: NamiSKU;
45
49
  purchaseDate: number;
46
50
  expiresDate?: number;
47
- purchaseSource: "CAMPAIGN" | "MARKETPLACE" | "UNKNOWN";
51
+ purchaseSource: 'CAMPAIGN' | 'MARKETPLACE' | 'UNKNOWN';
48
52
  receiptId: string;
49
53
  localizedPrice: string;
50
54
  userId: string;
@@ -52,22 +56,22 @@ export type NamiPurchaseSuccessAmazon = {
52
56
  };
53
57
 
54
58
  export enum NamiPaywallAction {
55
- BUY_SKU = "BUY_SKU",
56
- SELECT_SKU = "SELECT_SKU",
57
- RESTORE_PURCHASES = "RESTORE_PURCHASES",
58
- SIGN_IN = "SIGN_IN",
59
- CLOSE_PAYWALL = "CLOSE_PAYWALL",
60
- SHOW_PAYWALL = "SHOW_PAYWALL",
61
- PURCHASE_SELECTED_SKU = "PURCHASE_SELECTED_SKU",
62
- PURCHASE_SUCCESS = "PURCHASE_SUCCESS",
63
- PURCHASE_FAILED = "PURCHASE_FAILED",
64
- PURCHASE_CANCELLED = "PURCHASE_CANCELLED",
65
- PURCHASE_PENDING = "PURCHASE_PENDING",
66
- PURCHASE_UNKNOWN = "PURCHASE_UNKNOWN",
67
- PURCHASE_DEFERRED = "PURCHASE_DEFERRED",
68
- DEEPLINK = "DEEPLINK",
69
- TOGGLE_CHANGE = "TOGGLE_CHANGE",
70
- PAGE_CHANGE = "PAGE_CHANGE",
71
- SLIDE_CHANGE = "SLIDE_CHANGE",
72
- UNKNOWN = "UNKNOWN"
59
+ BUY_SKU = 'BUY_SKU',
60
+ SELECT_SKU = 'SELECT_SKU',
61
+ RESTORE_PURCHASES = 'RESTORE_PURCHASES',
62
+ SIGN_IN = 'SIGN_IN',
63
+ CLOSE_PAYWALL = 'CLOSE_PAYWALL',
64
+ SHOW_PAYWALL = 'SHOW_PAYWALL',
65
+ PURCHASE_SELECTED_SKU = 'PURCHASE_SELECTED_SKU',
66
+ PURCHASE_SUCCESS = 'PURCHASE_SUCCESS',
67
+ PURCHASE_FAILED = 'PURCHASE_FAILED',
68
+ PURCHASE_CANCELLED = 'PURCHASE_CANCELLED',
69
+ PURCHASE_PENDING = 'PURCHASE_PENDING',
70
+ PURCHASE_UNKNOWN = 'PURCHASE_UNKNOWN',
71
+ PURCHASE_DEFERRED = 'PURCHASE_DEFERRED',
72
+ DEEPLINK = 'DEEPLINK',
73
+ TOGGLE_CHANGE = 'TOGGLE_CHANGE',
74
+ PAGE_CHANGE = 'PAGE_CHANGE',
75
+ SLIDE_CHANGE = 'SLIDE_CHANGE',
76
+ UNKNOWN = 'UNKNOWN',
73
77
  }
@@ -0,0 +1,141 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ EmitterSubscription,
5
+ } from 'react-native';
6
+ import {
7
+ NamiPurchaseSuccessAmazon,
8
+ NamiPurchaseSuccessApple,
9
+ NamiPurchaseSuccessGooglePlay,
10
+ NamiSKU,
11
+ } from './types';
12
+
13
+ export enum NamiPaywallManagerEvents {
14
+ RegisterBuySKU = 'RegisterBuySKU',
15
+ PaywallCloseRequested = 'PaywallCloseRequested',
16
+ PaywallSignInRequested = 'PaywallSignInRequested',
17
+ PaywallRestoreRequested = 'PaywallRestoreRequested',
18
+ }
19
+
20
+ export enum ServicesEnum {
21
+ Amazon = 'Amazon',
22
+ GooglePlay = 'GooglePlay',
23
+ }
24
+
25
+ export interface INamiPaywallManager {
26
+ paywallEmitter: NativeEventEmitter;
27
+ buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => void;
28
+ buySkuCompleteAmazon: (purchaseSuccess: NamiPurchaseSuccessAmazon) => void;
29
+ buySkuCompleteGooglePlay: (
30
+ purchaseSuccess: NamiPurchaseSuccessGooglePlay,
31
+ ) => void;
32
+ registerBuySkuHandler: (
33
+ callback: (sku: NamiSKU) => void,
34
+ ) => EmitterSubscription['remove'];
35
+ registerCloseHandler: (callback: () => void) => EmitterSubscription['remove'];
36
+ registerSignInHandler: (
37
+ callback: () => void,
38
+ ) => EmitterSubscription['remove'];
39
+ registerRestoreHandler: (
40
+ callback: () => void,
41
+ ) => EmitterSubscription['remove'];
42
+ dismiss: (animated?: boolean) => void;
43
+ show: () => void;
44
+ hide: () => void;
45
+ isHidden: () => Promise<void>;
46
+ }
47
+
48
+ const { NamiPaywallManagerBridge, RNNamiPaywallManager } = NativeModules;
49
+
50
+ export const NamiPaywallManager: INamiPaywallManager = {
51
+ paywallEmitter: new NativeEventEmitter(RNNamiPaywallManager),
52
+ ...RNNamiPaywallManager,
53
+ ...NamiPaywallManagerBridge,
54
+ buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => {
55
+ RNNamiPaywallManager.buySkuComplete(purchaseSuccess);
56
+ },
57
+ buySkuCompleteAmazon: (purchaseSuccess: NamiPurchaseSuccessAmazon) => {
58
+ RNNamiPaywallManager.buySkuComplete(purchaseSuccess, ServicesEnum.Amazon);
59
+ },
60
+ buySkuCompleteGooglePlay: (
61
+ purchaseSuccess: NamiPurchaseSuccessGooglePlay,
62
+ ) => {
63
+ RNNamiPaywallManager.buySkuComplete(
64
+ purchaseSuccess,
65
+ ServicesEnum.GooglePlay,
66
+ );
67
+ },
68
+ registerBuySkuHandler: (callback: (sku: NamiSKU) => void) => {
69
+ let subscription;
70
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
71
+ NamiPaywallManagerEvents.RegisterBuySKU,
72
+ sku => {
73
+ callback(sku);
74
+ },
75
+ );
76
+ RNNamiPaywallManager.registerBuySkuHandler();
77
+ return () => {
78
+ if (subscription) {
79
+ subscription.remove();
80
+ }
81
+ };
82
+ },
83
+ registerCloseHandler: (callback: (body: any) => void) => {
84
+ let subscription;
85
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
86
+ NamiPaywallManagerEvents.PaywallCloseRequested,
87
+ body => {
88
+ callback(body);
89
+ },
90
+ );
91
+ RNNamiPaywallManager.registerCloseHandler();
92
+ return () => {
93
+ if (subscription) {
94
+ subscription.remove();
95
+ }
96
+ };
97
+ },
98
+ registerSignInHandler(callback) {
99
+ let subscription;
100
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
101
+ NamiPaywallManagerEvents.PaywallSignInRequested,
102
+ () => {
103
+ callback();
104
+ },
105
+ );
106
+ RNNamiPaywallManager.registerSignInHandler();
107
+
108
+ return () => {
109
+ if (subscription) {
110
+ subscription.remove();
111
+ }
112
+ };
113
+ },
114
+ registerRestoreHandler(callback) {
115
+ let subscription;
116
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
117
+ NamiPaywallManagerEvents.PaywallRestoreRequested,
118
+ () => {
119
+ callback();
120
+ },
121
+ );
122
+ RNNamiPaywallManager.registerRestoreHandler();
123
+ return () => {
124
+ if (subscription) {
125
+ subscription.remove();
126
+ }
127
+ };
128
+ },
129
+ dismiss: (animated?: boolean) => {
130
+ RNNamiPaywallManager.dismiss(animated ?? true);
131
+ },
132
+ show: () => {
133
+ RNNamiPaywallManager.show();
134
+ },
135
+ hide: () => {
136
+ RNNamiPaywallManager.hide();
137
+ },
138
+ isHidden: () => {
139
+ return RNNamiPaywallManager.isHidden();
140
+ },
141
+ };
@@ -1,5 +1,5 @@
1
- import { EmitterSubscription } from "react-native";
2
- import { NamiSKU } from "./types";
1
+ import { EmitterSubscription } from 'react-native';
2
+ import { NamiSKU } from './types';
3
3
 
4
4
  export const NamiPurchaseManager: {
5
5
  allPurchases: () => NamiPurchase[];
@@ -10,24 +10,24 @@ export const NamiPurchaseManager: {
10
10
  callback: (
11
11
  purchaseState: NamiPurchasesState,
12
12
  purchases: NamiPurchase[],
13
- error: string
14
- ) => void
15
- ) => EmitterSubscription["remove"];
13
+ error: string,
14
+ ) => void,
15
+ ) => EmitterSubscription['remove'];
16
16
  skuPurchased: (skuId: string) => boolean;
17
17
  registerPurchasesChangedHandler: (
18
18
  callback: (
19
19
  purchaseState: NamiPurchasesState,
20
20
  purchases: NamiPurchase[],
21
- error: string
22
- ) => void
23
- ) => EmitterSubscription["remove"];
21
+ error: string,
22
+ ) => void,
23
+ ) => EmitterSubscription['remove'];
24
24
  registerRestorePurchasesHandler: (
25
25
  callback: (
26
26
  state: NamiRestorePurchasesState,
27
27
  newPurchases: NamiPurchase[],
28
- oldPurchases: NamiPurchase[]
29
- ) => void
30
- ) => EmitterSubscription["remove"];
28
+ oldPurchases: NamiPurchase[],
29
+ ) => void,
30
+ ) => EmitterSubscription['remove'];
31
31
  };
32
32
 
33
33
  export type NamiPurchase = {
@@ -36,26 +36,26 @@ export type NamiPurchase = {
36
36
  transactionIdentifier?: string;
37
37
  expires?: Date;
38
38
  purchaseInitiatedTimestamp: Date;
39
- purchaseSource?: "CAMPAIGN" | "MARKETPLACE" | "UNKNOWN";
39
+ purchaseSource?: 'CAMPAIGN' | 'MARKETPLACE' | 'UNKNOWN';
40
40
  };
41
41
 
42
42
  export enum NamiPurchaseState {
43
- PURCHASED = "PURCHASED",
44
- FAILED = "FAILED",
45
- CANCELLED = "CANCELLEDd",
46
- PENDING = "PENDING",
47
- UNKNOWN = "UNKNOWN",
43
+ PURCHASED = 'PURCHASED',
44
+ FAILED = 'FAILED',
45
+ CANCELLED = 'CANCELLEDd',
46
+ PENDING = 'PENDING',
47
+ UNKNOWN = 'UNKNOWN',
48
48
  }
49
49
 
50
- export type NamiRestorePurchasesState = "started" | "finished" | "error";
50
+ export type NamiRestorePurchasesState = 'started' | 'finished' | 'error';
51
51
 
52
52
  export type NamiPurchasesState =
53
- | "pending"
54
- | "purchased"
55
- | "consumed"
56
- | "resubscribed"
57
- | "unsubscribed"
58
- | "deferred"
59
- | "failed"
60
- | "cancelled"
61
- | "unknown";
53
+ | 'pending'
54
+ | 'purchased'
55
+ | 'consumed'
56
+ | 'resubscribed'
57
+ | 'unsubscribed'
58
+ | 'deferred'
59
+ | 'failed'
60
+ | 'cancelled'
61
+ | 'unknown';
@@ -0,0 +1,100 @@
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
+ import { EmitterSubscription } from 'react-native';
3
+ import {
4
+ NamiPurchase,
5
+ NamiPurchasesState,
6
+ NamiRestorePurchasesState,
7
+ } from './types';
8
+
9
+ export const { NamiPurchaseManagerBridge, RNNamiPurchaseManager } =
10
+ NativeModules;
11
+
12
+ export enum NamiPurchaseManagerEvents {
13
+ PurchasesChanged = 'PurchasesChanged',
14
+ RestorePurchasesStateChanged = 'RestorePurchasesStateChanged',
15
+ }
16
+
17
+ export interface INamiPurchaseManager {
18
+ emitter: NativeEventEmitter;
19
+ allPurchases: () => NamiPurchase[];
20
+ anySkuPurchased: (skuIds: string[]) => boolean;
21
+ consumePurchasedSku: (skuId: string) => void;
22
+ presentCodeRedemptionSheet: () => void;
23
+ restorePurchases: (
24
+ callback: (
25
+ purchaseState: NamiPurchasesState,
26
+ purchases: NamiPurchase[],
27
+ error: string,
28
+ ) => void,
29
+ ) => EmitterSubscription['remove'];
30
+ skuPurchased: (skuId: string) => boolean;
31
+ registerPurchasesChangedHandler: (
32
+ callback: (
33
+ purchaseState: NamiPurchasesState,
34
+ purchases: NamiPurchase[],
35
+ error: string,
36
+ ) => void,
37
+ ) => EmitterSubscription['remove'];
38
+ registerRestorePurchasesHandler: (
39
+ callback: (
40
+ state: NamiRestorePurchasesState,
41
+ newPurchases: NamiPurchase[],
42
+ oldPurchases: NamiPurchase[],
43
+ ) => void,
44
+ ) => EmitterSubscription['remove'];
45
+ }
46
+
47
+ export const NamiPurchaseManager: INamiPurchaseManager = {
48
+ emitter: new NativeEventEmitter(RNNamiPurchaseManager),
49
+ ...NamiPurchaseManagerBridge,
50
+ ...RNNamiPurchaseManager,
51
+ registerPurchasesChangedHandler: (
52
+ callback: (
53
+ purchaseState: NamiPurchasesState,
54
+ purchases: NamiPurchase[],
55
+ error: string,
56
+ ) => void,
57
+ ) => {
58
+ const subscription = NamiPurchaseManager.emitter.addListener(
59
+ NamiPurchaseManagerEvents.PurchasesChanged,
60
+ body => {
61
+ let purchases = body.purchases;
62
+ let purchaseState =
63
+ body.purchaseState.toLowerCase() as NamiPurchasesState;
64
+ let error = body.error;
65
+ callback(purchaseState, purchases, error);
66
+ },
67
+ );
68
+ RNNamiPurchaseManager.registerPurchasesChangedHandler();
69
+ return () => {
70
+ if (subscription) {
71
+ subscription.remove();
72
+ }
73
+ };
74
+ },
75
+ registerRestorePurchasesHandler: (
76
+ callback: (
77
+ state: NamiRestorePurchasesState,
78
+ newPurchases: NamiPurchase[],
79
+ oldPurchases: NamiPurchase[],
80
+ ) => void,
81
+ ) => {
82
+ if (Platform.OS === 'ios') {
83
+ const subscription = NamiPurchaseManager.emitter.addListener(
84
+ NamiPurchaseManagerEvents.RestorePurchasesStateChanged,
85
+ body => {
86
+ let state = body.state.toLowerCase() as NamiRestorePurchasesState;
87
+ let newPurchases = body.newPurchases;
88
+ let oldPurchases = body.oldPurchases;
89
+ callback(state, newPurchases, oldPurchases);
90
+ },
91
+ );
92
+ RNNamiPurchaseManager.registerRestorePurchasesHandler();
93
+ return () => {
94
+ if (subscription) {
95
+ subscription.remove();
96
+ }
97
+ };
98
+ }
99
+ },
100
+ };