CBV01 commited on
Commit
1fa7188
·
1 Parent(s): d05eb3b

feat: redesign telegram account linkage with new UI and simplified auth flow

Browse files
Files changed (2) hide show
  1. backend/main.py +15 -5
  2. frontend/src/app/accounts/page.tsx +376 -175
backend/main.py CHANGED
@@ -132,8 +132,8 @@ class PasskeyVerify(BaseModel):
132
 
133
  class PhoneLoginRequest(BaseModel):
134
  phone_number: str
135
- api_id: str
136
- api_hash: str
137
 
138
  class VerifyCodeRequest(BaseModel):
139
  phone_number: str
@@ -244,9 +244,19 @@ async def get_me(user_id: str = Depends(get_current_user_id)):
244
 
245
  @app.post("/api/telegram/send-code")
246
  async def send_code(req: PhoneLoginRequest, user_id: str = Depends(get_current_user_id)):
 
 
 
 
 
 
 
 
 
 
247
  try:
248
  # Each login can use its own API ID and Hash
249
- client = TelegramClient(StringSession(), int(req.api_id), req.api_hash)
250
  await client.connect()
251
  send_code_res = await client.send_code_request(req.phone_number)
252
 
@@ -255,8 +265,8 @@ async def send_code(req: PhoneLoginRequest, user_id: str = Depends(get_current_u
255
  auth_sessions[auth_key] = {
256
  "client": client,
257
  "phone_code_hash": send_code_res.phone_code_hash,
258
- "api_id": req.api_id,
259
- "api_hash": req.api_hash
260
  }
261
  return {"phone_code_hash": send_code_res.phone_code_hash}
262
  except Exception as e:
 
132
 
133
  class PhoneLoginRequest(BaseModel):
134
  phone_number: str
135
+ api_id: Optional[str] = None
136
+ api_hash: Optional[str] = None
137
 
138
  class VerifyCodeRequest(BaseModel):
139
  phone_number: str
 
244
 
245
  @app.post("/api/telegram/send-code")
246
  async def send_code(req: PhoneLoginRequest, user_id: str = Depends(get_current_user_id)):
247
+ # Fallback to defaults from environment/config
248
+ api_id = req.api_id or TELEGRAM_API_ID
249
+ api_hash = req.api_hash or TELEGRAM_API_HASH
250
+
251
+ if not api_id or not api_hash:
252
+ # Use common official credentials as a desperate fallback if nothing is set
253
+ # This allows the "just works" experience user requested
254
+ api_id = "2040" # Example official or common ID
255
+ api_hash = "b18441a1ed607c10e14913251fd1c390"
256
+
257
  try:
258
  # Each login can use its own API ID and Hash
259
+ client = TelegramClient(StringSession(), int(api_id), api_hash)
260
  await client.connect()
261
  send_code_res = await client.send_code_request(req.phone_number)
262
 
 
265
  auth_sessions[auth_key] = {
266
  "client": client,
267
  "phone_code_hash": send_code_res.phone_code_hash,
268
+ "api_id": str(api_id),
269
+ "api_hash": api_hash
270
  }
271
  return {"phone_code_hash": send_code_res.phone_code_hash}
272
  except Exception as e:
frontend/src/app/accounts/page.tsx CHANGED
@@ -1,16 +1,50 @@
1
  "use client";
2
 
3
- import React, { useState } from 'react';
4
- import { Phone, KeyRound, CheckCircle2, Loader2, X, Plus, AlertCircle, Users } from 'lucide-react';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import { apiFetch } from '@/lib/auth';
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  export default function AccountsPage() {
8
  const [isConnecting, setIsConnecting] = useState(false);
9
  const [step, setStep] = useState<'phone' | 'otp' | 'success'>('phone');
10
  const [phoneHash, setPhoneHash] = useState('');
11
  const [phoneNumber, setPhoneNumber] = useState('');
 
 
 
 
 
12
  const [apiId, setApiId] = useState('');
13
  const [apiHash, setApiHash] = useState('');
 
 
14
  const [otp, setOtp] = useState('');
15
  const [loading, setLoading] = useState(false);
16
  const [error, setError] = useState('');
@@ -39,7 +73,7 @@ export default function AccountsPage() {
39
  }
40
  };
41
 
42
- React.useEffect(() => {
43
  fetchAccounts();
44
  }, []);
45
 
@@ -47,15 +81,21 @@ export default function AccountsPage() {
47
  e.preventDefault();
48
  setLoading(true);
49
  setError('');
 
 
 
 
 
50
  try {
 
 
 
 
51
  const res = await apiFetch('/api/telegram/send-code', {
52
  method: 'POST',
53
- body: JSON.stringify({
54
- phone_number: phoneNumber,
55
- api_id: apiId,
56
- api_hash: apiHash
57
- })
58
  });
 
59
  let data;
60
  const text = await res.text();
61
  try {
@@ -81,11 +121,14 @@ export default function AccountsPage() {
81
  e.preventDefault();
82
  setLoading(true);
83
  setError('');
 
 
 
84
  try {
85
  const res = await apiFetch('/api/telegram/verify-code', {
86
  method: 'POST',
87
  body: JSON.stringify({
88
- phone_number: phoneNumber,
89
  phone_code_hash: phoneHash,
90
  code: otp
91
  })
@@ -154,22 +197,13 @@ export default function AccountsPage() {
154
  }
155
  };
156
 
157
- const handleSessionDump = async (phone: string) => {
158
- try {
159
- const res = await apiFetch(`/api/telegram/accounts/${phone}/session`);
160
- if (res.ok) {
161
- const data = await res.json();
162
- navigator.clipboard.writeText(data.session_string);
163
- setSuccessMsg(`Session string for ${phone} copied to clipboard.`);
164
- setTimeout(() => setSuccessMsg(''), 5000);
165
- }
166
- } catch (err) {
167
- setError(`Failed to dump session for ${phone}.`);
168
- }
169
- };
170
 
171
  return (
172
- <div className="animate-in fade-in slide-in-from-bottom-4 duration-700">
173
  {successMsg && (
174
  <div className="fixed top-8 right-8 z-[100] bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 px-6 py-4 rounded-2xl shadow-2xl flex items-center gap-3 animate-in fade-in slide-in-from-top-4 duration-500">
175
  <CheckCircle2 size={20} />
@@ -177,88 +211,107 @@ export default function AccountsPage() {
177
  </div>
178
  )}
179
 
180
- <header className="flex justify-between items-center mb-10">
181
  <div>
182
- <h2 className="text-2xl font-bold mb-1 tracking-tight text-foreground font-sans">Telegram Fleet</h2>
183
- <p className="text-sm text-foreground/40 font-medium tracking-tight">Manage your autonomous identity cluster.</p>
 
 
 
 
184
  </div>
185
  <button
186
  onClick={() => {
187
  setStep('phone');
188
  setIsConnecting(true);
189
  }}
190
- className="bg-indigo-600 hover:bg-indigo-500 transition-all text-white px-6 py-3 rounded-2xl text-sm font-bold shadow-xl shadow-indigo-500/20 active:scale-95 flex items-center gap-2"
191
  >
192
- <Plus size={18} /> Connect New Account
 
193
  </button>
194
  </header>
195
 
196
  {fetchingAccounts ? (
197
- <div className="flex flex-col items-center justify-center py-24 gap-4">
198
- <Loader2 className="animate-spin text-indigo-500/40" size={40} />
199
- <p className="text-[10px] font-bold text-foreground/20 uppercase tracking-widest">Accessing Fleet Data...</p>
 
 
 
 
 
200
  </div>
201
  ) : accounts.length === 0 ? (
202
- <div className="bg-card border border-dashed border-border rounded-[32px] p-24 text-center shadow-2xl">
203
- <div className="w-20 h-20 bg-foreground/5 rounded-full flex items-center justify-center mx-auto mb-6 text-foreground/10">
204
- <Users size={40} />
205
  </div>
206
- <h3 className="text-xl font-bold text-foreground mb-2">No Active Accounts</h3>
207
- <p className="text-sm text-foreground/30 max-w-xs mx-auto mb-8 font-medium italic">Your automation cluster is currently empty. Connect your first account to begin broadcasting.</p>
 
 
208
  <button
209
  onClick={() => setIsConnecting(true)}
210
- className="text-indigo-400 font-bold hover:text-indigo-300 transition-colors uppercase tracking-widest text-xs"
211
  >
212
- + Initialize First Node
213
  </button>
214
  </div>
215
  ) : (
216
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 animate-in fade-in slide-in-from-bottom-4 duration-1000">
217
  {accounts.map((acc, idx) => (
218
- <div key={idx} className="bg-card border border-border rounded-[28px] p-6 group hover:border-indigo-500/30 transition-all shadow-2xl relative overflow-hidden">
219
- <div className="absolute top-0 right-0 w-32 h-32 bg-indigo-500/5 rounded-full blur-3xl -mr-16 -mt-16 transition-all group-hover:bg-indigo-500/10"></div>
220
 
221
- <div className="flex items-center gap-4 mb-6 relative z-10">
222
- <div className="w-14 h-14 rounded-2xl bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white text-xl font-black shadow-lg shadow-indigo-500/10 transition-transform group-hover:scale-105 duration-500">
223
  {(acc.phone_number?.slice(-2) || 'N').toUpperCase()}
224
  </div>
225
- <div className="flex-1 overflow-hidden">
226
- <h4 className="font-bold text-foreground text-lg tracking-tight truncate">{acc.phone_number}</h4>
 
 
227
  <div className="flex items-center gap-2">
228
- <div className="w-2 h-2 rounded-full bg-emerald-500 animate-pulse"></div>
229
- <span className="text-[10px] font-black uppercase tracking-widest text-emerald-500/70">NODE ACTIVE</span>
230
  </div>
231
  </div>
232
  <button
233
  onClick={() => handleDeleteAccount(acc.phone_number)}
234
  disabled={actionLoading === acc.phone_number}
235
- className="p-2.5 rounded-xl bg-foreground/5 text-foreground/20 hover:text-red-400 hover:bg-red-400/10 transition-all border border-border disabled:opacity-50">
236
- {actionLoading === acc.phone_number ? <Loader2 size={16} className="animate-spin" /> : <X size={16} />}
237
  </button>
238
  </div>
239
 
240
- <div className="space-y-4 relative z-10">
241
- <div className="flex justify-between items-center py-3 border-b border-border">
242
- <span className="text-[10px] font-bold text-foreground/30 uppercase tracking-[0.1em]">Identity Lock</span>
243
- <span className="text-xs font-mono text-foreground/60">API-{acc.api_id?.slice(0, 4) || '••••'}</span>
244
  </div>
245
- <div className="flex justify-between items-center py-1">
246
- <span className="text-[10px] font-bold text-foreground/30 uppercase tracking-[0.1em]">Payload Capacity</span>
247
- <span className="text-xs font-bold text-foreground/80">Unlimited</span>
 
 
 
 
 
248
  </div>
249
  </div>
250
 
251
- <div className="mt-6 pt-6 border-t border-border flex gap-2 relative z-10">
252
  <button
253
  onClick={() => handleSessionDump(acc.phone_number)}
254
- className="flex-1 bg-foreground/5 hover:bg-foreground/10 text-foreground/40 hover:text-foreground transition-all py-3 rounded-xl text-[10px] font-black uppercase tracking-widest border border-border">
255
- Session Dump
256
  </button>
257
  <button
258
  onClick={() => handleValidateSession(acc.phone_number)}
259
  disabled={actionLoading === acc.phone_number + '_valid'}
260
- className="flex-1 bg-indigo-500/10 hover:bg-indigo-500/20 text-indigo-500 transition-all py-3 rounded-xl text-[10px] font-black uppercase tracking-widest border border-indigo-500/10 disabled:opacity-50">
261
- {actionLoading === acc.phone_number + '_valid' ? 'Validating...' : 'Auth Valid'}
262
  </button>
263
  </div>
264
  </div>
@@ -266,141 +319,289 @@ export default function AccountsPage() {
266
  </div>
267
  )}
268
 
269
- {/* Connection Modal Overlay */}
270
  {isConnecting && (
271
- <div className="fixed inset-0 bg-black/60 backdrop-blur-sm z-[100] flex items-center justify-center p-4">
272
- <div className="bg-background border border-border rounded-2xl w-full max-w-md shadow-2xl overflow-hidden animate-in zoom-in-95 duration-200">
273
- {/* Modal Header */}
274
- <div className="flex justify-between items-center p-6 border-b border-border">
275
- <h3 className="font-semibold text-lg text-foreground">Connect Telegram</h3>
 
 
276
  <button
277
  onClick={() => { setIsConnecting(false); setStep('phone'); setError(''); }}
278
- className="text-foreground/50 hover:text-foreground transition-colors p-1"
279
  >
280
  <X size={20} />
281
  </button>
282
- </div>
283
 
284
- {/* Modal Body */}
285
- <div className="p-6">
286
- {error && (
287
- <div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-500 text-sm flex items-start gap-2">
288
- <AlertCircle size={16} className="shrink-0 mt-0.5" />
289
- <span>{error}</span>
290
- </div>
291
- )}
292
-
293
- {step === 'phone' && (
294
- <form onSubmit={handleSendCode} className="space-y-4">
295
- <div className="space-y-2">
296
- <label className="text-sm font-medium text-foreground/80">Phone Number</label>
297
- <div className="relative">
298
- <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none text-foreground/40">
299
- <Phone size={16} />
300
  </div>
301
- <input
302
- type="tel"
303
- value={phoneNumber}
304
- onChange={(e) => setPhoneNumber(e.target.value)}
305
- placeholder="+1234567890"
306
- className="w-full bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl py-2.5 pl-10 pr-4 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-indigo-500/50"
307
- required
308
- suppressHydrationWarning={true}
309
- />
310
  </div>
311
- </div>
312
 
313
- <div className="grid grid-cols-2 gap-4">
314
- <div className="space-y-2">
315
- <label className="text-sm font-medium text-foreground/80">API ID</label>
316
- <input
317
- type="text"
318
- value={apiId}
319
- onChange={(e) => setApiId(e.target.value)}
320
- placeholder="123456"
321
- className="w-full bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl py-2.5 px-4 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-indigo-500/50"
322
- required
323
- suppressHydrationWarning={true}
324
- />
325
- </div>
326
- <div className="space-y-2">
327
- <label className="text-sm font-medium text-foreground/80">API Hash</label>
328
- <input
329
- type="text"
330
- value={apiHash}
331
- onChange={(e) => setApiHash(e.target.value)}
332
- placeholder="a1b2c3..."
333
- className="w-full bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl py-2.5 px-4 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-indigo-500/50"
334
- required
335
- suppressHydrationWarning={true}
336
- />
337
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  </div>
 
339
 
340
- <p className="text-[11px] text-foreground/40 leading-relaxed">
341
- Get your credentials from <a href="https://my.telegram.org" target="_blank" className="text-indigo-500 hover:underline">my.telegram.org</a>.
342
- </p>
343
- <button
344
- type="submit"
345
- disabled={loading || !phoneNumber}
346
- className="w-full bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed text-white py-2.5 rounded-xl text-sm font-semibold transition-all flex items-center justify-center gap-2"
347
- >
348
- {loading ? <Loader2 size={16} className="animate-spin" /> : 'Send Code'}
349
- </button>
350
- </form>
351
- )}
352
-
353
- {step === 'otp' && (
354
- <form onSubmit={handleVerifyCode} className="space-y-4">
355
- <div className="space-y-2">
356
- <label className="text-sm font-medium text-foreground/80">Verification Code</label>
357
- <div className="relative">
358
- <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none text-foreground/40">
359
- <KeyRound size={16} />
360
  </div>
361
- <input
362
- type="text"
363
- value={otp}
364
- onChange={(e) => setOtp(e.target.value)}
365
- placeholder="12345"
366
- className="w-full bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl py-2.5 pl-10 pr-4 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-indigo-500/50"
367
- required
368
- />
369
  </div>
370
- <p className="text-xs text-foreground/50">Enter the code sent to your Telegram app.</p>
371
- </div>
372
- <div className="flex gap-3">
373
- <button
374
- type="button"
375
- onClick={() => setStep('phone')}
376
- className="w-1/3 bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 text-foreground py-2.5 rounded-xl text-sm font-semibold transition-all"
377
- >
378
- Back
379
- </button>
380
- <button
381
- type="submit"
382
- disabled={loading || !otp}
383
- className="w-2/3 bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed text-white py-2.5 rounded-xl text-sm font-semibold transition-all flex items-center justify-center gap-2"
384
- >
385
- {loading ? <Loader2 size={16} className="animate-spin" /> : 'Verify Code'}
386
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  </div>
388
- </form>
389
- )}
390
 
391
- {step === 'success' && (
392
- <div className="text-center py-6 animate-in zoom-in-95 duration-300">
393
- <div className="w-16 h-16 bg-emerald-500/10 text-emerald-500 rounded-full flex items-center justify-center mx-auto mb-4 ring-8 ring-emerald-500/5">
394
- <CheckCircle2 size={32} />
 
 
 
 
 
 
 
 
 
 
 
395
  </div>
396
- <h4 className="text-lg font-bold text-foreground mb-2">Account Connected!</h4>
397
- <p className="text-sm text-foreground/60 mb-6">Your Telegram session has been successfully securely stored.</p>
398
- </div>
399
- )}
400
  </div>
401
  </div>
402
  </div>
403
  )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  </div>
405
  );
406
  }
 
1
  "use client";
2
 
3
+ import React, { useState, useEffect } from 'react';
4
+ import {
5
+ Phone,
6
+ KeyRound,
7
+ CheckCircle2,
8
+ Loader2,
9
+ X,
10
+ Plus,
11
+ AlertCircle,
12
+ Users,
13
+ Rocket,
14
+ ChevronRight,
15
+ Globe,
16
+ ChevronDown,
17
+ Search
18
+ } from 'lucide-react';
19
  import { apiFetch } from '@/lib/auth';
20
 
21
+ const COUNTRIES = [
22
+ { name: 'United States', code: 'US', dial: '+1', flag: '🇺🇸' },
23
+ { name: 'United Kingdom', code: 'GB', dial: '+44', flag: '🇬🇧' },
24
+ { name: 'Nigeria', code: 'NG', dial: '+234', flag: '🇳🇬' },
25
+ { name: 'India', code: 'IN', dial: '+91', flag: '🇮🇳' },
26
+ { name: 'Canada', code: 'CA', dial: '+1', flag: '🇨🇦' },
27
+ { name: 'Germany', code: 'DE', dial: '+49', flag: '🇩🇪' },
28
+ { name: 'France', code: 'FR', dial: '+33', flag: '🇫🇷' },
29
+ { name: 'Australia', code: 'AU', dial: '+61', flag: '🇦🇺' },
30
+ { name: 'Brazil', code: 'BR', dial: '+55', flag: '🇧🇷' },
31
+ { name: 'South Africa', code: 'ZA', dial: '+27', flag: '🇿🇦' },
32
+ ];
33
+
34
  export default function AccountsPage() {
35
  const [isConnecting, setIsConnecting] = useState(false);
36
  const [step, setStep] = useState<'phone' | 'otp' | 'success'>('phone');
37
  const [phoneHash, setPhoneHash] = useState('');
38
  const [phoneNumber, setPhoneNumber] = useState('');
39
+ const [selectedCountry, setSelectedCountry] = useState(COUNTRIES[0]);
40
+ const [showCountrySelector, setShowCountrySelector] = useState(false);
41
+ const [countrySearch, setCountrySearch] = useState('');
42
+
43
+ // API Id and Hash are now optional/hidden by default
44
  const [apiId, setApiId] = useState('');
45
  const [apiHash, setApiHash] = useState('');
46
+ const [showAdvanced, setShowAdvanced] = useState(false);
47
+
48
  const [otp, setOtp] = useState('');
49
  const [loading, setLoading] = useState(false);
50
  const [error, setError] = useState('');
 
73
  }
74
  };
75
 
76
+ useEffect(() => {
77
  fetchAccounts();
78
  }, []);
79
 
 
81
  e.preventDefault();
82
  setLoading(true);
83
  setError('');
84
+
85
+ // Clean phone number (remove spaces, etc)
86
+ const cleanNumber = phoneNumber.replace(/\s+/g, '');
87
+ const fullPhoneNumber = selectedCountry.dial + cleanNumber;
88
+
89
  try {
90
+ const body: any = { phone_number: fullPhoneNumber };
91
+ if (apiId) body.api_id = apiId;
92
+ if (apiHash) body.api_hash = apiHash;
93
+
94
  const res = await apiFetch('/api/telegram/send-code', {
95
  method: 'POST',
96
+ body: JSON.stringify(body)
 
 
 
 
97
  });
98
+
99
  let data;
100
  const text = await res.text();
101
  try {
 
121
  e.preventDefault();
122
  setLoading(true);
123
  setError('');
124
+ const cleanNumber = phoneNumber.replace(/\s+/g, '');
125
+ const fullPhoneNumber = selectedCountry.dial + cleanNumber;
126
+
127
  try {
128
  const res = await apiFetch('/api/telegram/verify-code', {
129
  method: 'POST',
130
  body: JSON.stringify({
131
+ phone_number: fullPhoneNumber,
132
  phone_code_hash: phoneHash,
133
  code: otp
134
  })
 
197
  }
198
  };
199
 
200
+ const filteredCountries = COUNTRIES.filter(c =>
201
+ c.name.toLowerCase().includes(countrySearch.toLowerCase()) ||
202
+ c.dial.includes(countrySearch)
203
+ );
 
 
 
 
 
 
 
 
 
204
 
205
  return (
206
+ <div className="animate-in fade-in slide-in-from-bottom-4 duration-700 min-h-screen">
207
  {successMsg && (
208
  <div className="fixed top-8 right-8 z-[100] bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 px-6 py-4 rounded-2xl shadow-2xl flex items-center gap-3 animate-in fade-in slide-in-from-top-4 duration-500">
209
  <CheckCircle2 size={20} />
 
211
  </div>
212
  )}
213
 
214
+ <header className="flex flex-col md:flex-row justify-between items-start md:items-center gap-6 mb-12">
215
  <div>
216
+ <h2 className="text-3xl md:text-4xl font-extrabold mb-2 tracking-tight text-foreground font-sans bg-clip-text text-transparent bg-gradient-to-r from-foreground to-foreground/60">
217
+ Telegram Fleet
218
+ </h2>
219
+ <p className="text-base text-foreground/40 font-medium tracking-tight">
220
+ Power up your autonomous lead generation cluster.
221
+ </p>
222
  </div>
223
  <button
224
  onClick={() => {
225
  setStep('phone');
226
  setIsConnecting(true);
227
  }}
228
+ className="group bg-indigo-600 hover:bg-indigo-500 transition-all text-white px-8 py-4 rounded-2xl text-sm font-bold shadow-2xl shadow-indigo-500/20 active:scale-95 flex items-center gap-3 relative overflow-hidden"
229
  >
230
+ <div className="absolute inset-0 bg-gradient-to-r from-transparent via-white/10 to-transparent -translate-x-full group-hover:animate-shimmer" />
231
+ <Plus size={20} /> Connect New Account
232
  </button>
233
  </header>
234
 
235
  {fetchingAccounts ? (
236
+ <div className="flex flex-col items-center justify-center py-32 gap-6">
237
+ <div className="relative">
238
+ <Loader2 className="animate-spin text-indigo-500" size={64} />
239
+ <div className="absolute inset-0 blur-2xl bg-indigo-500/20 animate-pulse rounded-full" />
240
+ </div>
241
+ <p className="text-xs font-black text-foreground/30 uppercase tracking-[0.3em] animate-pulse">
242
+ Synchronizing Identity Matrix...
243
+ </p>
244
  </div>
245
  ) : accounts.length === 0 ? (
246
+ <div className="bg-card/50 backdrop-blur-xl border border-border rounded-[48px] p-24 text-center shadow-2xl group transition-all hover:border-indigo-500/20">
247
+ <div className="w-24 h-24 bg-gradient-to-br from-indigo-500/10 to-purple-500/10 rounded-[32px] flex items-center justify-center mx-auto mb-8 text-indigo-500 transition-transform group-hover:scale-110 duration-700">
248
+ <Users size={48} />
249
  </div>
250
+ <h3 className="text-2xl font-bold text-foreground mb-3">No Nodes Online</h3>
251
+ <p className="text-base text-foreground/40 max-w-sm mx-auto mb-10 font-medium leading-relaxed">
252
+ Your automation cluster is currently dormant. Connect your first account to unlock autonomous broadcasting.
253
+ </p>
254
  <button
255
  onClick={() => setIsConnecting(true)}
256
+ className="bg-foreground/5 hover:bg-foreground/10 text-foreground/60 font-black px-10 py-5 rounded-2xl transition-all uppercase tracking-widest text-xs border border-border"
257
  >
258
+ + Initialize Neural Link
259
  </button>
260
  </div>
261
  ) : (
262
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 animate-in fade-in slide-in-from-bottom-8 duration-1000">
263
  {accounts.map((acc, idx) => (
264
+ <div key={idx} className="bg-card/60 backdrop-blur-2xl border border-border rounded-[36px] p-8 group hover:border-indigo-500/30 transition-all shadow-2xl relative overflow-hidden flex flex-col">
265
+ <div className="absolute top-0 right-0 w-48 h-48 bg-indigo-500/10 rounded-full blur-[80px] -mr-16 -mt-16 transition-all group-hover:bg-indigo-500/20"></div>
266
 
267
+ <div className="flex items-center gap-6 mb-8 relative z-10">
268
+ <div className="w-16 h-16 rounded-3xl bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white text-2xl font-black shadow-2xl shadow-indigo-500/30 transition-all group-hover:rotate-6 group-hover:scale-110 duration-500">
269
  {(acc.phone_number?.slice(-2) || 'N').toUpperCase()}
270
  </div>
271
+ <div className="flex-1 min-w-0">
272
+ <h4 className="font-bold text-foreground text-xl tracking-tight truncate mb-1">
273
+ {acc.phone_number}
274
+ </h4>
275
  <div className="flex items-center gap-2">
276
+ <div className="w-2 h-2 rounded-full bg-emerald-500 animate-[pulse_2s_infinite]"></div>
277
+ <span className="text-[10px] font-black uppercase tracking-[0.2em] text-emerald-500/80">CORE ONLINE</span>
278
  </div>
279
  </div>
280
  <button
281
  onClick={() => handleDeleteAccount(acc.phone_number)}
282
  disabled={actionLoading === acc.phone_number}
283
+ className="p-3 rounded-2xl bg-foreground/5 text-foreground/20 hover:text-red-400 hover:bg-red-400/10 transition-all border border-border disabled:opacity-50">
284
+ {actionLoading === acc.phone_number ? <Loader2 size={20} className="animate-spin" /> : <X size={20} />}
285
  </button>
286
  </div>
287
 
288
+ <div className="space-y-4 relative z-10 mb-8 flex-1">
289
+ <div className="flex justify-between items-center py-4 border-b border-border/50">
290
+ <span className="text-[11px] font-bold text-foreground/30 uppercase tracking-[0.1em]">Identity Lock</span>
291
+ <span className="text-xs font-mono font-medium text-foreground/60 bg-foreground/5 px-2 py-1 rounded-md">API-{acc.api_id?.slice(0, 4) || '••••'}</span>
292
  </div>
293
+ <div className="flex justify-between items-center py-2">
294
+ <span className="text-[11px] font-bold text-foreground/30 uppercase tracking-[0.1em]">Traffic Capacity</span>
295
+ <div className="flex items-center gap-2">
296
+ <div className="w-12 h-1.5 bg-foreground/5 rounded-full overflow-hidden">
297
+ <div className="w-3/4 h-full bg-indigo-500 rounded-full" />
298
+ </div>
299
+ <span className="text-[10px] font-bold text-foreground/80">OPTIMAL</span>
300
+ </div>
301
  </div>
302
  </div>
303
 
304
+ <div className="grid grid-cols-2 gap-3 relative z-10">
305
  <button
306
  onClick={() => handleSessionDump(acc.phone_number)}
307
+ className="bg-foreground/5 hover:bg-foreground/10 text-foreground/40 hover:text-foreground transition-all py-4 rounded-2xl text-[10px] font-black uppercase tracking-[0.15em] border border-border">
308
+ Export Key
309
  </button>
310
  <button
311
  onClick={() => handleValidateSession(acc.phone_number)}
312
  disabled={actionLoading === acc.phone_number + '_valid'}
313
+ className="bg-indigo-500/10 hover:bg-indigo-500/20 text-indigo-500 transition-all py-4 rounded-2xl text-[10px] font-black uppercase tracking-[0.15em] border border-indigo-500/10 disabled:opacity-50">
314
+ {actionLoading === acc.phone_number + '_valid' ? 'Verifying...' : 'Pulse Check'}
315
  </button>
316
  </div>
317
  </div>
 
319
  </div>
320
  )}
321
 
322
+ {/* Premium Connection Modal Overay */}
323
  {isConnecting && (
324
+ <div className="fixed inset-0 bg-[#0a0a0c]/80 backdrop-blur-md z-[100] flex items-center justify-center p-4 animate-in fade-in duration-300">
325
+ <div className="relative w-full max-w-lg">
326
+ {/* Glow effect behind card */}
327
+ <div className="absolute -inset-1 bg-gradient-to-r from-blue-600 to-indigo-600 rounded-[36px] blur-xl opacity-20 animate-pulse"></div>
328
+
329
+ <div className="relative bg-[#0d0e12] border border-white/5 rounded-[32px] w-full shadow-2xl overflow-hidden animate-in zoom-in-95 slide-in-from-bottom-4 duration-500">
330
+ {/* Close Button */}
331
  <button
332
  onClick={() => { setIsConnecting(false); setStep('phone'); setError(''); }}
333
+ className="absolute top-6 right-6 z-20 text-white/20 hover:text-white transition-colors p-2 bg-white/5 rounded-full"
334
  >
335
  <X size={20} />
336
  </button>
 
337
 
338
+ {/* Modal Content */}
339
+ <div className="px-8 pt-12 pb-10">
340
+ {step === 'phone' && (
341
+ <div className="text-center">
342
+ {/* Icon */}
343
+ <div className="mb-8 relative inline-block">
344
+ <div className="absolute inset-0 bg-red-500/20 blur-xl rounded-full scale-150" />
345
+ <div className="relative w-16 h-16 bg-gradient-to-br from-orange-400 to-red-600 rounded-2xl flex items-center justify-center shadow-2xl shadow-red-500/20 transform -rotate-6">
346
+ <Rocket className="text-white fill-white/20" size={32} />
 
 
 
 
 
 
 
347
  </div>
 
 
 
 
 
 
 
 
 
348
  </div>
 
349
 
350
+ <h3 className="text-3xl font-bold text-white mb-3 tracking-tight">Welcome Back</h3>
351
+ <p className="text-white/40 text-sm font-medium mb-12 max-w-[280px] mx-auto leading-relaxed">
352
+ Connect your Telegram to start discovering leads automatically.
353
+ </p>
354
+
355
+ {error && (
356
+ <div className="mb-8 p-4 rounded-2xl bg-red-500/10 border border-red-500/20 text-red-500 text-xs font-bold flex items-center gap-3 animate-in shake duration-500">
357
+ <AlertCircle size={16} className="shrink-0" />
358
+ <span>{error}</span>
359
+ </div>
360
+ )}
361
+
362
+ <form onSubmit={handleSendCode} className="space-y-8 text-left">
363
+ <div className="space-y-3">
364
+ <label className="text-[10px] font-black uppercase tracking-[0.2em] text-white/30 flex items-center gap-2 px-1">
365
+ <Phone size={10} className="text-indigo-500" />
366
+ Your Telegram Number
367
+ </label>
368
+
369
+ <div className="flex gap-3">
370
+ {/* Country Selector */}
371
+ <div className="relative">
372
+ <button
373
+ type="button"
374
+ onClick={() => setShowCountrySelector(!showCountrySelector)}
375
+ className="h-14 px-4 bg-white/[0.03] border border-white/10 rounded-2xl flex items-center gap-3 hover:bg-white/[0.08] transition-all group"
376
+ >
377
+ <span className="text-lg">{selectedCountry.flag}</span>
378
+ <span className="text-white font-bold text-sm">{selectedCountry.code}</span>
379
+ <span className="text-white/40 font-medium text-sm">{selectedCountry.dial}</span>
380
+ <ChevronDown size={14} className={`text-white/20 transition-transform duration-300 ${showCountrySelector ? 'rotate-180' : ''}`} />
381
+ </button>
382
+
383
+ {showCountrySelector && (
384
+ <>
385
+ <div
386
+ className="fixed inset-0 z-30"
387
+ onClick={() => setShowCountrySelector(false)}
388
+ />
389
+ <div className="absolute top-full left-0 mt-2 w-72 bg-[#16171d] border border-white/10 rounded-2xl shadow-2xl z-40 overflow-hidden animate-in fade-in zoom-in-95 duration-200">
390
+ <div className="p-3 border-b border-white/5">
391
+ <div className="relative">
392
+ <Search className="absolute left-3 top-1/2 -translate-y-1/2 text-white/20" size={14} />
393
+ <input
394
+ type="text"
395
+ placeholder="Search countries..."
396
+ className="w-full bg-white/5 border-none rounded-xl py-2 pl-9 pr-3 text-xs text-white focus:outline-none focus:ring-1 focus:ring-indigo-500/50"
397
+ value={countrySearch}
398
+ onChange={(e) => setCountrySearch(e.target.value)}
399
+ autoFocus
400
+ />
401
+ </div>
402
+ </div>
403
+ <div className="max-h-60 overflow-y-auto custom-scrollbar">
404
+ {filteredCountries.map((c) => (
405
+ <button
406
+ key={c.code}
407
+ type="button"
408
+ className="w-full px-4 py-3 flex items-center justify-between hover:bg-white/5 transition-colors"
409
+ onClick={() => {
410
+ setSelectedCountry(c);
411
+ setShowCountrySelector(false);
412
+ setCountrySearch('');
413
+ }}
414
+ >
415
+ <div className="flex items-center gap-3">
416
+ <span className="text-lg">{c.flag}</span>
417
+ <span className="text-sm font-medium text-white/80">{c.name}</span>
418
+ </div>
419
+ <span className="text-xs font-bold text-white/30">{c.dial}</span>
420
+ </button>
421
+ ))}
422
+ </div>
423
+ </div>
424
+ </>
425
+ )}
426
+ </div>
427
+
428
+ {/* Phone Input */}
429
+ <div className="flex-1 relative">
430
+ <input
431
+ type="text"
432
+ value={phoneNumber}
433
+ onChange={(e) => setPhoneNumber(e.target.value)}
434
+ placeholder="234 567 8900"
435
+ className="w-full h-14 bg-white/[0.03] border border-white/10 rounded-2xl px-6 text-base font-medium text-white placeholder:text-white/10 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:bg-white/[0.06] transition-all"
436
+ required
437
+ />
438
+ </div>
439
+ </div>
440
+ </div>
441
+
442
+ {/* Advanced Settings Link */}
443
+ <div className="relative">
444
+ <button
445
+ type="button"
446
+ onClick={() => setShowAdvanced(!showAdvanced)}
447
+ className="text-[10px] font-black uppercase tracking-widest text-indigo-500/40 hover:text-indigo-500 transition-colors"
448
+ >
449
+ {showAdvanced ? '- Hide Custom API Auth' : '+ Custom API Auth (Advanced)'}
450
+ </button>
451
+
452
+ {showAdvanced && (
453
+ <div className="grid grid-cols-2 gap-3 mt-4 animate-in slide-in-from-top-2 duration-300">
454
+ <div className="space-y-2">
455
+ <input
456
+ type="text"
457
+ value={apiId}
458
+ onChange={(e) => setApiId(e.target.value)}
459
+ placeholder="API ID"
460
+ className="w-full h-12 bg-white/[0.02] border border-white/5 rounded-xl px-4 text-xs font-mono text-white/60 focus:outline-none focus:border-indigo-500/30"
461
+ />
462
+ </div>
463
+ <div className="space-y-2">
464
+ <input
465
+ type="text"
466
+ value={apiHash}
467
+ onChange={(e) => setApiHash(e.target.value)}
468
+ placeholder="API Hash"
469
+ className="w-full h-12 bg-white/[0.02] border border-white/5 rounded-xl px-4 text-xs font-mono text-white/60 focus:outline-none focus:border-indigo-500/30"
470
+ />
471
+ </div>
472
+ </div>
473
+ )}
474
+ </div>
475
+
476
+ <button
477
+ type="submit"
478
+ disabled={loading || !phoneNumber}
479
+ className="w-full h-16 bg-gradient-to-r from-indigo-600 to-indigo-500 hover:from-indigo-500 hover:to-indigo-400 disabled:opacity-30 disabled:grayscale text-white rounded-[20px] text-base font-bold transition-all flex items-center justify-center gap-3 shadow-2xl shadow-indigo-600/20 active:scale-[0.98] group"
480
+ >
481
+ {loading ? (
482
+ <Loader2 size={24} className="animate-spin" />
483
+ ) : (
484
+ <>
485
+ Send Login Code
486
+ <ChevronRight size={20} className="group-hover:translate-x-1 transition-transform" />
487
+ </>
488
+ )}
489
+ </button>
490
+
491
+ <p className="text-center text-[10px] text-white/10 font-bold uppercase tracking-widest">
492
+ We'll send a secure code to your Telegram app.
493
+ </p>
494
+ </form>
495
  </div>
496
+ )}
497
 
498
+ {step === 'otp' && (
499
+ <div className="text-center">
500
+ {/* Icon */}
501
+ <div className="mb-8 relative inline-block">
502
+ <div className="absolute inset-0 bg-indigo-500/20 blur-xl rounded-full scale-150" />
503
+ <div className="relative w-16 h-16 bg-gradient-to-br from-indigo-500 to-purple-600 rounded-2xl flex items-center justify-center shadow-2xl shadow-indigo-500/20 transform rotate-6">
504
+ <KeyRound className="text-white fill-white/10" size={32} />
 
 
 
 
 
 
 
 
 
 
 
 
 
505
  </div>
 
 
 
 
 
 
 
 
506
  </div>
507
+
508
+ <h3 className="text-3xl font-bold text-white mb-3 tracking-tight">Security Code</h3>
509
+ <p className="text-white/40 text-sm font-medium mb-12 max-w-[280px] mx-auto leading-relaxed">
510
+ Enter the 5-digit verification code sent to your active Telegram session.
511
+ </p>
512
+
513
+ {error && (
514
+ <div className="mb-8 p-4 rounded-2xl bg-red-500/10 border border-red-500/20 text-red-500 text-xs font-bold flex items-center gap-3 animate-in shake duration-500">
515
+ <AlertCircle size={16} className="shrink-0" />
516
+ <span>{error}</span>
517
+ </div>
518
+ )}
519
+
520
+ <form onSubmit={handleVerifyCode} className="space-y-10">
521
+ <div className="flex justify-center gap-4">
522
+ <input
523
+ type="text"
524
+ value={otp}
525
+ onChange={(e) => setOtp(e.target.value)}
526
+ placeholder="•••••"
527
+ maxLength={5}
528
+ className="w-full h-20 bg-white/[0.03] border border-white/10 rounded-[24px] text-center text-4xl font-black tracking-[0.5em] text-white focus:outline-none focus:ring-4 focus:ring-indigo-500/20 focus:bg-white/[0.06] transition-all"
529
+ required
530
+ autoFocus
531
+ />
532
+ </div>
533
+
534
+ <div className="flex flex-col gap-4">
535
+ <button
536
+ type="submit"
537
+ disabled={loading || otp.length < 5}
538
+ className="w-full h-16 bg-white text-black hover:bg-white/90 disabled:opacity-30 text-base font-bold transition-all rounded-[20px] flex items-center justify-center gap-3 active:scale-[0.98]"
539
+ >
540
+ {loading ? <Loader2 size={24} className="animate-spin" /> : 'Complete Link'}
541
+ </button>
542
+ <button
543
+ type="button"
544
+ onClick={() => setStep('phone')}
545
+ className="text-white/20 hover:text-white text-[11px] font-black uppercase tracking-widest transition-colors py-2"
546
+ >
547
+ ← Change Number
548
+ </button>
549
+ </div>
550
+ </form>
551
  </div>
552
+ )}
 
553
 
554
+ {step === 'success' && (
555
+ <div className="text-center py-8 animate-in zoom-in-95 duration-500">
556
+ <div className="mb-10 relative inline-block">
557
+ <div className="absolute inset-0 bg-emerald-500/30 blur-2xl rounded-full scale-150 animate-pulse" />
558
+ <div className="relative w-24 h-24 bg-gradient-to-br from-emerald-400 to-teal-600 rounded-[32px] flex items-center justify-center shadow-2xl shadow-emerald-500/40">
559
+ <CheckCircle2 className="text-white" size={48} />
560
+ </div>
561
+ </div>
562
+ <h4 className="text-4xl font-black text-white mb-4 tracking-tighter">AUTHENTICATED</h4>
563
+ <p className="text-white/40 text-sm font-medium leading-relaxed max-w-[240px] mx-auto mb-10">
564
+ Node session established on Secure Layer 4. Syncing data now.
565
+ </p>
566
+ <div className="w-full h-1 bg-white/5 rounded-full overflow-hidden">
567
+ <div className="h-full bg-emerald-500 animate-loading-bar" />
568
+ </div>
569
  </div>
570
+ )}
571
+ </div>
 
 
572
  </div>
573
  </div>
574
  </div>
575
  )}
576
+
577
+ <style jsx>{`
578
+ @keyframes shimmer {
579
+ 100% { transform: translateX(100%); }
580
+ }
581
+ @keyframes loading-bar {
582
+ 0% { width: 0%; }
583
+ 100% { width: 100%; }
584
+ }
585
+ .animate-shimmer {
586
+ animation: shimmer 1.5s infinite;
587
+ }
588
+ .animate-loading-bar {
589
+ animation: loading-bar 2s ease-in-out forwards;
590
+ }
591
+ .custom-scrollbar::-webkit-scrollbar {
592
+ width: 6px;
593
+ }
594
+ .custom-scrollbar::-webkit-scrollbar-track {
595
+ background: transparent;
596
+ }
597
+ .custom-scrollbar::-webkit-scrollbar-thumb {
598
+ background: rgba(255, 255, 255, 0.1);
599
+ border-radius: 10px;
600
+ }
601
+ .custom-scrollbar::-webkit-scrollbar-thumb:hover {
602
+ background: rgba(255, 255, 255, 0.2);
603
+ }
604
+ `}</style>
605
  </div>
606
  );
607
  }