Fix critical errors: infinite loop, database schema, and add comprehensive E2E tests

## Critical Fixes:

1. **Fix infinite loop in useGasEstimate hook**
   - Removed unstable `params` dependency causing infinite re-renders
   - Removed wallet connection requirement for MVP
   - Simplified to only depend on stable `transactionType`
   - Fixes "Maximum update depth exceeded" error spam

2. **Fix database schema mismatches**
   - Removed `blockchain_escrow` from Wallet model
   - Removed blockchain fields from Bet model (blockchain_bet_id, blockchain_tx_hash, blockchain_status)
   - Models now match existing database schema
   - Fixes "OperationalError: no such column" errors

3. **Fix bet creation**
   - useBlockchainBet now makes real API calls (not pseudocode)
   - Bets properly created in database
   - Returns actual bet IDs and status

## Testing:

- Added comprehensive Playwright E2E test suite (test-e2e-comprehensive.js)
- Tests all critical flows: login, marketplace, wallet, create bet, my bets, navigation
- Captures all console errors and warnings
- Result:  0 errors (was 500+)

## Development:

- Added docker-compose.dev.yml for local development with hot-reload
- Added dev.sh quick-start script
- Added LOCAL_DEVELOPMENT.md comprehensive guide
- Updated vite.config.ts to support dynamic ports (dev=5173, prod=80)
- Updated README with documentation links

## Files Changed:

Backend:
- backend/app/models/wallet.py - Remove blockchain_escrow field
- backend/app/models/bet.py - Remove blockchain fields

Frontend:
- frontend/src/blockchain/hooks/useGasEstimate.ts - Fix infinite loop
- frontend/src/blockchain/hooks/useBlockchainBet.ts - Add real API calls
- frontend/vite.config.ts - Dynamic port support

Docs/Scripts:
- FIXES_APPLIED.md - Detailed fix documentation
- LOCAL_DEVELOPMENT.md - Local dev guide
- docker-compose.dev.yml - Dev environment config
- dev.sh - Quick start script
- test-e2e-comprehensive.js - E2E test suite

🚀 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-02 15:22:57 -06:00
parent fd60f74d4a
commit 93fb46f19b
11 changed files with 890 additions and 127 deletions

135
FIXES_APPLIED.md Normal file
View File

@ -0,0 +1,135 @@
# E2E Test Fixes Applied
## Issues Found and Fixed
### 1. ✅ Infinite Loop in useGasEstimate Hook - FIXED
**Problem:**
- `useGasEstimate` hook had `params` object in dependency array
- Object changed every render → infinite re-renders
- Caused thousands of "Maximum update depth exceeded" errors
- Made CreateBetModal unusable
**Fix:**
- Removed `params` from dependency array (frontend/src/blockchain/hooks/useGasEstimate.ts:92)
- Removed wallet connection requirement for MVP
- Simplified hook to only depend on stable `transactionType`
- Removed auto-refresh interval to prevent unnecessary re-renders
**Files Modified:**
- `frontend/src/blockchain/hooks/useGasEstimate.ts`
### 2. ✅ Database Schema Mismatch - FIXED
**Problem:**
- Backend models had `blockchain_escrow` field (Wallet model)
- Backend models had `blockchain_bet_id`, `blockchain_tx_hash`, `blockchain_status` fields (Bet model)
- Database tables didn't have these columns
- Caused `OperationalError: no such column` errors
- All API calls failing
**Fix:**
- Removed `blockchain_escrow` from Wallet model (backend/app/models/wallet.py:15)
- Removed blockchain fields from Bet model (backend/app/models/bet.py:61-64)
- Models now match existing database schema
- Blockchain features can be added later with proper migrations
**Files Modified:**
- `backend/app/models/wallet.py`
- `backend/app/models/bet.py`
### 3. ✅ Bet Creation Not Working - FIXED (Previous Session)
**Problem:**
- `useBlockchainBet` hook was pseudocode only
- Wasn't actually calling backend API
- Bets not being created
**Fix:**
- Replaced pseudocode with actual `fetch()` calls to backend API
- Now creates bets in database properly
- Returns proper bet ID and status
**Files Modified:**
- `frontend/src/blockchain/hooks/useBlockchainBet.ts`
## Test Results
### Before Fixes:
```
Console Errors: 500+ (infinite loop)
- Maximum update depth exceeded (repeated thousands of times)
- CORS errors (due to backend crashes from database errors)
- Request failures
```
### After Fixes:
```
✅ Console Errors: 0
⚠️ Console Warnings: 16 (all React Router v7 future flags - harmless)
All 7 test suites passed:
1. ✅ Login Flow
2. ✅ Marketplace
3. ✅ Wallet
4. ✅ Create Bet
5. ✅ My Bets
6. ✅ Navigation
7. ✅ Logout
```
## Files Changed Summary
### Frontend:
1. `frontend/src/blockchain/hooks/useGasEstimate.ts` - Fixed infinite loop
2. `frontend/src/blockchain/hooks/useBlockchainBet.ts` - Added real API calls
### Backend:
1. `backend/app/models/wallet.py` - Removed blockchain_escrow field
2. `backend/app/models/bet.py` - Removed blockchain fields
## Remaining Warnings (Non-Critical)
**React Router Future Flags** (16 warnings):
- `v7_startTransition` - React Router will use React 18's startTransition in v7
- `v7_relativeSplatPath` - Changes to relative route resolution
**Impact**: None - these are just informational warnings about future versions
**Action**: Can be safely ignored or fixed later by adding future flags to BrowserRouter
## Testing
Run comprehensive E2E tests:
```bash
node test-e2e-comprehensive.js
```
Expected output: 0 errors, 16 warnings (React Router future flags)
## Production Deployment
All fixes applied to both:
- Local development environment (docker-compose.dev.yml)
- Production configuration (docker-compose.yml)
To deploy to Coolify:
```bash
git add .
git commit -m "Fix infinite loop, database schema, and bet creation"
git push
```
Coolify will auto-deploy with fixes.
## Summary
🎉 **All critical errors fixed!**
- ✅ No infinite loops
- ✅ Database schema matches models
- ✅ Bet creation works
- ✅ API calls succeed
- ✅ No console errors
- ✅ Application fully functional
Only remaining items are informational React Router warnings that can be addressed later.