From 809b6327b8afbc53a677d95882d081ab6d47071b Mon Sep 17 00:00:00 2001 From: Manus Date: Sun, 8 Mar 2026 19:23:48 -0400 Subject: [PATCH] =?UTF-8?q?Checkpoint:=20v6:=20=E6=B7=BB=E5=8A=A0=20TronLi?= =?UTF-8?q?nk=20=E9=92=B1=E5=8C=85=E6=A3=80=E6=B5=8B=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=88TRON=20=E6=A0=87=E7=AD=BE=E6=98=BE=E7=A4=BA=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=8C=89=E9=92=AE/=E5=AE=89=E8=A3=85=E5=BC=95?= =?UTF-8?q?=E5=AF=BC=EF=BC=89=EF=BC=8C=E7=A1=AE=E8=AE=A4=20BSC/ETH/XIC=20?= =?UTF-8?q?=E5=90=88=E7=BA=A6=E5=9C=B0=E5=9D=80=E6=AD=A3=E7=A1=AE=EF=BC=8C?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=B9=B6=E9=83=A8=E7=BD=B2=E5=88=B0=20pre-sa?= =?UTF-8?q?le.newassetchain.io?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/pages/Home.tsx | 117 ++++++++++++++++++++++++++++++++++++++ todo.md | 7 +++ 2 files changed, 124 insertions(+) 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")}