Skip to content

Latest commit

 

History

History
101 lines (77 loc) · 3.7 KB

File metadata and controls

101 lines (77 loc) · 3.7 KB

LNPixels Integration Complete! 🎉

Summary

I have successfully integrated the new lnpixels-app with the API backend and set up pnpm as the package manager. Here's what was accomplished:

✅ What was implemented:

1. New API Endpoint: POST /api/invoices/pixels

  • Accepts a specific set of pixels instead of requiring a rectangle
  • Validates pixel coordinates, colors, and letters
  • Calculates pricing using the backend pricing logic
  • Supports up to 1000 pixels per request
  • Returns a Lightning invoice for payment

2. Updated Frontend Integration

  • Modified the lnpixels-app API client to use the new endpoint
  • Updated the save modal to send pixels to the new bulk endpoint
  • Fixed WebSocket connections to use correct events (pixel.update, activity.append)
  • Aligned pricing logic between frontend and backend

3. Pricing Logic Updates

  • Black pixels (#000000) now cost 1 sat (like basic pixels)
  • Colored pixels cost 10 sats
  • Letter pixels cost 100 sats
  • Overwrite rule: 2x last sold price or base price, whichever is higher

4. CORS Configuration

  • Added support for the new lnpixels-app port (3002)
  • Updated both HTTP and WebSocket CORS settings
  • Ensured proper cross-origin communication

5. PNPM Workspace Setup

  • Created pnpm-workspace.yaml configuration
  • Updated root package.json with convenient scripts
  • Added workspace scripts for running individual apps or all together

🚀 How to run:

Start both servers:

# Start API server (port 3000)
pnpm dev:api

# Start lnpixels-app (port 3002) 
pnpm dev:app

# Or start both in parallel
pnpm dev:all

URLs:

🧪 Testing the Integration:

1. Test the new API endpoint:

curl -X POST http://localhost:3000/api/invoices/pixels \
  -H "Content-Type: application/json" \
  -d @test-payload.json

Expected response: Invoice with amount of 111 sats (100 + 10 + 1)

2. Test the frontend:

  1. Open http://localhost:3002/
  2. Draw some pixels on the canvas (try both paint and text modes)
  3. Click the save button to test the new bulk pixels endpoint
  4. Verify that the pricing is calculated correctly

📁 File Changes:

Backend Changes:

  • api/src/routes.ts: Added new /invoices/pixels endpoint
  • api/src/pricing.ts: Updated pricing logic for black pixels
  • api/src/server.ts: Added CORS middleware
  • api/src/socket.ts: Updated CORS origins
  • api/test/invoices.test.ts: Added tests for new endpoint

Frontend Changes:

  • lnpixels-app/lib/api.ts: Added createPixelsInvoice method
  • lnpixels-app/components/save-modal.tsx: Updated to use new endpoint
  • lnpixels-app/hooks/use-websocket.ts: Fixed WebSocket events
  • lnpixels-app/package.json: Updated dev script to use port 3002

Project Setup:

  • pnpm-workspace.yaml: Created workspace configuration
  • package.json: Updated with pnpm scripts and workspace management

🎯 Key Benefits:

  1. Flexible Pixel Selection: Users can now paint any shape/pattern and save it as a single purchase
  2. Better Performance: Single API call instead of multiple individual pixel purchases
  3. Consistent Pricing: Frontend and backend pricing logic are now aligned
  4. Modern Tooling: Using pnpm for better dependency management and monorepo support
  5. Real-time Updates: WebSocket integration for live pixel updates

The integration is complete and ready for testing! The new lnpixels-app provides a much better user experience while maintaining compatibility with the existing API and payment system.