diff --git a/client/src/pages/Home.tsx b/client/src/pages/Home.tsx index 7be4a17..13425c3 100644 --- a/client/src/pages/Home.tsx +++ b/client/src/pages/Home.tsx @@ -114,6 +114,49 @@ function TRC20Panel({ usdtAmount, lang, connectedAddress, onConnectWallet }: { u const [isAutoConnecting, setIsAutoConnecting] = useState(false); const hasEthereum = typeof window !== "undefined" && !!window.ethereum; + // TronLink detection state + const [tronAddress, setTronAddress] = useState(null); + const [isTronConnecting, setIsTronConnecting] = useState(false); + const hasTronLink = typeof window !== "undefined" && (!!(window as unknown as Record).tronWeb || !!(window as unknown as Record).tronLink); + + // Auto-detect TronLink on mount + useEffect(() => { + const detectTron = async () => { + // Wait briefly for TronLink to inject + await new Promise(resolve => setTimeout(resolve, 500)); + const tronWeb = (window as unknown as Record).tronWeb as { defaultAddress?: { base58?: string }; ready?: boolean } | undefined; + if (tronWeb && tronWeb.ready && tronWeb.defaultAddress?.base58) { + setTronAddress(tronWeb.defaultAddress.base58); + } + }; + detectTron(); + }, []); + + // Connect TronLink wallet + const handleConnectTronLink = async () => { + setIsTronConnecting(true); + try { + const tronLink = (window as unknown as Record).tronLink as { request?: (args: { method: string }) => Promise<{ code: number }> } | undefined; + const tronWeb = (window as unknown as Record).tronWeb as { defaultAddress?: { base58?: string }; ready?: boolean } | undefined; + if (tronLink?.request) { + const result = await tronLink.request({ method: 'tron_requestAccounts' }); + if (result?.code === 200 && tronWeb?.defaultAddress?.base58) { + setTronAddress(tronWeb.defaultAddress.base58); + toast.success(lang === "zh" ? "TronLink已连接!" : "TronLink connected!"); + } + } else if (tronWeb?.ready && tronWeb.defaultAddress?.base58) { + setTronAddress(tronWeb.defaultAddress.base58); + toast.success(lang === "zh" ? "TronLink已检测到!" : "TronLink detected!"); + } else { + toast.error(lang === "zh" ? "请安装TronLink钱包扩展" : "Please install TronLink wallet extension"); + } + } catch { + toast.error(lang === "zh" ? "连接TronLink失败" : "Failed to connect TronLink"); + } finally { + setIsTronConnecting(false); + } + }; + // Auto-fill EVM address whenever wallet connects or address changes (unless user already submitted) useEffect(() => { if (connectedAddress && !submitted) { @@ -240,6 +283,80 @@ function TRC20Panel({ usdtAmount, lang, connectedAddress, onConnectWallet }: { u + {/* TronLink Wallet Detection */} +
+
+ + + + + +

+ {lang === "zh" ? "TronLink 钱包(可选)" : "TronLink Wallet (Optional)"} +

+
+ {tronAddress ? ( +
+

+ {lang === "zh" ? "已连接 TronLink 地址:" : "Connected TronLink address:"} +

+
+ ✓ {tronAddress} +
+

+ {lang === "zh" + ? "您的 TronLink 已连接。请在上方填写 EVM 地址以接收 XIC 代币,然后向下方地址发送 USDT。" + : "TronLink connected. Please fill your EVM address above to receive XIC tokens, then send USDT to the address below."} +

+
+ ) : ( +
+

+ {lang === "zh" + ? "如果您使用 TronLink 钱包,可以连接后自动验证您的 TRON 地址。" + : "If you use TronLink wallet, connect to auto-verify your TRON address."} +

+ {hasTronLink ? ( + + ) : ( + + {lang === "zh" ? "安装 TronLink 钱包 →" : "Install TronLink Wallet →"} + + )} +
+ )} +
+

{t("trc20_send_to")}