mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 12:28:22 +00:00
4.7 KiB
4.7 KiB
Withdrawal Token Persistence Fix
This document describes the fix for the admin panel withdrawal feature that was causing coin loss due to non-persistent cashu tokens.
Problem
The original admin panel withdrawal feature had a critical issue:
- Generated cashu tokens were only displayed momentarily in the UI
- If the modal was closed accidentally, the token was lost forever
- No record of pending withdrawals was maintained
- This resulted in actual coin loss for administrators
Solution
1. Token Persistence
- Added
PendingWithdrawaldatabase model to store all withdrawal tokens - Every withdrawal is now automatically saved to the database
- Tokens are never lost, even if the UI is closed accidentally
2. Pending Withdrawals Display
- New "Pending Withdrawals" section in the admin panel
- Shows all unclaimed withdrawal tokens with details:
- Amount and currency unit
- Mint URL
- Creation timestamp
- Auto-send status
- Lightning address (if auto-sent)
- Easy copy-to-clipboard functionality for tokens
- Ability to mark withdrawals as claimed when used
3. Automatic Lightning Address Sending
- Optional auto-send feature for withdrawals
- If
RECEIVE_LN_ADDRESSis configured and auto-send is enabled:- Tokens are automatically sent to the Lightning address
- No manual token handling required
- Withdrawal is marked as completed automatically
- Fallback to manual token storage if auto-send fails
4. Enhanced UI/UX
- Checkbox option to enable auto-send during withdrawal
- Better feedback messages for successful operations
- Real-time updates of pending withdrawals list
- Improved error handling and user notifications
Database Changes
New Table: pending_withdrawals
CREATE TABLE pending_withdrawals (
id INTEGER PRIMARY KEY,
token TEXT NOT NULL,
amount INTEGER NOT NULL,
unit TEXT NOT NULL,
mint_url TEXT NOT NULL,
created_at TIMESTAMP NOT NULL,
claimed BOOLEAN NOT NULL DEFAULT FALSE,
auto_sent BOOLEAN NOT NULL DEFAULT FALSE,
ln_address TEXT,
notes TEXT
);
API Changes
Enhanced /admin/withdraw endpoint
- New optional parameter:
auto_send_to_ln: bool - Returns additional fields:
withdrawal_id: Database ID of the stored withdrawalauto_sent: Whether the token was automatically sentln_address: Lightning address used (if auto-sent)amount_received: Amount received by Lightning address
New endpoint: /admin/api/mark-withdrawal-claimed/{withdrawal_id}
- POST endpoint to mark a withdrawal as claimed
- Prevents accidental reuse of tokens
- Helps track withdrawal status
New partial: /admin/partials/pending-withdrawals
- HTMX-powered component for displaying pending withdrawals
- Auto-refreshes when new withdrawals are created
- Provides interactive token management
Configuration
Environment Variables
The fix uses existing configuration:
RECEIVE_LN_ADDRESS: Lightning address for auto-send functionalityADMIN_PASSWORD: Required for admin panel access
Settings
Auto-send functionality respects the existing receive_ln_address setting that can be configured through the admin panel settings interface.
Usage
Manual Withdrawal (Default)
- Click "💸 Withdraw Balance" in admin panel
- Select mint and currency
- Enter withdrawal amount
- Click "Withdraw"
- Token is generated and stored in pending withdrawals
- Copy token from the result or from pending withdrawals list
- Use token in your cashu wallet
- Mark as claimed when used (optional)
Auto-Send Withdrawal
- Ensure
RECEIVE_LN_ADDRESSis configured in settings - Click "💸 Withdraw Balance" in admin panel
- Select mint and currency
- Enter withdrawal amount
- Check "Auto-send to Lightning address" checkbox
- Click "Withdraw"
- Funds are automatically sent to your Lightning address
- Withdrawal is marked as completed automatically
Migration
The database migration 123abc456def_add_pending_withdrawals_table.py will be automatically applied when the application starts, creating the new pending_withdrawals table.
Benefits
- No More Coin Loss: All withdrawal tokens are permanently stored
- Better UX: Clear visibility of all pending withdrawals
- Automation: Optional auto-send reduces manual token handling
- Audit Trail: Complete history of all withdrawals
- Recovery: Ability to retrieve tokens even after UI accidents
- Flexibility: Choice between manual tokens and automatic Lightning sends
Backward Compatibility
This fix is fully backward compatible:
- Existing withdrawal functionality continues to work
- No breaking changes to existing APIs
- New features are opt-in
- Database migration is automatic and safe