@umituz/react-native-subscription 2.14.96 → 2.14.98
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/LICENSE +21 -0
- package/README.md +462 -0
- package/package.json +3 -3
- package/src/application/README.md +229 -0
- package/src/application/ports/README.md +103 -0
- package/src/domain/README.md +402 -0
- package/src/domain/constants/README.md +80 -0
- package/src/domain/entities/README.md +176 -0
- package/src/domain/errors/README.md +307 -0
- package/src/domain/value-objects/README.md +186 -0
- package/src/domains/config/README.md +390 -0
- package/src/domains/paywall/README.md +371 -0
- package/src/domains/paywall/components/PaywallHeader.tsx +8 -11
- package/src/domains/paywall/components/README.md +185 -0
- package/src/domains/paywall/entities/README.md +199 -0
- package/src/domains/paywall/hooks/README.md +129 -0
- package/src/domains/wallet/README.md +292 -0
- package/src/domains/wallet/domain/README.md +108 -0
- package/src/domains/wallet/domain/entities/README.md +122 -0
- package/src/domains/wallet/domain/errors/README.md +157 -0
- package/src/domains/wallet/infrastructure/README.md +96 -0
- package/src/domains/wallet/presentation/components/BalanceCard.tsx +6 -12
- package/src/domains/wallet/presentation/components/README.md +231 -0
- package/src/domains/wallet/presentation/hooks/README.md +255 -0
- package/src/infrastructure/README.md +514 -0
- package/src/infrastructure/mappers/README.md +34 -0
- package/src/infrastructure/models/README.md +26 -0
- package/src/infrastructure/repositories/README.md +385 -0
- package/src/infrastructure/services/README.md +374 -0
- package/src/presentation/README.md +410 -0
- package/src/presentation/components/README.md +183 -0
- package/src/presentation/components/details/CreditRow.md +337 -0
- package/src/presentation/components/details/DetailRow.md +283 -0
- package/src/presentation/components/details/PremiumDetailsCard.md +266 -0
- package/src/presentation/components/details/PremiumStatusBadge.md +266 -0
- package/src/presentation/components/details/README.md +449 -0
- package/src/presentation/components/feedback/PaywallFeedbackModal.md +314 -0
- package/src/presentation/components/feedback/README.md +447 -0
- package/src/presentation/components/paywall/PaywallModal.md +444 -0
- package/src/presentation/components/paywall/README.md +190 -0
- package/src/presentation/components/sections/README.md +468 -0
- package/src/presentation/components/sections/SubscriptionSection.md +246 -0
- package/src/presentation/hooks/README.md +743 -0
- package/src/presentation/hooks/useAuthAwarePurchase.md +359 -0
- package/src/presentation/hooks/useAuthGate.md +403 -0
- package/src/presentation/hooks/useAuthSubscriptionSync.md +398 -0
- package/src/presentation/hooks/useCreditChecker.md +407 -0
- package/src/presentation/hooks/useCredits.md +342 -0
- package/src/presentation/hooks/useCreditsGate.md +346 -0
- package/src/presentation/hooks/useDeductCredit.md +160 -0
- package/src/presentation/hooks/useDevTestCallbacks.md +422 -0
- package/src/presentation/hooks/useFeatureGate.md +157 -0
- package/src/presentation/hooks/useInitializeCredits.md +458 -0
- package/src/presentation/hooks/usePaywall.md +334 -0
- package/src/presentation/hooks/usePaywallOperations.md +486 -0
- package/src/presentation/hooks/usePaywallVisibility.md +344 -0
- package/src/presentation/hooks/usePremium.md +230 -0
- package/src/presentation/hooks/usePremiumGate.md +423 -0
- package/src/presentation/hooks/usePremiumWithCredits.md +429 -0
- package/src/presentation/hooks/useSubscription.md +450 -0
- package/src/presentation/hooks/useSubscriptionDetails.md +438 -0
- package/src/presentation/hooks/useSubscriptionGate.md +168 -0
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +374 -0
- package/src/presentation/hooks/useSubscriptionStatus.md +424 -0
- package/src/presentation/hooks/useUserTier.md +356 -0
- package/src/presentation/hooks/useUserTierWithRepository.md +452 -0
- package/src/presentation/screens/README.md +194 -0
- package/src/presentation/types/README.md +38 -0
- package/src/presentation/utils/README.md +52 -0
- package/src/revenuecat/README.md +523 -0
- package/src/revenuecat/domain/README.md +147 -0
- package/src/revenuecat/domain/errors/README.md +197 -0
- package/src/revenuecat/infrastructure/config/README.md +40 -0
- package/src/revenuecat/infrastructure/managers/README.md +49 -0
- package/src/revenuecat/presentation/hooks/README.md +56 -0
- package/src/revenuecat/presentation/hooks/usePurchasePackage.ts +1 -1
- package/src/utils/README.md +529 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Wallet Presentation Hooks
|
|
2
|
+
|
|
3
|
+
React hooks for wallet and credit functionality.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This directory contains React hooks specifically for credit management and wallet operations.
|
|
8
|
+
|
|
9
|
+
## Hooks
|
|
10
|
+
|
|
11
|
+
### useCredits
|
|
12
|
+
Access and manage credit balance.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function useCredits(params: {
|
|
16
|
+
userId: string | undefined;
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
}): {
|
|
19
|
+
credits: number;
|
|
20
|
+
balance: number;
|
|
21
|
+
transactions: Transaction[];
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
error: Error | null;
|
|
24
|
+
refetch: () => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Usage:**
|
|
29
|
+
```typescript
|
|
30
|
+
function CreditBalance() {
|
|
31
|
+
const { credits, isLoading } = useCredits({ userId: user?.uid });
|
|
32
|
+
|
|
33
|
+
if (isLoading) return <LoadingSpinner />;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<View>
|
|
37
|
+
<Text>Balance: {credits} credits</Text>
|
|
38
|
+
</View>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### useDeductCredit
|
|
44
|
+
Deduct credits with optimistic updates.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
function useDeductCredit(params: {
|
|
48
|
+
userId: string | undefined;
|
|
49
|
+
onCreditsExhausted?: () => void;
|
|
50
|
+
}): {
|
|
51
|
+
deductCredit: (cost?: number) => Promise<boolean>;
|
|
52
|
+
deductCredits: (cost: number) => Promise<boolean>;
|
|
53
|
+
isDeducting: boolean;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Usage:**
|
|
58
|
+
```typescript
|
|
59
|
+
function AIGeneration() {
|
|
60
|
+
const { deductCredit } = useDeductCredit({
|
|
61
|
+
userId: user?.uid,
|
|
62
|
+
onCreditsExhausted: () => showPaywall(),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const handleGenerate = async () => {
|
|
66
|
+
const success = await deductCredit(5);
|
|
67
|
+
if (success) {
|
|
68
|
+
await callAIGenerationAPI();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### useInitializeCredits
|
|
75
|
+
Initialize credits after purchase.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
function useInitializeCredits(params: {
|
|
79
|
+
userId: string | undefined;
|
|
80
|
+
}): {
|
|
81
|
+
initializeCredits: (options?: {
|
|
82
|
+
purchaseId?: string;
|
|
83
|
+
productId?: string;
|
|
84
|
+
}) => Promise<boolean>;
|
|
85
|
+
isInitializing: boolean;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Usage:**
|
|
90
|
+
```typescript
|
|
91
|
+
function PurchaseCompletion() {
|
|
92
|
+
const { initializeCredits } = useInitializeCredits({
|
|
93
|
+
userId: user?.uid,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const handlePurchaseComplete = async (transaction: Purchase) => {
|
|
97
|
+
const success = await initializeCredits({
|
|
98
|
+
purchaseId: transaction.transactionId,
|
|
99
|
+
productId: transaction.productId,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (success) {
|
|
103
|
+
Alert.alert('Success', 'Credits added!');
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### useCreditChecker
|
|
110
|
+
Check credit availability before operations.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
function useCreditChecker(params?: {
|
|
114
|
+
onCreditDeducted?: (userId: string, cost: number) => void;
|
|
115
|
+
}): {
|
|
116
|
+
checkCreditsAvailable: (
|
|
117
|
+
userId: string | undefined,
|
|
118
|
+
cost?: number
|
|
119
|
+
) => Promise<CreditCheckResult>;
|
|
120
|
+
deductCreditsAfterSuccess: (
|
|
121
|
+
userId: string | undefined,
|
|
122
|
+
cost?: number
|
|
123
|
+
) => Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Usage:**
|
|
128
|
+
```typescript
|
|
129
|
+
function PreCheckFeature() {
|
|
130
|
+
const { checkCreditsAvailable } = useCreditChecker();
|
|
131
|
+
|
|
132
|
+
const handleCheck = async () => {
|
|
133
|
+
const result = await checkCreditsAvailable(user?.uid, 10);
|
|
134
|
+
|
|
135
|
+
if (!result.canProceed) {
|
|
136
|
+
Alert.alert(
|
|
137
|
+
'Insufficient Credits',
|
|
138
|
+
`You need ${result.required} credits but have ${result.currentBalance}`
|
|
139
|
+
);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
await executeFeature();
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Usage Patterns
|
|
149
|
+
|
|
150
|
+
### Two-Step Credit Process
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
function TwoStepCreditProcess() {
|
|
154
|
+
const { checkCreditsAvailable } = useCreditChecker();
|
|
155
|
+
const { deductCreditsAfterSuccess } = useCreditChecker();
|
|
156
|
+
|
|
157
|
+
const handleOperation = async () => {
|
|
158
|
+
// Step 1: Check credits
|
|
159
|
+
const check = await checkCreditsAvailable(user?.uid, 10);
|
|
160
|
+
|
|
161
|
+
if (!check.canProceed) {
|
|
162
|
+
showPaywall({ required: 10 });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
// Step 2: Perform operation
|
|
168
|
+
await performOperation();
|
|
169
|
+
|
|
170
|
+
// Step 3: Deduct credits after success
|
|
171
|
+
await deductCreditsAfterSuccess(user?.uid, 10);
|
|
172
|
+
|
|
173
|
+
Alert.alert('Success', 'Operation completed');
|
|
174
|
+
} catch (error) {
|
|
175
|
+
Alert.alert('Error', 'Operation failed');
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### With Loading and Error States
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
function CreditOperation() {
|
|
185
|
+
const { credits, isLoading, error } = useCredits({ userId: user?.uid });
|
|
186
|
+
const { deductCredit } = useDeductCredit({
|
|
187
|
+
userId: user?.uid,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const handleDeduct = async () => {
|
|
191
|
+
if (isLoading) return;
|
|
192
|
+
|
|
193
|
+
const success = await deductCredit(5);
|
|
194
|
+
|
|
195
|
+
if (success) {
|
|
196
|
+
await executeFeature();
|
|
197
|
+
} else {
|
|
198
|
+
Alert.alert('Failed', 'Could not deduct credits');
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<View>
|
|
204
|
+
{error && <ErrorBanner message={error.message} />}
|
|
205
|
+
{isLoading ? (
|
|
206
|
+
<LoadingSpinner />
|
|
207
|
+
) : (
|
|
208
|
+
<>
|
|
209
|
+
<Text>Credits: {credits}</Text>
|
|
210
|
+
<Button onPress={handleDeduct} disabled={isLoading}>
|
|
211
|
+
Use 5 Credits
|
|
212
|
+
</Button>
|
|
213
|
+
</>
|
|
214
|
+
)}
|
|
215
|
+
</View>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### With Auto-Initialization
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
function AutoInitialize() {
|
|
224
|
+
const { isPremium } = usePremium();
|
|
225
|
+
const { credits } = useCredits({ userId: user?.uid });
|
|
226
|
+
const { initializeCredits, isInitializing } = useInitializeCredits({
|
|
227
|
+
userId: user?.uid,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
// Auto-initialize if premium but no credits
|
|
232
|
+
if (isPremium && !credits && !isInitializing) {
|
|
233
|
+
initializeCredits();
|
|
234
|
+
}
|
|
235
|
+
}, [isPremium, credits]);
|
|
236
|
+
|
|
237
|
+
return <YourComponent />;
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Best Practices
|
|
242
|
+
|
|
243
|
+
1. **Check Balance First**: Always check before deducting
|
|
244
|
+
2. **Handle Loading**: Show loading states appropriately
|
|
245
|
+
3. **Error Recovery**: Handle deduction failures gracefully
|
|
246
|
+
4. **Optimistic Updates**: Use optimistic updates for better UX
|
|
247
|
+
5. **Track Usage**: Log all credit operations
|
|
248
|
+
6. **Auto-Init**: Initialize credits after premium purchase
|
|
249
|
+
7. **Test Scenarios**: Test zero credits, max credits, failures
|
|
250
|
+
|
|
251
|
+
## Related
|
|
252
|
+
|
|
253
|
+
- [useCredits Hook Documentation](../../../presentation/hooks/useCredits.md)
|
|
254
|
+
- [useDeductCredit Hook Documentation](../../../presentation/hooks/useDeductCredit.md)
|
|
255
|
+
- [Credits Entity](../../domain/entities/README.md)
|