feat: enhance wallet trial creation logic#2670
Conversation
📝 WalkthroughWalkthroughAdds a fingerprint-based duplicate detection to wallet trial creation (blocked in production), new UserRepository query to find trial users by fingerprint, corresponding tests for duplicate/no-fingerprint paths, and propagates the User-Agent header in the client-ip-forwarding interceptor. Changes
Sequence DiagramsequenceDiagram
participant Client
participant WalletController
participant UserRepository
participant Database
Client->>WalletController: POST /wallet (initiate trial)
WalletController->>WalletController: Check user's lastFingerprint
alt User has fingerprint (production)
WalletController->>UserRepository: findTrialUsersByFingerprint(fingerprint, userId)
UserRepository->>Database: SELECT ... JOIN UserWallets WHERE lastFingerprint = ? AND isTrialing AND userId != ?
Database-->>UserRepository: Matching users[]
UserRepository-->>WalletController: Return matches
alt matches found
WalletController-->>Client: 400 Duplicate fingerprint error
else no matches
WalletController->>WalletController: Create trial wallet
WalletController-->>Client: 201 Trial created
end
else No fingerprint
WalletController->>WalletController: Create trial wallet
WalletController-->>Client: 201 Trial created
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2670 +/- ##
==========================================
+ Coverage 51.32% 53.75% +2.42%
==========================================
Files 1054 1055 +1
Lines 29573 29320 -253
Branches 6649 6350 -299
==========================================
+ Hits 15179 15760 +581
+ Misses 14175 13186 -989
- Partials 219 374 +155
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/api/src/user/repositories/user/user.repository.ts`:
- Around line 82-87: findTrialUsersByFingerprint is currently returning users
with any wallet matching the fingerprint; restrict the query to trialing wallets
by adding a condition on the wallet's isTrialing column so only wallets where
UserWallets.isTrialing === true are matched. Update the query built in
findTrialUsersByFingerprint to include this additional predicate along with the
existing eq(UserWallets.userId, this.table.id), eq(this.table.lastFingerprint,
fingerprint) and ne(this.table.id, excludeUserId) so the function returns only
trial users.
Summary by CodeRabbit
Bug Fixes
Tests
Chores