# Eldorado Boost Watcher (Chrome/Edge extension)

Live-monitors Eldorado.gg seller notifications (`/api/notifications/me`), instantly shows **new LoL boost requests** (Rank / Placements / Net Wins / Custom), suggests a price per request, and lets you **send offers** — one click (manual) or fully automatic — with desktop notification + sound + icon badge alerts.

## How it works

All authenticated calls are sent **from inside an open `eldorado.gg` tab** (content script), not from the extension background. Reason: session cookies (`__Host-EldoradoIdToken`, etc.) and Cloudflare `cf_clearance` are only valid when sent from the page's own (same-site) origin. The content script exposes a small relay so the service worker can run those calls. Cookies/tokens are **never stored** or hardcoded.

```
eldorado.gg tab (content.js: poll + apiFetch relay)
   ⇅ chrome messaging
service worker (background.js: dedup, notify, pricing, offer engine)
   ⇅ storage
popup (list + Offer buttons + settings)
```

## ⚠️ Important: an Eldorado tab must be open

The extension works **while a logged-in `eldorado.gg` tab is open** (pin one and leave it). Polling and all offers/conversations go through that tab; closing it stops everything.

## Installation

1. Open `chrome://extensions` (Edge: `edge://extensions`).
2. Turn on **Developer mode**.
3. **Load unpacked** → select this folder.
4. Sign in to `eldorado.gg`, leave the tab open/pinned.

## Usage

### Live tab
Recent boost requests: emblem · category · `current → target` · region · **suggested price** · time.
- **Offer $X button** (Rank Boost & Placements): one click sends the offer. After sending it shows `✓ $X`. Requires the **Master switch** to be on.
- Click a row (not the button) to open the request on Eldorado.

### Settings → Automation
- **Master switch** — global kill switch. Off = nothing is ever sent (manual or auto). **Default off.**
- **Auto-offer** — automatically offers on matching new requests (categories + region scope, price floor/cap, `max offers/hour`, `min gap`). Fires directly (local dedup, no pre-check) for speed.
- **Delivery time** (`guaranteedDeliveryTime`, default 28 days).
- **Messaging** — *Start conversation after offer* (creates the chat so the buyer sees you). *Send opener message* + editable template is present but **experimental/not wired** (see below).

### Settings → Pricing / Alert filter
Price matrix per tier/division, net-win and region multipliers, margin/min/round; alert filters by category/region/min-price (unchanged from before).

## Captured Eldorado endpoints (Phase 2)

| Purpose | Request |
|------|------|
| Request detail | `GET /api/boostingOffers/boostingRequests/{id}` |
| **Create offer** | `POST /api/boostingOffers` — `{details:{boostingRequestId, guaranteedDeliveryTime, pricing:{quantity,minQuantity,volumeDiscounts,pricePerUnit:{amount,currency}}}}` |
| Start conversation | `POST /api/boostingOffers/boostingRequests/{id}/createConversationForSeller` → `talkJsConversationId` |
| TalkJS auth | `GET /api/conversations/me/authorize` → `{token}` |

Offer price = `EldoradoPricing.compute(req).final` (USD). Only **Rank Boost (5)** and **Placements (6)** are offerable (confirmed body). **Net Wins (7)** needs a win-count quantity and **Custom (4)** has no price → excluded from offers.

## Safety / guardrails
- **Master kill switch** (default off) gates every offer/conversation/message.
- **Dedup**: a request is never offered twice (`offered` map in storage).
- **Rate limit**: `max offers/hour` + `min gap (s)` between auto-offers.
- **Price guards**: skip if price is null, below floor, or (auto only) above cap.
- **Scope**: auto-offers only fire for enabled categories + selected regions.
- Test offers create **real** offers (money/obligation) — start with the manual button and care. Automatic offering carries higher ToS risk; a manual-approval start is recommended.

## Messaging text — not wired yet (Phase 2b)
Starting a conversation works now. **Sending opener text** needs the outbound TalkJS "send message" frame (we only have the inbound socket format). Plan: either drive the page's existing TalkJS session (MAIN-world) or replicate a captured outbound send. Until then the *Send opener* toggle is disabled.

## File structure

| File | Role |
|------|------|
| `manifest.json` | MV3 definition |
| `content.js` | Polls the API + `apiFetch` relay (the actual same-site fetcher) |
| `parse.js` | Notification JSON → clean request object |
| `pricing.js` | `EldoradoPricing` — per-request price engine |
| `background.js` | Service worker: dedup, notifications, badge, sound, **offer engine** |
| `offscreen.html/js` | Background notification sound |
| `popup.html/js/css` | List + Offer buttons + settings (incl. Automation) |
| `assets/` | Icons, `alert.wav`, rank emblems (`assets/ranks/`) |
| `tools/generate-assets.js` | Generates the icons + sound |
| `tools/test-offer.js` | Locks the offer-body contract (`node tools/test-offer.js`) |

Regenerate assets: `node tools/generate-assets.js`

## Security note
Tokens are read live from the browser and never persisted. Do not commit cookies/tokens. If you pasted a live session anywhere, rotate it (re-login).
