@umituz/react-native-subscription 2.14.99 → 2.14.100
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 +1 -1
- 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/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/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/README.md +95 -370
- 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/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/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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Presentation Components
|
|
2
|
+
|
|
3
|
+
React Native UI components for subscription and paywall features.
|
|
4
|
+
|
|
5
|
+
## Location
|
|
6
|
+
|
|
7
|
+
**Directory**: `src/presentation/components/`
|
|
8
|
+
|
|
9
|
+
**Type**: Component Library
|
|
10
|
+
|
|
11
|
+
## Strategy
|
|
12
|
+
|
|
13
|
+
### Component Categories
|
|
14
|
+
|
|
15
|
+
Components are organized by functionality:
|
|
16
|
+
|
|
17
|
+
1. **Details Components**
|
|
18
|
+
- CreditRow: Display credit balance and info
|
|
19
|
+
- DetailRow: Generic detail display row
|
|
20
|
+
- PremiumStatusBadge: Visual premium indicator
|
|
21
|
+
- PremiumDetailsCard: Premium subscription details
|
|
22
|
+
|
|
23
|
+
2. **Feedback Components**
|
|
24
|
+
- PaywallFeedbackModal: User feedback collection
|
|
25
|
+
- Alert components: Warning and info displays
|
|
26
|
+
|
|
27
|
+
3. **Section Components**
|
|
28
|
+
- SubscriptionSection: Subscription info section
|
|
29
|
+
- CreditsSection: Credits balance section
|
|
30
|
+
|
|
31
|
+
4. **Paywall Components**
|
|
32
|
+
- PaywallModal: Upgrade/purchase modal
|
|
33
|
+
- Purchase options: Subscription and credit packages
|
|
34
|
+
|
|
35
|
+
### Design Principles
|
|
36
|
+
|
|
37
|
+
All components follow these principles:
|
|
38
|
+
- **Reusable**: Composable and configurable
|
|
39
|
+
- **Typed**: Full TypeScript support
|
|
40
|
+
- **Accessible**: WCAG compliant where possible
|
|
41
|
+
- **Testable**: Easy to test in isolation
|
|
42
|
+
- **Themeable**: Support custom styling
|
|
43
|
+
|
|
44
|
+
### Integration Points
|
|
45
|
+
|
|
46
|
+
- **React Native**: Core UI framework
|
|
47
|
+
- **Design System**: Shared UI components
|
|
48
|
+
- **Localization**: i18n string support
|
|
49
|
+
- **Theme**: Custom styling support
|
|
50
|
+
|
|
51
|
+
## Restrictions
|
|
52
|
+
|
|
53
|
+
### REQUIRED
|
|
54
|
+
|
|
55
|
+
- **Props Typing**: All components MUST have TypeScript interfaces
|
|
56
|
+
- **Default Props**: MUST provide sensible defaults
|
|
57
|
+
- **Accessibility**: MUST implement accessibility labels
|
|
58
|
+
- **Responsive**: MUST handle different screen sizes
|
|
59
|
+
|
|
60
|
+
### PROHIBITED
|
|
61
|
+
|
|
62
|
+
- **NEVER** hardcode colors or sizes (use theme)
|
|
63
|
+
- **NEVER** include business logic in components
|
|
64
|
+
- **DO NOT** make direct API calls
|
|
65
|
+
- **NEVER** hardcode strings (use localization)
|
|
66
|
+
|
|
67
|
+
### CRITICAL SAFETY
|
|
68
|
+
|
|
69
|
+
- **ALWAYS** validate props before rendering
|
|
70
|
+
- **ALWAYS** handle loading and error states
|
|
71
|
+
- **NEVER** trust user input for security decisions
|
|
72
|
+
- **MUST** implement proper error boundaries
|
|
73
|
+
- **ALWAYS** sanitize user-provided content
|
|
74
|
+
|
|
75
|
+
## Rules
|
|
76
|
+
|
|
77
|
+
### Component Structure
|
|
78
|
+
|
|
79
|
+
**CORRECT**: Proper component structure
|
|
80
|
+
- Define TypeScript interface for component props
|
|
81
|
+
- List all required props (amount, isLoading, onPress)
|
|
82
|
+
- List optional props with question marks
|
|
83
|
+
- Destructure props in function signature
|
|
84
|
+
- Check loading state and return SkeletonLoader
|
|
85
|
+
- Render TouchableOpacity with conditional disabled
|
|
86
|
+
- Display text content
|
|
87
|
+
|
|
88
|
+
**INCORRECT**: No props interface
|
|
89
|
+
- Don't create components without TypeScript interfaces
|
|
90
|
+
- Never omit type definitions for props
|
|
91
|
+
- Don't use any type or skip type checking
|
|
92
|
+
|
|
93
|
+
### Theme Usage
|
|
94
|
+
|
|
95
|
+
**CORRECT**: Use theme for styling
|
|
96
|
+
- Import and use useTheme hook
|
|
97
|
+
- Access colors from theme object
|
|
98
|
+
- Apply theme colors to styles
|
|
99
|
+
- Use semantic color names (primary, onPrimary)
|
|
100
|
+
|
|
101
|
+
**INCORRECT**: Hardcoded colors
|
|
102
|
+
- Don't use hex color codes directly in styles
|
|
103
|
+
- Never hardcode values like '#007AFF' or '#FFFFFF'
|
|
104
|
+
- Don't skip theme integration
|
|
105
|
+
- Avoid inline color values
|
|
106
|
+
|
|
107
|
+
### Accessibility
|
|
108
|
+
|
|
109
|
+
**CORRECT**: Accessibility support
|
|
110
|
+
- Define accessibilityLabel prop for Button
|
|
111
|
+
- Define accessibilityHint for additional context
|
|
112
|
+
- Set accessibilityState with disabled condition
|
|
113
|
+
- Provide clear, descriptive labels
|
|
114
|
+
- Include hints for complex interactions
|
|
115
|
+
|
|
116
|
+
**INCORRECT**: No accessibility
|
|
117
|
+
- Don't create components without a11y labels
|
|
118
|
+
- Never skip accessibilityHint for complex UI
|
|
119
|
+
- Don't omit accessibilityState for interactive elements
|
|
120
|
+
- Avoid non-descriptive labels
|
|
121
|
+
|
|
122
|
+
### Conditional Rendering
|
|
123
|
+
|
|
124
|
+
**CORRECT**: Handle all states
|
|
125
|
+
- Check if loading and return SkeletonLoader
|
|
126
|
+
- Check if error and return ErrorDisplay
|
|
127
|
+
- Check if credits is undefined and return Placeholder
|
|
128
|
+
- Render content only when all states are valid
|
|
129
|
+
- Handle all possible state combinations
|
|
130
|
+
|
|
131
|
+
**INCORRECT**: Incomplete state handling
|
|
132
|
+
- Don't render content without checking error state
|
|
133
|
+
- Never assume data is always defined
|
|
134
|
+
- Don't skip placeholder for undefined data
|
|
135
|
+
- Avoid incomplete conditional chains
|
|
136
|
+
|
|
137
|
+
## AI Agent Guidelines
|
|
138
|
+
|
|
139
|
+
### When Building Components
|
|
140
|
+
|
|
141
|
+
1. **Always** define TypeScript interfaces for props
|
|
142
|
+
2. **Always** use theme for styling (no hardcoded values)
|
|
143
|
+
3. **Always** implement accessibility labels
|
|
144
|
+
4. **Always** handle loading and error states
|
|
145
|
+
5. **Never** include business logic in components
|
|
146
|
+
|
|
147
|
+
### Integration Checklist
|
|
148
|
+
|
|
149
|
+
- [ ] Define TypeScript interface for props
|
|
150
|
+
- [ ] Use theme for all styling
|
|
151
|
+
- [ ] Implement accessibility labels
|
|
152
|
+
- [ ] Handle loading state
|
|
153
|
+
- [ ] Handle error state
|
|
154
|
+
- [ ] Provide sensible defaults
|
|
155
|
+
- [ ] Test with different screen sizes
|
|
156
|
+
- [ ] Test accessibility
|
|
157
|
+
- [ ] Test with various prop combinations
|
|
158
|
+
- [ ] Document component usage
|
|
159
|
+
|
|
160
|
+
### Common Patterns
|
|
161
|
+
|
|
162
|
+
1. **Compound Components**: Build complex UIs from simple parts
|
|
163
|
+
2. **Render Props**: Share stateful logic
|
|
164
|
+
3. **Slot Pattern**: Allow content injection
|
|
165
|
+
4. **Control Props**: Make components controlled or uncontrolled
|
|
166
|
+
5. **Asynchronous States**: Handle loading, error, success states
|
|
167
|
+
6. **Responsive Design**: Adapt to different screen sizes
|
|
168
|
+
7. **Theme Integration**: Use design system tokens
|
|
169
|
+
8. **Accessibility First**: Include a11y from the start
|
|
170
|
+
|
|
171
|
+
## Related Documentation
|
|
172
|
+
|
|
173
|
+
- **Details Components**: `details/README.md`
|
|
174
|
+
- **Feedback Components**: `feedback/README.md`
|
|
175
|
+
- **Section Components**: `sections/README.md`
|
|
176
|
+
- **Paywall Components**: `paywall/README.md`
|
|
177
|
+
- **Design System**: External design system documentation
|
|
178
|
+
- **Hooks**: `../hooks/README.md`
|
|
179
|
+
|
|
180
|
+
## Component Examples
|
|
181
|
+
|
|
182
|
+
### CreditRow
|
|
183
|
+
|
|
184
|
+
Display user's credit balance with optional actions.
|
|
185
|
+
|
|
186
|
+
Usage:
|
|
187
|
+
- Set amount prop to number of credits
|
|
188
|
+
- Set isLoading to true during data fetch
|
|
189
|
+
- Provide onPress callback for navigation
|
|
190
|
+
- Component displays credit count and handles tap
|
|
191
|
+
|
|
192
|
+
### PremiumStatusBadge
|
|
193
|
+
|
|
194
|
+
Visual indicator for premium subscription status.
|
|
195
|
+
|
|
196
|
+
Usage:
|
|
197
|
+
- Set isPremium to boolean status
|
|
198
|
+
- Set tier to subscription level (gold, silver, etc.)
|
|
199
|
+
- Component renders styled badge
|
|
200
|
+
|
|
201
|
+
### PaywallModal
|
|
202
|
+
|
|
203
|
+
Modal for subscription and credit purchase.
|
|
204
|
+
|
|
205
|
+
Usage:
|
|
206
|
+
- Set isVisible to boolean for show/hide
|
|
207
|
+
- Provide onClose callback
|
|
208
|
+
- Pass features array for premium features list
|
|
209
|
+
- Modal handles purchase flow
|
|
210
|
+
|
|
211
|
+
## Directory Structure
|
|
212
|
+
|
|
213
|
+
The components directory contains:
|
|
214
|
+
- **details/** - Detail display components (CreditRow, DetailRow, PremiumStatusBadge, PremiumDetailsCard)
|
|
215
|
+
- **feedback/** - Feedback and alert components (PaywallFeedbackModal)
|
|
216
|
+
- **sections/** - Section components (SubscriptionSection)
|
|
217
|
+
- **paywall/** - Paywall components (PaywallModal)
|
|
@@ -1,337 +1,92 @@
|
|
|
1
1
|
# CreditRow Component
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Row component displaying credit information with amount and label.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Location
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { CreditRow } from '@umituz/react-native-subscription';
|
|
9
|
-
```
|
|
7
|
+
**Import Path**: `@umituz/react-native-subscription`
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
**File**: `src/presentation/components/details/CreditRow.tsx`
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
interface CreditRowProps {
|
|
15
|
-
label: string;
|
|
16
|
-
current: number;
|
|
17
|
-
total: number;
|
|
18
|
-
remainingLabel?: string;
|
|
19
|
-
}
|
|
20
|
-
```
|
|
11
|
+
**Type**: Component
|
|
21
12
|
|
|
22
|
-
##
|
|
13
|
+
## Strategy
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|------|------|---------|-------------|
|
|
26
|
-
| `label` | `string` | **Required** | Credit type label |
|
|
27
|
-
| `current` | `number` | **Required** | Current credit amount |
|
|
28
|
-
| `total` | `number` | **Required** | Maximum credit amount |
|
|
29
|
-
| `remainingLabel` | `string` | `undefined` | Label for remaining text |
|
|
15
|
+
### Credit Information Display
|
|
30
16
|
|
|
31
|
-
|
|
17
|
+
1. **Amount Display**: Show credit amount with icon
|
|
18
|
+
2. **Label Display**: Show credit type or source label
|
|
19
|
+
3. **Visual Hierarchy**: Clear separation between amount and label
|
|
20
|
+
4. **Icon Integration**: Display appropriate icon for credit type
|
|
21
|
+
5. **Styling Options**: Support custom styling override
|
|
22
|
+
6. **Compact Layout**: Efficient use of space for list items
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
function CreditsDisplay() {
|
|
35
|
-
const { credits } = useCredits();
|
|
24
|
+
### Integration Points
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
total={100}
|
|
42
|
-
remainingLabel="credits remaining"
|
|
43
|
-
/>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
```
|
|
26
|
+
- **useCredits**: For credit balance and transaction data
|
|
27
|
+
- **Icon System**: For credit type icons
|
|
28
|
+
- **List Components**: For credit transaction lists
|
|
29
|
+
- **Settings UI**: For credits section in settings
|
|
47
30
|
|
|
48
|
-
##
|
|
31
|
+
## Restrictions
|
|
49
32
|
|
|
50
|
-
###
|
|
33
|
+
### REQUIRED
|
|
51
34
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
- **Amount Prop**: MUST provide valid credit amount
|
|
36
|
+
- **Label Prop**: MUST provide descriptive label
|
|
37
|
+
- **Icon Display**: SHOULD display appropriate icon
|
|
38
|
+
- **Null Handling**: MUST handle null or zero values
|
|
56
39
|
|
|
57
|
-
|
|
58
|
-
<View>
|
|
59
|
-
<CreditRow
|
|
60
|
-
label="Monthly Credits"
|
|
61
|
-
current={monthlyCredits}
|
|
62
|
-
total={100}
|
|
63
|
-
remainingLabel="credits left"
|
|
64
|
-
/>
|
|
40
|
+
### PROHIBITED
|
|
65
41
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
remainingLabel="bonus credits"
|
|
71
|
-
/>
|
|
42
|
+
- **NEVER** display without amount
|
|
43
|
+
- **NEVER** hardcode icon types
|
|
44
|
+
- **DO NOT** use for non-credit data
|
|
45
|
+
- **DO NOT** display negative amounts without clear indication
|
|
72
46
|
|
|
73
|
-
|
|
74
|
-
label="Reward Credits"
|
|
75
|
-
current={25}
|
|
76
|
-
total={100}
|
|
77
|
-
remainingLabel="rewards"
|
|
78
|
-
/>
|
|
79
|
-
</View>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
```
|
|
47
|
+
### CRITICAL SAFETY
|
|
83
48
|
|
|
84
|
-
|
|
49
|
+
- **ALWAYS** validate amount prop
|
|
50
|
+
- **MUST** handle zero or null amounts
|
|
51
|
+
- **ALWAYS** provide clear labels
|
|
52
|
+
- **NEVER** expose raw transaction data
|
|
85
53
|
|
|
86
|
-
|
|
87
|
-
function LiveCredits() {
|
|
88
|
-
const { credits, refetch } = useCredits();
|
|
54
|
+
## AI Agent Guidelines
|
|
89
55
|
|
|
90
|
-
|
|
91
|
-
const interval = setInterval(() => {
|
|
92
|
-
refetch();
|
|
93
|
-
}, 30000); // Update every 30 seconds
|
|
56
|
+
### When Implementing Credit Rows
|
|
94
57
|
|
|
95
|
-
|
|
96
|
-
|
|
58
|
+
1. **Always** provide valid amount
|
|
59
|
+
2. **Always** provide clear label
|
|
60
|
+
3. **Always** display appropriate icon
|
|
61
|
+
4. **Always** handle zero amounts
|
|
62
|
+
5. **Never** use for non-credit display
|
|
97
63
|
|
|
98
|
-
|
|
99
|
-
<CreditRow
|
|
100
|
-
label="Credits"
|
|
101
|
-
current={credits}
|
|
102
|
-
total={100}
|
|
103
|
-
remainingLabel="remaining"
|
|
104
|
-
/>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
```
|
|
64
|
+
### Integration Checklist
|
|
108
65
|
|
|
109
|
-
|
|
66
|
+
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
67
|
+
- [ ] Provide valid amount prop
|
|
68
|
+
- [ ] Provide clear label prop
|
|
69
|
+
- [ ] Display appropriate icon
|
|
70
|
+
- [ ] Handle zero amounts
|
|
71
|
+
- [ ] Handle null amounts
|
|
72
|
+
- [ ] Apply custom styling if needed
|
|
73
|
+
- [ ] Test with positive amount
|
|
74
|
+
- [ ] Test with zero amount
|
|
75
|
+
- [ ] Test in list context
|
|
76
|
+
- [ ] Test standalone display
|
|
110
77
|
|
|
111
|
-
|
|
112
|
-
function CreditWarning() {
|
|
113
|
-
const { credits } = useCredits();
|
|
78
|
+
### Common Patterns
|
|
114
79
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
remainingLabel={credits < 20 ? '⚠️ Low balance!' : 'credits remaining'}
|
|
121
|
-
/>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
```
|
|
80
|
+
1. **Transaction List**: Show credit transactions
|
|
81
|
+
2. **Balance Display**: Show current balance
|
|
82
|
+
3. **Allocation Breakdown**: Show credit sources
|
|
83
|
+
4. **History View**: Display transaction history
|
|
84
|
+
5. **Settings Section**: Credits section in settings
|
|
125
85
|
|
|
126
|
-
|
|
86
|
+
## Related Documentation
|
|
127
87
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// Calculate bonus credits from transactions
|
|
134
|
-
const bonusCredits = transactions
|
|
135
|
-
.filter(tx => tx.type === 'bonus')
|
|
136
|
-
.reduce((sum, tx) => sum + tx.amount, 0);
|
|
137
|
-
|
|
138
|
-
// Calculate total usage
|
|
139
|
-
const totalUsed = 100 - monthlyCredits + bonusCredits;
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<Card>
|
|
143
|
-
<Text style={styles.title}>Your Credits</Text>
|
|
144
|
-
|
|
145
|
-
<CreditRow
|
|
146
|
-
label="Monthly Credits"
|
|
147
|
-
current={monthlyCredits}
|
|
148
|
-
total={100}
|
|
149
|
-
remainingLabel="credits this month"
|
|
150
|
-
/>
|
|
151
|
-
|
|
152
|
-
<CreditRow
|
|
153
|
-
label="Bonus Credits"
|
|
154
|
-
current={bonusCredits}
|
|
155
|
-
total={50}
|
|
156
|
-
remainingLabel="bonus credits"
|
|
157
|
-
/>
|
|
158
|
-
|
|
159
|
-
<View style={styles.footer}>
|
|
160
|
-
<Text style={styles.info}>
|
|
161
|
-
Resets on {getNextMonthDate(purchasedAt).toLocaleDateString()}
|
|
162
|
-
</Text>
|
|
163
|
-
</View>
|
|
164
|
-
</Card>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## Progress Bar Colors
|
|
170
|
-
|
|
171
|
-
The progress bar color changes based on percentage:
|
|
172
|
-
|
|
173
|
-
| Percentage | Color | Visual |
|
|
174
|
-
|------------|-------|--------|
|
|
175
|
-
| 0-20% | Error (red) | ██████░░░░░░░░░░░░░ |
|
|
176
|
-
| 21-50% | Warning (orange) | ████████████░░░░░░ |
|
|
177
|
-
| 51-100% | Success (green) | ████████████████████ |
|
|
178
|
-
|
|
179
|
-
## Examples
|
|
180
|
-
|
|
181
|
-
### In Subscription Settings
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
function SubscriptionCredits() {
|
|
185
|
-
const { credits, isLoading } = useCredits();
|
|
186
|
-
|
|
187
|
-
if (isLoading) return <LoadingSkeleton />;
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<View style={styles.section}>
|
|
191
|
-
<Text style={styles.sectionTitle}>Credits</Text>
|
|
192
|
-
|
|
193
|
-
<CreditRow
|
|
194
|
-
label="Monthly Allowance"
|
|
195
|
-
current={credits}
|
|
196
|
-
total={100}
|
|
197
|
-
remainingLabel="credits"
|
|
198
|
-
/>
|
|
199
|
-
</View>
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
### With Purchase Link
|
|
205
|
-
|
|
206
|
-
```typescript
|
|
207
|
-
function CreditWithPurchase() {
|
|
208
|
-
const { credits } = useCredits();
|
|
209
|
-
|
|
210
|
-
const isLow = credits < 20;
|
|
211
|
-
|
|
212
|
-
return (
|
|
213
|
-
<View>
|
|
214
|
-
<CreditRow
|
|
215
|
-
label="Credits"
|
|
216
|
-
current={credits}
|
|
217
|
-
total={100}
|
|
218
|
-
remainingLabel="remaining"
|
|
219
|
-
/>
|
|
220
|
-
|
|
221
|
-
{isLow && (
|
|
222
|
-
<Button
|
|
223
|
-
onPress={() => navigation.navigate('CreditPackages')}
|
|
224
|
-
title="Get More Credits"
|
|
225
|
-
style={styles.purchaseButton}
|
|
226
|
-
/>
|
|
227
|
-
)}
|
|
228
|
-
</View>
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### With Feature Costs
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
function FeatureCostDisplay() {
|
|
237
|
-
const { credits } = useCredits();
|
|
238
|
-
|
|
239
|
-
const features = [
|
|
240
|
-
{ name: 'AI Generation', cost: 5 },
|
|
241
|
-
{ name: 'Advanced Export', cost: 3 },
|
|
242
|
-
{ name: 'Cloud Sync', cost: 1 },
|
|
243
|
-
];
|
|
244
|
-
|
|
245
|
-
return (
|
|
246
|
-
<View>
|
|
247
|
-
<CreditRow
|
|
248
|
-
label="Available Credits"
|
|
249
|
-
current={credits}
|
|
250
|
-
total={100}
|
|
251
|
-
remainingLabel="credits"
|
|
252
|
-
/>
|
|
253
|
-
|
|
254
|
-
<View style={styles.divider} />
|
|
255
|
-
|
|
256
|
-
{features.map((feature) => (
|
|
257
|
-
<DetailRow
|
|
258
|
-
key={feature.name}
|
|
259
|
-
label={feature.name}
|
|
260
|
-
value={`${feature.cost} credits`}
|
|
261
|
-
/>
|
|
262
|
-
))}
|
|
263
|
-
</View>
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
## Component Layout
|
|
269
|
-
|
|
270
|
-
```
|
|
271
|
-
┌─────────────────────────────────────┐
|
|
272
|
-
│ Monthly Credits [50/100] │
|
|
273
|
-
│ ████████████░░░░░░░░░░░░░░░░ │
|
|
274
|
-
│ 50 credits remaining │
|
|
275
|
-
└─────────────────────────────────────┘
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
## Styling
|
|
279
|
-
|
|
280
|
-
```typescript
|
|
281
|
-
const styles = StyleSheet.create({
|
|
282
|
-
container: {
|
|
283
|
-
gap: 8,
|
|
284
|
-
marginVertical: 4,
|
|
285
|
-
},
|
|
286
|
-
header: {
|
|
287
|
-
flexDirection: 'row',
|
|
288
|
-
justifyContent: 'space-between',
|
|
289
|
-
alignItems: 'center',
|
|
290
|
-
},
|
|
291
|
-
label: {
|
|
292
|
-
fontWeight: '500',
|
|
293
|
-
},
|
|
294
|
-
badge: {
|
|
295
|
-
paddingHorizontal: 8,
|
|
296
|
-
paddingVertical: 2,
|
|
297
|
-
borderRadius: 6,
|
|
298
|
-
backgroundColor: tokens.colors.surfaceSecondary,
|
|
299
|
-
},
|
|
300
|
-
count: {
|
|
301
|
-
fontWeight: '600',
|
|
302
|
-
},
|
|
303
|
-
progressBar: {
|
|
304
|
-
height: 8,
|
|
305
|
-
borderRadius: 4,
|
|
306
|
-
overflow: 'hidden',
|
|
307
|
-
backgroundColor: tokens.colors.surfaceSecondary,
|
|
308
|
-
},
|
|
309
|
-
progressFill: {
|
|
310
|
-
height: '100%',
|
|
311
|
-
borderRadius: 4,
|
|
312
|
-
backgroundColor: progressColor, // Dynamic based on percentage
|
|
313
|
-
},
|
|
314
|
-
});
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
## Best Practices
|
|
318
|
-
|
|
319
|
-
1. **Show total always** - Display max credits for context
|
|
320
|
-
2. **Update regularly** - Keep credits current
|
|
321
|
-
3. **Color code thresholds** - Use colors for low/high amounts
|
|
322
|
-
4. **Provide context** - Explain credit reset周期
|
|
323
|
-
5. **Link to purchase** - Add purchase option when low
|
|
324
|
-
6. **Test edge cases** - Zero credits, max credits, negative values
|
|
325
|
-
7. **Format numbers** - Use appropriate number formatting
|
|
326
|
-
|
|
327
|
-
## Related Components
|
|
328
|
-
|
|
329
|
-
- **PremiumDetailsCard** - Contains credit rows
|
|
330
|
-
- **DetailRow** - Simple label-value row
|
|
331
|
-
- **SubscriptionSection** - Section with credits
|
|
332
|
-
|
|
333
|
-
## See Also
|
|
334
|
-
|
|
335
|
-
- [useCredits](../../hooks/useCredits.md)
|
|
336
|
-
- [Credits Entity](../../../domains/wallet/domain/entities/Credits.md)
|
|
337
|
-
- [Credits README](../../../../domains/wallet/README.md)
|
|
88
|
+
- **DetailRow**: Generic detail row component
|
|
89
|
+
- **PremiumDetailsCard**: Premium details card
|
|
90
|
+
- **useCredits**: Credits hook
|
|
91
|
+
- **Credits README**: `../../../../domains/wallet/README.md`
|
|
92
|
+
- **Details README**: `./README.md`
|