import { useEffect, useMemo, useRef, useState } from 'react' import { ArrowRight, Copy, RefreshCw, Shield, Wallet, } from 'lucide-react' import { QRCodeSVG } from 'qrcode.react' import { toast } from 'sonner' import { useLanguage } from '../contexts/LanguageContext' import { api } from '../lib/api' import type { BeginnerOnboardingResponse } from '../types' import { setBeginnerWalletAddress } from '../lib/onboarding' export function BeginnerOnboardingPage() { const { language } = useLanguage() const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState('') const [refreshingBalance, setRefreshingBalance] = useState(false) const hasRequestedRef = useRef(false) const isZh = language === 'zh' const loadOnboarding = async (showLoading: boolean) => { if (showLoading) { setLoading(true) } else { setRefreshingBalance(true) } setError('') try { const result = await api.prepareBeginnerOnboarding() setData(result) setBeginnerWalletAddress(result.address) } catch (err) { setError( err instanceof Error ? err.message : isZh ? '新手钱包准备失败' : 'Failed to prepare beginner wallet' ) } finally { if (showLoading) { setLoading(false) } else { setRefreshingBalance(false) } } } useEffect(() => { if (hasRequestedRef.current) { return } hasRequestedRef.current = true void loadOnboarding(true) }, []) const noticeText = useMemo( () => isZh ? '此钱包仅用于大模型调用费用,不会自动充到交易所。私钥丢失后无法恢复,只充 Base 链 USDC。' : 'This wallet only pays for model calls. It does not fund your exchange automatically. The private key cannot be recovered, and you should only deposit Base USDC.', [isZh] ) const copyText = async (value: string, label: string) => { try { await navigator.clipboard.writeText(value) toast.success(isZh ? `${label}已复制` : `${label} copied`) } catch { toast.error(isZh ? '复制失败' : 'Copy failed') } } const handleContinue = () => { window.history.pushState({}, '', '/traders') window.dispatchEvent(new PopStateEvent('popstate')) } return (
{isZh ? '新手保护' : 'Beginner Guard'}

{isZh ? '钱包已经帮你准备好了' : 'Your wallet is ready'}

Claw402 + DeepSeek · {isZh ? '按次付费' : 'Pay per call'}
{loading ? (
{isZh ? '正在准备你的 Base 钱包...' : 'Preparing your Base wallet...'}
) : data ? (
{isZh ? '充值地址(Base USDC)' : 'Deposit address (Base USDC)'}
{data.balance_usdc} USDC
{isZh ? '$5-$10 可以用很久' : '$5-$10 usually lasts a long time'}
{isZh ? '钱包地址' : 'Wallet address'}
{data.address}
{isZh ? '私钥,请立即备份' : 'Private key, back it up now'}
{data.private_key}
{noticeText}
{data.env_warning ? (
{data.env_warning}
) : null} {error ? (
{error}
) : null} {data.env_saved ? (
{isZh ? `钱包信息已同步保存到 ${data.env_path || '.env'}` : `Wallet details were also saved to ${data.env_path || '.env'}`}
) : null}
) : null}
) }