Wallet Feature Technical Documentation
Wallet Feature Technical Documentation
Overview
The wallet feature provides a comprehensive financial transaction system that enables users to
create virtual accounts, manage funds, transfer money, and track transaction history. This
system is integrated with a third-party banking API (VFD Bank) to provide real financial
transactions while maintaining a secure, managed environment within the application.
This document outlines the technical implementation details of the wallet system, including
architecture, core components, API endpoints, and integration points.
Key Components
WalletService
The primary service that handles all wallet-related operations. It interacts with the database
through PrismaService and with the banking API through walletApi.
Dependencies
Architecture
The wallet system consists of the following components:
API Endpoints
Metho Endpoint Description Authenticatio
d n
Core Functionality
1. Virtual Account Management
2. Wallet Operations
Balance Management
typescript
Transaction History
typescript
4. Escrow System
Move to Escrow
typescript
5. Beneficiary Management
Adding Beneficiaries
typescript
Retrieving Beneficiaries
typescript
Removing Beneficiaries
typescript
6. Referral System
Referral Flow
7. Transaction Logging
Log Cleanup
typescript
async cleanupExpiredLogs()
Simulating Credits
typescript
Data Models
Wallet
Wallet Transaction
Wallet Beneficiary
Error Handling
The service implements comprehensive error handling, including:
1. HTTP Exceptions: Appropriate HTTP error codes for different error scenarios
2. Custom Error Handling: Via the handleApiError method
3. Transaction Rollback: Using Prisma's transaction feature to ensure data integrity
Security Features
1. Transaction PIN: Required for sensitive operations
2. PIN Encryption: PIN is stored using bcrypt hashing
3. Transaction Signatures: SHA-512 hashing for secure transfer signatures
4. KYC Validation: Transactions are validated against KYC requirements
Integration Points
VFD Bank API
Testing Support
The wallet service includes features to support testing:
Implementation Notes
1. All monetary operations use Prisma transactions to ensure atomicity
2. Transaction references and IDs are generated using UUID to ensure uniqueness
3. Balance updates use increment/decrement operations to prevent race conditions
4. Error handling includes specific error types for different failure scenarios
5. Escrow functionality provides protection for marketplace transactions
Future Enhancements
1. Tiered Referral Program: Different bonus rates based on user activity or tier
2. Time-Limited Campaigns: Special referral rates during promotional periods
3. Multi-level Referrals: Extending the program to second-level referrals
4. Notifications: Alerting users when they earn referral bonuses
5. Analytics Dashboard: Providing users with visual analytics of their referral performance
Implementation Notes
1. Security Considerations:
○ Referral code uniqueness is guaranteed via database constraints
○ Validation of referral codes during sign-up
○ Error handling is designed to be non-blocking for the main transaction flow
○ Idempotency prevents duplicate bonus awards for the same transaction
2. Integration Points:
○ User Registration: The processReferralSignup function is called during user
creation
○ Transaction Completion: The processReferralBonus is called in the
handleCompletedStatus method of the EscrowService