Skip to content

Commit f739563

Browse files
committed
refactor: Address PR review feedback
- Use modern #Preview macros instead of PreviewProvider - Make preview helper properties private - Use wrappedValue instead of initialValue for State - Remove redundant comments - Simplify configuration properties with default values - Refactor configurePrimerStyle into focused helper methods - Use Swift shorthand syntax for optional binding (if let x)
1 parent 64b4559 commit f739563

File tree

24 files changed

+804
-127
lines changed

24 files changed

+804
-127
lines changed

.claude/settings.local.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"mcp__atlassian__getJiraIssue",
5+
"mcp__figma-desktop__get_design_context",
6+
"mcp__figma-desktop__get_screenshot",
7+
"mcp__serena__find_symbol",
8+
"mcp__serena__find_file",
9+
"mcp__serena__search_for_pattern",
10+
"mcp__serena__activate_project",
11+
"mcp__serena__get_symbols_overview",
12+
"Bash(do )",
13+
"Bash(\"$file\")",
14+
"Bash(done)",
15+
"Bash(perl -i -p0e:*)",
16+
"Bash(do)",
17+
"Bash(xcodebuild test:*)",
18+
"Bash(bundle exec fastlane test_sdk:*)",
19+
"Bash(do echo \"=== $file.swift ===\")",
20+
"Bash(tee:*)",
21+
"Bash(swift test:*)",
22+
"Bash(bundle exec pod install:*)",
23+
"Bash(xcodebuild:*)",
24+
"Bash(find:*)",
25+
"Read(//private/tmp/**)",
26+
"Bash(while read file)",
27+
"Bash(do sed -i '' 's/CheckoutColors/PrimerColors/g' \"$file\" echo \"Updated: $file\" done)",
28+
"Bash(xargs:*)",
29+
"Bash(for file in /Users/onurvar/Projects/primer-sdk-ios/Sources/PrimerSDK/Classes/CheckoutComponents/Internal/Presentation/Components/Inputs/{CardholderNameInputField,NameInputField,AddressLineInputField,PostalCodeInputField,CityInputField,ExpiryDateInputField,StateInputField,EmailInputField,CVVInputField,CountryInputField,CardNumberInputField}.swift)",
30+
"Bash(echo:*)",
31+
"mcp__serena__list_dir",
32+
"mcp__figma-desktop__get_variable_defs",
33+
"mcp__serena__insert_after_symbol",
34+
"mcp__serena__replace_symbol_body",
35+
"mcp__serena__insert_before_symbol",
36+
"mcp__serena__find_referencing_symbols",
37+
"Bash(git stash push:*)",
38+
"Bash(git log:*)",
39+
"Bash(gh api:*)",
40+
"Bash(gh pr view:*)",
41+
"Bash(git checkout:*)"
42+
],
43+
"deny": [],
44+
"ask": []
45+
}
46+
}

.gitignore

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,4 @@ launch.json
101101
.cursorrules
102102

103103
# Style-dictionary file generation, we only want to commit package.json and package-lock.json
104-
**/node_modules/
105-
106-
# Serena files
107-
.serena/
108-
109-
# Claude files
110-
.claude/
111-
CLAUDE.md
112-
.mcp.json
104+
**/node_modules/

.mcp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.serena/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/cache
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Code Style and Conventions
2+
3+
## Formatting Rules
4+
5+
The project uses **SwiftFormat** with a specific configuration defined in `BuildTools/.swiftformat`.
6+
7+
### Active SwiftFormat Rules
8+
- `isEmpty` - Prefer `.isEmpty` over `.count == 0`
9+
- `preferCountWhere` - Prefer `count(where:)` over `filter().count`
10+
- `redundantExtensionACL` - Remove redundant access control in extensions
11+
- `modifierOrder` - Consistent ordering of declaration modifiers
12+
- `consecutiveBlankLines` - Remove consecutive blank lines
13+
- `blankLineAfterImports` - Add blank line after imports
14+
- `andOperator` - Use `&&` instead of `,` in conditions
15+
- `elseOnSameLine` - Place `else` on same line as closing brace
16+
- `fileHeader` - Standardize file headers
17+
- `hoistPatternLet` - Hoist pattern let bindings
18+
- `leadingDelimiters` - Consistent leading delimiter placement
19+
- `modifiersOnSameLine` - Keep modifiers on same line
20+
- `preferKeyPath` - Prefer key paths where possible
21+
- `redundantInternal` - Remove redundant `internal` keyword
22+
23+
### Automatic Formatting
24+
25+
The project uses a **pre-commit hook** that automatically formats code before each commit:
26+
27+
```bash
28+
# Install the hook (run once)
29+
make hook
30+
```
31+
32+
The hook runs SwiftFormat on staged Swift files using `git-format-staged.sh`.
33+
34+
## Swift Style Guidelines
35+
36+
### General Principles
37+
- Write clear, readable code
38+
- Use descriptive variable and function names
39+
- Add documentation for public APIs
40+
- Follow Swift API Design Guidelines
41+
- Maintain consistency with existing code patterns
42+
43+
### File Organization
44+
- Import statements at the top
45+
- Blank line after imports
46+
- Group related functionality together
47+
- Use `// MARK: -` comments for section organization
48+
49+
### Access Control
50+
- Use the most restrictive access level possible
51+
- Default to `internal` when appropriate
52+
- Mark public APIs explicitly
53+
- Use `private` and `fileprivate` for implementation details
54+
55+
### Naming Conventions
56+
- Use descriptive names that convey purpose
57+
- Follow Swift naming conventions:
58+
- Types: `PascalCase`
59+
- Functions, properties, variables: `camelCase`
60+
- Constants: `camelCase` (not SCREAMING_SNAKE_CASE)
61+
62+
## Git Conventions
63+
64+
### Branch Naming
65+
Follow the pattern: `<initials>/<type>/<description>`
66+
- `ov/fix/xxx` - Bug fixes
67+
- `ov/refactor/xxx` - Refactoring work
68+
- `ov/feat/xxx` - New features
69+
70+
### Commit Messages
71+
Follow the **50/72 rule**:
72+
73+
**Subject line (50 chars max):**
74+
```
75+
type: Brief description in imperative mood
76+
```
77+
78+
**Body (wrap at 72 chars):**
79+
```
80+
Explain what changes were made and why (not how).
81+
Include any relevant context or reasoning.
82+
83+
Reference issue numbers if applicable.
84+
```
85+
86+
**Types:**
87+
- `feat:` - New feature
88+
- `fix:` - Bug fix
89+
- `refactor:` - Code refactoring
90+
- `test:` - Adding or updating tests
91+
- `docs:` - Documentation changes
92+
- `chore:` - Build process, dependency updates
93+
- `perf:` - Performance improvements
94+
95+
**Examples:**
96+
```
97+
refactor: Remove PromiseKit from Apple Pay components
98+
99+
Replace PromiseKit with native async/await for better
100+
maintainability and to reduce dependencies.
101+
```
102+
103+
```
104+
fix: Correct 3DS authentication flow for Safari
105+
106+
The 3DS window was not properly handling Safari's security
107+
restrictions. This adjusts the flow to use SFSafariViewController
108+
consistently.
109+
```
110+
111+
### Important Rules
112+
- **Do NOT mention Claude/AI assistance** in commit messages
113+
- Use imperative mood ("Add feature" not "Added feature")
114+
- Focus on what and why, not how
115+
- Keep subject line under 50 characters
116+
- Separate subject from body with blank line
117+
- Wrap body at 72 characters
118+
119+
## Code Review Guidelines
120+
121+
- Focus on code clarity and maintainability
122+
- Ensure tests are included for new features
123+
- Check for proper error handling
124+
- Verify PCI compliance for payment-related code
125+
- Review for potential memory leaks
126+
- Ensure accessibility is maintained
127+
- Check that UI updates happen on main thread
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Codebase Structure
2+
3+
## Root Directory Layout
4+
```
5+
.
6+
├── Sources/PrimerSDK/ # Main SDK source code
7+
├── Tests/ # Unit tests
8+
├── Debug App/ # Debug/testing application
9+
├── fastlane/ # CI/CD automation
10+
├── BuildTools/ # Build utilities and scripts
11+
├── Scripts/ # Additional scripts
12+
├── DesignTokens/ # Design system tokens
13+
├── Package*.swift # SPM configurations
14+
├── PrimerSDK.podspec # CocoaPods specification
15+
├── Makefile # Build automation
16+
├── CLAUDE.md # Project instructions
17+
└── PrimerSDK.xcworkspace # Xcode workspace (use this!)
18+
```
19+
20+
## Main Source Code Structure
21+
22+
### Sources/PrimerSDK/Classes/
23+
The main SDK implementation organized into:
24+
25+
#### Core/
26+
Core SDK functionality and services:
27+
- **Primer/** - Main SDK entry point and configuration
28+
- **PrimerHeadlessUniversalCheckout/** - Headless checkout system
29+
- `Composable/` - Individual payment method components
30+
- `Managers/` - Component managers
31+
- `Models/` - Data models
32+
- **3DS/** - 3D Secure authentication
33+
- **Analytics/** - Analytics and telemetry
34+
- **Payment Services/** - Payment processing services
35+
- **Logging/** - Logging infrastructure
36+
- **Keychain/** - Secure storage
37+
- **Cache/** - Caching layer
38+
- **Connectivity/** - Network connectivity checks
39+
- **BIN Data/** - Bank identification number data
40+
- **Models/** - Core data models
41+
- **Constants/** - SDK-wide constants
42+
43+
#### Data Models/
44+
API models, payment method configurations, themes, and response objects
45+
46+
#### PCI/
47+
PCI-compliant card data handling, tokenization, and secure processing
48+
49+
#### User Interface/
50+
UI components for Universal Checkout:
51+
- Root container and navigation controllers
52+
- Payment method view controllers
53+
- Tokenization view models
54+
- Reusable UI components
55+
56+
#### Services/
57+
Network layer, API client, and other services
58+
59+
#### CheckoutComponents/
60+
Checkout UI components and flows
61+
62+
#### Modules/
63+
Additional SDK modules and integrations
64+
65+
#### Extensions & Utilities/
66+
Helper extensions and utility functions
67+
68+
## Tests Structure
69+
70+
### Tests/
71+
- **Primer/** - Core SDK unit tests
72+
- **3DS/** - 3D Secure tests
73+
- **Klarna/** - Klarna integration tests
74+
- **Stripe/** - Stripe integration tests
75+
- **NolPay/** - NolPay integration tests
76+
- **Utilities/** - Test utilities and mocks
77+
78+
## Debug App Structure
79+
80+
### Debug App/
81+
Comprehensive testing environment:
82+
- **Sources/** - Debug app source code with test scenarios
83+
- **Tests/** - Debug app specific tests
84+
- Multiple Xcode projects:
85+
- `Primer.io Debug App.xcodeproj` - CocoaPods version
86+
- `Primer.io Debug App SPM.xcodeproj` - SPM version
87+
88+
## Important Files
89+
- `version.swift` - SDK version information
90+
- `Primer.swift` - Main SDK class and entry point
91+
- `PrimerHeadlessUniversalCheckout.swift` - Headless checkout entry point
92+
- `PrimerSDK.podspec` - CocoaPods specification
93+
- `Package.swift` - Swift Package Manager configuration
94+
- `Fastfile` - Build and deployment automation

0 commit comments

Comments
 (0)