Enhance README and wallet module documentation with new payment features

- Updated README.md to include new capabilities for Lightning invoice creation, smart payment scanning, universal payment support, and smart amount fields.
- Enhanced wallet-module documentation to reflect comprehensive Lightning Network wallet functionality, including detailed descriptions of payment processing, QR code scanning, and invoice management features.
- Added new sections for QR scanner component and payment flow architecture, improving clarity and usability for developers.

These changes provide clearer guidance on the application's features and improve the overall documentation quality.
This commit is contained in:
padreug 2025-09-18 23:23:30 +02:00
parent b8515c4598
commit ab1a6747ce
2 changed files with 160 additions and 49 deletions

View file

@ -15,6 +15,10 @@ A modular Vue 3 + TypeScript application with Nostr protocol integration and Lig
The application provides seamless Lightning Network wallet integration: The application provides seamless Lightning Network wallet integration:
- **Lightning Invoice Creation**: Create BOLT11 invoices for receiving payments with QR codes
- **Smart Payment Scanning**: QR code scanner for Lightning invoices, LNURL, and Lightning addresses
- **Universal Payment Support**: Send to Lightning invoices, Lightning addresses (user@domain.com), and LNURL
- **Smart Amount Fields**: Amount input only appears when needed (LNURL, Lightning addresses, or zero-amount invoices)
- **Instant Balance Updates**: WebSocket connection provides real-time balance updates when payments are sent or received - **Instant Balance Updates**: WebSocket connection provides real-time balance updates when payments are sent or received
- **Live Notifications**: Toast notifications for incoming payments - **Live Notifications**: Toast notifications for incoming payments
- **Connection Management**: Automatic reconnection with exponential backoff - **Connection Management**: Automatic reconnection with exponential backoff

View file

@ -19,10 +19,12 @@
The Wallet Module provides comprehensive Lightning Network wallet functionality for the Ario application. It integrates with LNbits to handle payments, manage wallet balances, and provide real-time updates through WebSocket connections. The Wallet Module provides comprehensive Lightning Network wallet functionality for the Ario application. It integrates with LNbits to handle payments, manage wallet balances, and provide real-time updates through WebSocket connections.
### **Key Capabilities** ### **Key Capabilities**
- **Lightning invoice creation** (BOLT11) for receiving payments with QR codes
- **QR code scanning** for Lightning invoices, LNURL, and Lightning addresses
- **Smart payment processing** with automatic payment type detection
- **Universal payment support** for Lightning invoices, Lightning addresses, and LNURL
- **Real-time balance updates** via WebSocket connection to LNbits - **Real-time balance updates** via WebSocket connection to LNbits
- **Payment processing** for Lightning invoices, Lightning addresses, and LNURL
- **Transaction management** with comprehensive history and status tracking - **Transaction management** with comprehensive history and status tracking
- **Pay link creation** for receiving payments with LNURL and Lightning addresses
- **Multi-wallet support** with automatic wallet selection - **Multi-wallet support** with automatic wallet selection
- **Battery optimization** through VisibilityService integration - **Battery optimization** through VisibilityService integration
@ -43,11 +45,14 @@ Automatic wallet balance synchronization without page refreshes:
- **Connection Management** - Automatic reconnection with exponential backoff - **Connection Management** - Automatic reconnection with exponential backoff
### **💸 Payment Processing** ### **💸 Payment Processing**
Comprehensive Lightning payment handling: Comprehensive Lightning payment handling with smart detection:
- **Lightning Invoices** - Pay BOLT11 invoices directly - **Lightning Invoices** - Pay BOLT11 invoices directly with amount detection
- **Lightning Addresses** - Send to Lightning addresses (user@domain.com) - **Lightning Addresses** - Send to Lightning addresses (user@domain.com)
- **LNURL Pay** - Support for LNURL payment requests - **LNURL Pay** - Support for LNURL payment requests
- **QR Code Scanning** - Camera-based scanning for all payment types
- **Smart Amount Fields** - Amount input only appears when needed (LNURL, Lightning addresses, zero-amount invoices)
- **Lightning URI Support** - Handles "lightning:" prefixes and BIP-21 URIs
- **Payment Validation** - Pre-flight checks for sufficient balance - **Payment Validation** - Pre-flight checks for sufficient balance
- **Error Handling** - User-friendly error messages and recovery - **Error Handling** - User-friendly error messages and recovery
@ -60,14 +65,16 @@ Complete transaction history and tracking:
- **Transaction Types** - Sent, received, pending, confirmed, failed - **Transaction Types** - Sent, received, pending, confirmed, failed
- **Search and Filter** - Find specific transactions quickly - **Search and Filter** - Find specific transactions quickly
### **🔗 Payment Links (LNURL)** ### **⚡ Lightning Invoice Creation**
Create reusable payment endpoints: Create BOLT11 invoices for receiving payments:
- **LNURL Generation** - Create payment links for receiving - **BOLT11 Invoice Generation** - Create Lightning invoices with specified amounts
- **Lightning Addresses** - Generate username@domain addresses - **QR Code Generation** - Automatic QR code creation for easy sharing
- **Amount Ranges** - Set minimum and maximum payment amounts - **Expiry Management** - Configurable invoice expiration times
- **Comments Support** - Allow payment comments - **Description Support** - Add payment descriptions and memos
- **Link Management** - Create, view, and delete payment links - **Real-time Status** - Live payment status updates (pending, paid, expired)
- **Mobile Optimization** - Responsive design for mobile devices
- **Copy Functionality** - Easy copying of invoice strings and payment hashes
## Architecture ## Architecture
@ -82,13 +89,25 @@ src/modules/wallet/services/
### **Component Layer** ### **Component Layer**
``` ```
src/modules/wallet/components/ src/modules/wallet/components/
├── SendDialog.vue # Payment sending interface ├── SendDialog.vue # Payment sending interface with QR scanning
├── ReceiveDialog.vue # Payment receiving interface ├── ReceiveDialog.vue # Lightning invoice creation interface
├── TransactionList.vue # Transaction history display ├── TransactionList.vue # Transaction history display
├── PayLinkManager.vue # LNURL payment link management
└── BalanceDisplay.vue # Wallet balance component └── BalanceDisplay.vue # Wallet balance component
``` ```
### **UI Components**
```
src/components/ui/
├── qr-scanner.vue # Camera-based QR code scanner
└── ... # Other Shadcn/UI components
```
### **Composables**
```
src/composables/
└── useQRScanner.ts # QR scanner functionality with camera access
```
### **Views Layer** ### **Views Layer**
``` ```
src/modules/wallet/views/ src/modules/wallet/views/
@ -150,27 +169,25 @@ if (payment.amount < 0) {
**Token:** `SERVICE_TOKENS.WALLET_SERVICE` **Token:** `SERVICE_TOKENS.WALLET_SERVICE`
**Key Features:** **Key Features:**
- Send Lightning payments (invoices, addresses, LNURL) - Send Lightning payments (invoices, addresses, LNURL) with smart type detection
- Create and manage LNURL payment links - Create Lightning invoices (BOLT11) for receiving payments
- Transaction history management - Transaction history management with real-time updates
- Payment link generation with Lightning addresses - QR code generation for payment sharing
**Reactive State:** **Reactive State:**
```typescript ```typescript
interface WalletService { interface WalletService {
transactions: ComputedRef<PaymentTransaction[]> // Transaction history transactions: ComputedRef<PaymentTransaction[]> // Transaction history
payLinks: ComputedRef<PayLink[]> // Created payment links isCreatingInvoice: ComputedRef<boolean> // Invoice creation state
isCreatingPayLink: ComputedRef<boolean> // Pay link creation state
isSendingPayment: ComputedRef<boolean> // Payment sending state isSendingPayment: ComputedRef<boolean> // Payment sending state
error: ComputedRef<string | null> // Error state error: ComputedRef<string | null> // Error state
} }
``` ```
**Key Methods:** **Key Methods:**
- `sendPayment(request: SendPaymentRequest)` - Send Lightning payment - `sendPayment(request: SendPaymentRequest)` - Send Lightning payment with type detection
- `createReceiveAddress(params)` - Create LNURL payment link - `createInvoice(params: CreateInvoiceRequest)` - Create BOLT11 Lightning invoice
- `deletePayLink(linkId: string)` - Remove payment link - `refresh()` - Reload transactions and balance data
- `refresh()` - Reload transactions and payment links
### **WalletWebSocketService** ### **WalletWebSocketService**
**Purpose:** Real-time wallet balance updates via WebSocket **Purpose:** Real-time wallet balance updates via WebSocket
@ -217,36 +234,37 @@ The wallet module integrates with the core PaymentService:
## Components ## Components
### **SendDialog.vue** 📤 ### **SendDialog.vue** 📤
Payment sending interface with comprehensive validation: Payment sending interface with smart payment detection and QR scanning:
**Features:** **Features:**
- Support for Lightning invoices, addresses, and LNURL - QR code scanner for Lightning invoices, LNURL, and Lightning addresses
- Amount validation against available balance - Automatic payment type detection (BOLT11, LNURL, Lightning address)
- Smart amount field visibility (only shows when needed)
- Lightning URI prefix handling ("lightning:" prefixes, BIP-21 URIs)
- Payment request parsing and validation - Payment request parsing and validation
- Real-time fee estimation - Amount validation against available balance
- Error handling with user-friendly messages - Error handling with user-friendly messages
**Form Fields:** **Form Fields:**
- Destination (invoice, address, or LNURL) - Destination (invoice, address, or LNURL) with QR scanner button
- Amount (when not specified in invoice) - Amount (conditionally visible based on payment type)
- Comment (for Lightning addresses) - Comment (for Lightning addresses and LNURL)
### **ReceiveDialog.vue** 📥 ### **ReceiveDialog.vue** 📥
Payment receiving interface for creating payment requests: Lightning invoice creation interface for receiving payments:
**Features:** **Features:**
- LNURL payment link creation - BOLT11 Lightning invoice generation
- Lightning address generation - QR code generation for easy sharing
- Customizable amount ranges - Real-time payment status tracking (pending, paid, expired)
- Comment support configuration - Mobile-responsive design with optimized layouts
- QR code generation for sharing - Copy functionality for invoice string and payment hash
- Payment success/failure indicators
- Configurable invoice expiry times
**Form Fields:** **Form Fields:**
- Description - Amount (required, in satoshis)
- Minimum amount - Description/Memo (optional payment description)
- Maximum amount
- Username (for Lightning address)
- Allow comments toggle
### **TransactionList.vue** 📋 ### **TransactionList.vue** 📋
Comprehensive transaction history display: Comprehensive transaction history display:
@ -268,17 +286,48 @@ Wallet balance component with real-time updates:
- Loading state indicators - Loading state indicators
- Connection status awareness - Connection status awareness
### **QRScanner Component** 📷
Camera-based QR code scanning for payments:
**Features:**
- WebRTC camera access with permission handling
- Real-time QR code detection using qr-scanner library
- Support for all Lightning payment types (BOLT11, LNURL, Lightning addresses)
- Lightning URI prefix cleaning ("lightning:" removal)
- Professional camera interface with scanning overlays
- Flash/torch support for low-light conditions
- Error handling for camera access issues
- Mobile-optimized scanning experience
**Technical Details:**
- Uses `qr-scanner` library for robust QR detection
- Handles camera permissions with user-friendly error messages
- Automatic cleanup on component unmount
- Configurable scan rate and highlighting options
## Payment Processing ## Payment Processing
### **Payment Flow Architecture** ### **Payment Flow Architecture**
``` ```
User Action ──→ Validation ──→ Payment ──→ Confirmation ──→ UI Update User Action ──→ Type Detection ──→ Validation ──→ Payment ──→ Confirmation ──→ UI Update
│ │ │ │ │ │ │ │ │ │ │
│ │ │ │ └─ Real-time via WebSocket │ │ │ │ │ └─ Real-time via WebSocket
│ │ │ └─ Transaction recorded │ │ │ │ └─ Transaction recorded
│ │ └─ LNbits API call │ │ │ └─ LNbits API call
│ └─ Balance check, format validation │ │ └─ Balance check, format validation
└─ Send/Receive dialog interaction │ └─ BOLT11/LNURL/Lightning address detection
└─ Send/Receive dialog or QR scan
```
### **QR Code Scanning Flow**
```
Camera Access ──→ QR Detection ──→ URI Cleaning ──→ Type Detection ──→ Form Population
│ │ │ │ │
│ │ │ │ └─ Auto-fill destination field
│ │ │ └─ BOLT11/LNURL/Lightning address
│ │ └─ Remove "lightning:" prefixes
│ └─ Real-time scanning with qr-scanner
└─ Permission handling with user-friendly errors
``` ```
### **Payment Types Supported** ### **Payment Types Supported**
@ -311,6 +360,33 @@ await walletService.sendPayment({
}) })
``` ```
### **Lightning Invoice Creation**
Create BOLT11 invoices for receiving payments:
#### **Invoice Creation**
```typescript
// Create Lightning invoice
const invoice = await walletService.createInvoice({
amount: 1000, // Amount in satoshis
memo: "Payment for services", // Optional description
expiry: 3600 // Optional expiry in seconds (default: 1 hour)
})
// Returns invoice object with:
// - payment_request: BOLT11 invoice string
// - payment_hash: Payment hash for tracking
// - amount: Invoice amount in sats
// - memo: Invoice description
// - expiry: Expiration time
```
#### **QR Code Generation**
```typescript
// QR code is automatically generated for created invoices
// Available in the UI for easy sharing
const qrCodeDataUrl = await paymentService.generateQRCode(invoice.payment_request)
```
### **Error Handling** ### **Error Handling**
Comprehensive error handling for payment failures: Comprehensive error handling for payment failures:
@ -468,6 +544,37 @@ describe('WalletService', () => {
const result = await service.sendPayment(request) const result = await service.sendPayment(request)
expect(result).toBe(true) expect(result).toBe(true)
}) })
it('should create Lightning invoice', async () => {
const invoiceData = {
amount: 1000,
memo: 'Test payment'
}
const invoice = await service.createInvoice(invoiceData)
expect(invoice.payment_request).toMatch(/^lnbc/)
expect(invoice.amount).toBe(1000)
})
})
```
#### **QR Scanner Tests**
```typescript
describe('QRScanner', () => {
it('should detect BOLT11 invoices', async () => {
const invoice = 'lnbc1000n1p3xh4v...'
const result = parsePaymentDestination(invoice)
expect(result.type).toBe('bolt11')
expect(result.amount).toBe(100)
})
it('should clean Lightning URIs', () => {
const uri = 'lightning:lnbc1000n1p3xh4v...'
const cleaned = normalizePaymentRequest(uri)
expect(cleaned).toBe('lnbc1000n1p3xh4v...')
})
}) })
``` ```