@umituz/react-native-subscription 2.14.99 → 2.14.101
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.
- package/README.md +211 -394
- package/package.json +3 -3
- package/src/application/README.md +46 -225
- package/src/application/ports/README.md +42 -97
- package/src/domain/README.md +36 -384
- package/src/domain/constants/README.md +0 -56
- package/src/domain/entities/README.md +43 -169
- package/src/domain/entities/SubscriptionStatus.ts +1 -1
- package/src/domain/errors/README.md +33 -287
- package/src/domain/value-objects/README.md +43 -179
- package/src/domains/README.md +50 -238
- package/src/domains/README.md.bak +274 -0
- package/src/domains/config/README.md +93 -383
- package/src/domains/config/domain/README.md +23 -376
- package/src/domains/config/domain/entities/README.md +34 -343
- package/src/domains/paywall/README.md +99 -369
- package/src/domains/paywall/components/README.md +34 -178
- package/src/domains/paywall/entities/README.md +34 -193
- package/src/domains/paywall/hooks/README.md +34 -122
- package/src/domains/wallet/README.md +34 -275
- package/src/domains/wallet/README.md.bak +209 -0
- package/src/domains/wallet/domain/README.md +34 -101
- package/src/domains/wallet/domain/entities/README.md +34 -115
- package/src/domains/wallet/domain/errors/README.md +34 -151
- package/src/domains/wallet/infrastructure/README.md +34 -89
- package/src/domains/wallet/presentation/components/README.md +34 -224
- package/src/domains/wallet/presentation/components/TransactionItem.tsx +1 -1
- package/src/domains/wallet/presentation/hooks/README.md +34 -248
- package/src/infrastructure/README.md +37 -496
- package/src/infrastructure/mappers/README.md +0 -13
- package/src/infrastructure/repositories/README.md +74 -360
- package/src/infrastructure/services/ActivationHandler.ts +1 -1
- package/src/infrastructure/services/README.md +95 -370
- package/src/infrastructure/services/SubscriptionService.ts +1 -1
- package/src/presentation/README.md +123 -408
- package/src/presentation/README.md.bak +172 -0
- package/src/presentation/components/README.md +151 -179
- package/src/presentation/components/README.md.bak +217 -0
- package/src/presentation/components/details/CreditRow.md +65 -310
- package/src/presentation/components/details/DetailRow.md +63 -255
- package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
- package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
- package/src/presentation/components/details/README.md +97 -447
- package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
- package/src/presentation/components/feedback/README.md +97 -445
- package/src/presentation/components/paywall/PaywallModal.md +66 -416
- package/src/presentation/components/paywall/README.md +50 -186
- package/src/presentation/components/sections/README.md +97 -466
- package/src/presentation/components/sections/SubscriptionSection.md +92 -244
- package/src/presentation/hooks/README.md +154 -741
- package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
- package/src/presentation/hooks/useAuthGate.md +61 -375
- package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
- package/src/presentation/hooks/useCreditChecker.md +73 -378
- package/src/presentation/hooks/useCredits.md +74 -313
- package/src/presentation/hooks/useCredits.md.bak +231 -0
- package/src/presentation/hooks/useCreditsGate.md +66 -318
- package/src/presentation/hooks/useDeductCredit.md +0 -76
- package/src/presentation/hooks/useDeductCredit.ts +1 -1
- package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
- package/src/presentation/hooks/useFeatureGate.md +105 -150
- package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
- package/src/presentation/hooks/useInitializeCredits.md +64 -430
- package/src/presentation/hooks/usePaywall.md +61 -306
- package/src/presentation/hooks/usePaywallOperations.md +64 -458
- package/src/presentation/hooks/usePaywallVisibility.md +67 -316
- package/src/presentation/hooks/usePremium.md +84 -226
- package/src/presentation/hooks/usePremiumGate.md +60 -395
- package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
- package/src/presentation/hooks/useSubscription.md +66 -422
- package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
- package/src/presentation/hooks/useSubscriptionGate.md +80 -164
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
- package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
- package/src/presentation/hooks/useUserTier.md +63 -328
- package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
- package/src/presentation/screens/README.md +48 -190
- package/src/presentation/types/README.md +0 -16
- package/src/presentation/utils/README.md +0 -21
- package/src/presentation/utils/subscriptionDateUtils.ts +1 -1
- package/src/revenuecat/README.md +99 -518
- package/src/revenuecat/application/README.md +35 -150
- package/src/revenuecat/application/ports/README.md +34 -162
- package/src/revenuecat/domain/README.md +42 -141
- package/src/revenuecat/domain/constants/README.md +34 -176
- package/src/revenuecat/domain/entities/README.md +34 -374
- package/src/revenuecat/domain/errors/README.md +47 -191
- package/src/revenuecat/domain/types/README.md +34 -366
- package/src/revenuecat/domain/value-objects/README.md +34 -434
- package/src/revenuecat/infrastructure/README.md +34 -43
- package/src/revenuecat/infrastructure/config/README.md +32 -23
- package/src/revenuecat/infrastructure/handlers/README.md +34 -211
- package/src/revenuecat/infrastructure/managers/README.md +34 -42
- package/src/revenuecat/infrastructure/services/README.md +35 -318
- package/src/revenuecat/infrastructure/utils/README.md +34 -375
- package/src/revenuecat/presentation/README.md +34 -176
- package/src/revenuecat/presentation/hooks/README.md +29 -35
- package/src/utils/README.md +38 -525
|
@@ -2,428 +2,91 @@
|
|
|
2
2
|
|
|
3
3
|
Combined hook for premium subscription with credits system integration.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Location
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { usePremiumWithCredits } from '@umituz/react-native-subscription';
|
|
9
|
-
```
|
|
7
|
+
**Import Path**: `@umituz/react-native-subscription`
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
**File**: `src/presentation/hooks/usePremiumWithCredits.ts`
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
function usePremiumWithCredits(params: {
|
|
15
|
-
userId: string | undefined;
|
|
16
|
-
isPremium: boolean;
|
|
17
|
-
}): {
|
|
18
|
-
credits: number;
|
|
19
|
-
balance: number;
|
|
20
|
-
transactions: Transaction[];
|
|
21
|
-
isLoading: boolean;
|
|
22
|
-
error: Error | null;
|
|
23
|
-
refetch: () => Promise<void>;
|
|
24
|
-
ensureCreditsInitialized: () => Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
```
|
|
11
|
+
**Type**: Hook
|
|
27
12
|
|
|
28
|
-
##
|
|
13
|
+
## Strategy
|
|
29
14
|
|
|
30
|
-
|
|
31
|
-
|-----------|------|---------|-------------|
|
|
32
|
-
| `userId` | `string \| undefined` | **Required** | User ID |
|
|
33
|
-
| `isPremium` | `boolean` | **Required** | Whether user has premium subscription |
|
|
15
|
+
### Premium + Credits Integration
|
|
34
16
|
|
|
35
|
-
|
|
17
|
+
1. **Credits Access**: Provide all credits data from useCredits hook
|
|
18
|
+
2. **Auto-Initialization**: Automatically initialize credits when user becomes premium
|
|
19
|
+
3. **Premium Check**: Monitor isPremium status to trigger initialization
|
|
20
|
+
4. **Duplicate Prevention**: Skip initialization if credits already exist
|
|
21
|
+
5. **Loading Management**: Handle loading state during initialization
|
|
22
|
+
6. **Error Handling**: Handle initialization failures gracefully
|
|
36
23
|
|
|
37
|
-
|
|
24
|
+
### Integration Points
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
- **useCredits**: For credits balance and transactions
|
|
27
|
+
- **usePremium**: For premium status check
|
|
28
|
+
- **useInitializeCredits**: For credit initialization
|
|
29
|
+
- **Credits Repository**: `src/domains/wallet/infrastructure/repositories/CreditsRepository.ts`
|
|
42
30
|
|
|
43
|
-
##
|
|
31
|
+
## Restrictions
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
function PremiumUserDashboard() {
|
|
47
|
-
const { user } = useAuth();
|
|
48
|
-
const { isPremium } = usePremium();
|
|
33
|
+
### REQUIRED
|
|
49
34
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
- **User ID**: MUST provide valid userId parameter
|
|
36
|
+
- **Premium Status**: MUST provide isPremium parameter
|
|
37
|
+
- **Loading State**: MUST handle loading state
|
|
38
|
+
- **Error Handling**: MUST handle initialization errors
|
|
54
39
|
|
|
55
|
-
|
|
56
|
-
if (isPremium) {
|
|
57
|
-
ensureCreditsInitialized();
|
|
58
|
-
}
|
|
59
|
-
}, [isPremium]);
|
|
40
|
+
### PROHIBITED
|
|
60
41
|
|
|
61
|
-
|
|
42
|
+
- **NEVER** call without valid userId
|
|
43
|
+
- **NEVER** call without isPremium parameter
|
|
44
|
+
- **DO NOT** manually manage credits state (use hook values)
|
|
45
|
+
- **DO NOT** call ensureCreditsInitialized excessively
|
|
62
46
|
|
|
63
|
-
|
|
64
|
-
<View>
|
|
65
|
-
<Text>Credits: {credits}</Text>
|
|
66
|
-
<Text>Status: {isPremium ? 'Premium' : 'Free'}</Text>
|
|
67
|
-
</View>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
```
|
|
47
|
+
### CRITICAL SAFETY
|
|
71
48
|
|
|
72
|
-
|
|
49
|
+
- **ALWAYS** validate userId before use
|
|
50
|
+
- **MUST** handle loading state during initialization
|
|
51
|
+
- **ALWAYS** check isPremium before showing premium features
|
|
52
|
+
- **NEVER** trust client-side state for security
|
|
73
53
|
|
|
74
|
-
|
|
54
|
+
## AI Agent Guidelines
|
|
75
55
|
|
|
76
|
-
|
|
77
|
-
function PremiumCreditsManager() {
|
|
78
|
-
const { user } = useAuth();
|
|
79
|
-
const { isPremium } = usePremium();
|
|
56
|
+
### When Implementing Premium + Credits
|
|
80
57
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} = usePremiumWithCredits({
|
|
87
|
-
userId: user?.uid,
|
|
88
|
-
isPremium,
|
|
89
|
-
});
|
|
58
|
+
1. **Always** provide valid userId
|
|
59
|
+
2. **Always** provide isPremium status
|
|
60
|
+
3. **Always** handle loading state
|
|
61
|
+
4. **Always** call ensureCreditsInitialized for premium users
|
|
62
|
+
5. **Never** manually initialize credits without checking isPremium
|
|
90
63
|
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
if (isPremium && !credits) {
|
|
94
|
-
console.log('User is premium but has no credits, initializing...');
|
|
95
|
-
ensureCreditsInitialized();
|
|
96
|
-
}
|
|
97
|
-
}, [isPremium, credits]);
|
|
64
|
+
### Integration Checklist
|
|
98
65
|
|
|
99
|
-
|
|
66
|
+
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
67
|
+
- [ ] Provide valid userId
|
|
68
|
+
- [ ] Provide isPremium from usePremium
|
|
69
|
+
- [ ] Handle loading state
|
|
70
|
+
- [ ] Call ensureCreditsInitialized when isPremium is true
|
|
71
|
+
- [ ] Test with premium user (no credits)
|
|
72
|
+
- [ ] Test with premium user (has credits)
|
|
73
|
+
- [ ] Test with free user
|
|
74
|
+
- [ ] Test subscription upgrade flow
|
|
75
|
+
- [ ] Test error scenarios
|
|
100
76
|
|
|
101
|
-
|
|
102
|
-
<View>
|
|
103
|
-
<CreditBalance credits={credits} />
|
|
104
|
-
<TransactionHistory transactions={transactions} />
|
|
105
|
-
</View>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
```
|
|
77
|
+
### Common Patterns
|
|
109
78
|
|
|
110
|
-
|
|
79
|
+
1. **Auto-Initialization**: Automatically initialize credits for premium users
|
|
80
|
+
2. **Subscription Change Detection**: Detect when user subscribes
|
|
81
|
+
3. **Premium Benefits Display**: Show credits along with premium status
|
|
82
|
+
4. **Subscription Monitor**: Refresh status periodically
|
|
83
|
+
5. **Manual Init**: Provide button for manual initialization
|
|
111
84
|
|
|
112
|
-
|
|
113
|
-
function SubscriptionWatcher() {
|
|
114
|
-
const { user } = useAuth();
|
|
115
|
-
const { isPremium } = usePremium();
|
|
85
|
+
## Related Documentation
|
|
116
86
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
// User just subscribed
|
|
126
|
-
if (isPremium && !previousPremium.current) {
|
|
127
|
-
console.log('User subscribed to premium!');
|
|
128
|
-
ensureCreditsInitialized();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
previousPremium.current = isPremium;
|
|
132
|
-
}, [isPremium]);
|
|
133
|
-
|
|
134
|
-
return (
|
|
135
|
-
<View>
|
|
136
|
-
<Text>Status: {isPremium ? 'Premium' : 'Free'}</Text>
|
|
137
|
-
<Text>Credits: {credits || 0}</Text>
|
|
138
|
-
</View>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### With Manual Initialization
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
function ManualCreditInit() {
|
|
147
|
-
const { user } = useAuth();
|
|
148
|
-
const { isPremium } = usePremium();
|
|
149
|
-
|
|
150
|
-
const { credits, isLoading, ensureCreditsInitialized } = usePremiumWithCredits({
|
|
151
|
-
userId: user?.uid,
|
|
152
|
-
isPremium,
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const handleInitializeCredits = async () => {
|
|
156
|
-
if (!isPremium) {
|
|
157
|
-
Alert.alert('Premium Required', 'This feature requires a subscription');
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (credits) {
|
|
162
|
-
Alert.alert('Already Initialized', 'Credits are already set up');
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
await ensureCreditsInitialized();
|
|
167
|
-
Alert.alert('Success', 'Credits initialized successfully');
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<View>
|
|
172
|
-
<Text>Credits: {credits || 'Not initialized'}</Text>
|
|
173
|
-
|
|
174
|
-
{!credits && isPremium && (
|
|
175
|
-
<Button
|
|
176
|
-
onPress={handleInitializeCredits}
|
|
177
|
-
disabled={isLoading}
|
|
178
|
-
title="Initialize Credits"
|
|
179
|
-
/>
|
|
180
|
-
)}
|
|
181
|
-
</View>
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### With Error Handling
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
function RobustCreditManager() {
|
|
190
|
-
const { user } = useAuth();
|
|
191
|
-
const { isPremium } = usePremium();
|
|
192
|
-
|
|
193
|
-
const {
|
|
194
|
-
credits,
|
|
195
|
-
error,
|
|
196
|
-
isLoading,
|
|
197
|
-
ensureCreditsInitialized,
|
|
198
|
-
} = usePremiumWithCredits({
|
|
199
|
-
userId: user?.uid,
|
|
200
|
-
isPremium,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
useEffect(() => {
|
|
204
|
-
if (error) {
|
|
205
|
-
console.error('Credits error:', error);
|
|
206
|
-
Alert.alert('Error', 'Failed to load credits');
|
|
207
|
-
}
|
|
208
|
-
}, [error]);
|
|
209
|
-
|
|
210
|
-
const handleRetry = async () => {
|
|
211
|
-
try {
|
|
212
|
-
await ensureCreditsInitialized();
|
|
213
|
-
} catch (err) {
|
|
214
|
-
Alert.alert('Error', 'Failed to initialize credits');
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
if (isLoading) return <LoadingScreen />;
|
|
219
|
-
|
|
220
|
-
return (
|
|
221
|
-
<View>
|
|
222
|
-
<Text>Credits: {credits || 0}</Text>
|
|
223
|
-
|
|
224
|
-
{error && (
|
|
225
|
-
<Button onPress={handleRetry} title="Retry" />
|
|
226
|
-
)}
|
|
227
|
-
</View>
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## Examples
|
|
233
|
-
|
|
234
|
-
### Premium Onboarding Flow
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
function PremiumOnboarding() {
|
|
238
|
-
const { user } = useAuth();
|
|
239
|
-
const { isPremium } = usePremium();
|
|
240
|
-
|
|
241
|
-
const {
|
|
242
|
-
credits,
|
|
243
|
-
isLoading,
|
|
244
|
-
ensureCreditsInitialized,
|
|
245
|
-
} = usePremiumWithCredits({
|
|
246
|
-
userId: user?.uid,
|
|
247
|
-
isPremium,
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
useEffect(() => {
|
|
251
|
-
// Auto-initialize credits for new premium users
|
|
252
|
-
if (isPremium && !credits && !isLoading) {
|
|
253
|
-
const initialize = async () => {
|
|
254
|
-
await ensureCreditsInitialized();
|
|
255
|
-
analytics.track('premium_credits_initialized', {
|
|
256
|
-
userId: user?.uid,
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
initialize();
|
|
260
|
-
}
|
|
261
|
-
}, [isPremium, credits, isLoading]);
|
|
262
|
-
|
|
263
|
-
if (!isPremium) {
|
|
264
|
-
return <PremiumUpgradePrompt />;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (isLoading) {
|
|
268
|
-
return <LoadingScreen message="Setting up your account..." />;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return (
|
|
272
|
-
<View>
|
|
273
|
-
<CongratulationsMessage />
|
|
274
|
-
|
|
275
|
-
<CreditCard credits={credits} />
|
|
276
|
-
|
|
277
|
-
<Button
|
|
278
|
-
onPress={() => navigation.navigate('Home')}
|
|
279
|
-
title="Get Started"
|
|
280
|
-
/>
|
|
281
|
-
</View>
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### Premium Benefits Display
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
function PremiumBenefits() {
|
|
290
|
-
const { user } = useAuth();
|
|
291
|
-
const { isPremium } = usePremium();
|
|
292
|
-
|
|
293
|
-
const { credits, balance, transactions } = usePremiumWithCredits({
|
|
294
|
-
userId: user?.uid,
|
|
295
|
-
isPremium,
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
return (
|
|
299
|
-
<ScrollView>
|
|
300
|
-
<PremiumBadge />
|
|
301
|
-
|
|
302
|
-
<View style={styles.section}>
|
|
303
|
-
<Text style={styles.title}>Your Premium Benefits</Text>
|
|
304
|
-
<BenefitItem icon="✓" text="Ad-free experience" />
|
|
305
|
-
<BenefitItem icon="✓" text="Unlimited access" />
|
|
306
|
-
<BenefitItem icon="✓" text={`${credits} monthly credits`} />
|
|
307
|
-
<BenefitItem icon="✓" text="Priority support" />
|
|
308
|
-
</View>
|
|
309
|
-
|
|
310
|
-
<View style={styles.section}>
|
|
311
|
-
<Text style={styles.title}>Credit Balance</Text>
|
|
312
|
-
<Text style={styles.balance}>{credits} Credits</Text>
|
|
313
|
-
<Text style={styles.value}>Worth ~${balance.toFixed(2)}</Text>
|
|
314
|
-
</View>
|
|
315
|
-
|
|
316
|
-
<View style={styles.section}>
|
|
317
|
-
<Text style={styles.title}>Recent Activity</Text>
|
|
318
|
-
{transactions.slice(0, 5).map((tx) => (
|
|
319
|
-
<TransactionItem key={tx.id} transaction={tx} />
|
|
320
|
-
))}
|
|
321
|
-
</View>
|
|
322
|
-
</ScrollView>
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Subscription Status Monitor
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
function SubscriptionMonitor() {
|
|
331
|
-
const { user } = useAuth();
|
|
332
|
-
const { isPremium } = usePremium();
|
|
333
|
-
|
|
334
|
-
const {
|
|
335
|
-
credits,
|
|
336
|
-
isLoading,
|
|
337
|
-
ensureCreditsInitialized,
|
|
338
|
-
} = usePremiumWithCredits({
|
|
339
|
-
userId: user?.uid,
|
|
340
|
-
isPremium,
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
const [lastChecked, setLastChecked] = useState<Date | null>(null);
|
|
344
|
-
|
|
345
|
-
const handleRefresh = async () => {
|
|
346
|
-
await ensureCreditsInitialized();
|
|
347
|
-
setLastChecked(new Date());
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
useEffect(() => {
|
|
351
|
-
// Periodic refresh every 5 minutes
|
|
352
|
-
const interval = setInterval(() => {
|
|
353
|
-
if (isPremium) {
|
|
354
|
-
handleRefresh();
|
|
355
|
-
}
|
|
356
|
-
}, 5 * 60 * 1000);
|
|
357
|
-
|
|
358
|
-
return () => clearInterval(interval);
|
|
359
|
-
}, [isPremium]);
|
|
360
|
-
|
|
361
|
-
return (
|
|
362
|
-
<View>
|
|
363
|
-
<Text>Subscription Status: {isPremium ? 'Active' : 'Inactive'}</Text>
|
|
364
|
-
<Text>Credits: {credits || 0}</Text>
|
|
365
|
-
{lastChecked && (
|
|
366
|
-
<Text>Last checked: {lastChecked.toLocaleTimeString()}</Text>
|
|
367
|
-
)}
|
|
368
|
-
|
|
369
|
-
<Button
|
|
370
|
-
onPress={handleRefresh}
|
|
371
|
-
disabled={isLoading}
|
|
372
|
-
title="Refresh Status"
|
|
373
|
-
/>
|
|
374
|
-
</View>
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
## How It Works
|
|
380
|
-
|
|
381
|
-
### Automatic Initialization
|
|
382
|
-
|
|
383
|
-
The hook automatically:
|
|
384
|
-
|
|
385
|
-
1. **Detects premium status** - Checks if user is premium
|
|
386
|
-
2. **Monitors credits** - Watches credits value
|
|
387
|
-
3. **Initializes when needed** - Calls init if premium but no credits
|
|
388
|
-
4. **Prevents duplicate inits** - Won't initialize if credits exist
|
|
389
|
-
5. **Handles loading** - Shows loading state during initialization
|
|
390
|
-
|
|
391
|
-
```typescript
|
|
392
|
-
// Premium user without credits
|
|
393
|
-
isPremium = true
|
|
394
|
-
credits = undefined
|
|
395
|
-
→ Auto-initializes credits ✅
|
|
396
|
-
|
|
397
|
-
// Premium user with credits
|
|
398
|
-
isPremium = true
|
|
399
|
-
credits = 100
|
|
400
|
-
→ No initialization needed ✅
|
|
401
|
-
|
|
402
|
-
// Free user
|
|
403
|
-
isPremium = false
|
|
404
|
-
credits = undefined
|
|
405
|
-
→ No initialization (not premium) ✅
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
## Best Practices
|
|
409
|
-
|
|
410
|
-
1. **Trust the hook** - Let it handle auto-initialization
|
|
411
|
-
2. **Monitor loading** - Show loading during initialization
|
|
412
|
-
3. **Handle errors** - Catch and display init failures
|
|
413
|
-
4. **Track events** - Log credit initialization
|
|
414
|
-
5. **Refresh periodically** - Keep credits up to date
|
|
415
|
-
6. **Check premium first** - Verify user is premium before showing features
|
|
416
|
-
7. **Test scenarios** - Test new subscription, existing subscription, cancellation
|
|
417
|
-
|
|
418
|
-
## Related Hooks
|
|
419
|
-
|
|
420
|
-
- **useCredits** - Credits management
|
|
421
|
-
- **useInitializeCredits** - Manual credit initialization
|
|
422
|
-
- **usePremium** - Premium status
|
|
423
|
-
- **useDeductCredit** - Credit deduction
|
|
424
|
-
|
|
425
|
-
## See Also
|
|
426
|
-
|
|
427
|
-
- [Credits System](../../../domains/wallet/README.md)
|
|
428
|
-
- [Premium Integration](../../../docs/PREMIUM_INTEGRATION.md)
|
|
429
|
-
- [Credits README](./useCredits.md)
|
|
87
|
+
- **useCredits**: Credits management
|
|
88
|
+
- **useInitializeCredits**: Manual credit initialization
|
|
89
|
+
- **usePremium**: Premium status
|
|
90
|
+
- **useDeductCredit**: Credit deduction
|
|
91
|
+
- **Credits System**: `src/domains/wallet/README.md`
|
|
92
|
+
- **Premium Integration**: `src/docs/PREMIUM_INTEGRATION.md`
|