Checkpoint: Fix: useWallet hook now auto-detects already-connected EVM wallets on page load using eth_accounts (silent, no popup). When user has MetaMask connected, the EVM address is automatically populated in the TRC20 panel. Also added isConnected: true to accountsChanged handler.
This commit is contained in:
parent
40be4636e9
commit
133aaedb68
|
|
@ -87,6 +87,36 @@ export function useWallet() {
|
|||
}
|
||||
}, []);
|
||||
|
||||
// Auto-detect already-connected wallet on page load (silent, no popup)
|
||||
useEffect(() => {
|
||||
const autoDetect = async () => {
|
||||
if (!window.ethereum) return;
|
||||
try {
|
||||
const provider = new BrowserProvider(window.ethereum as Eip1193Provider);
|
||||
// Use eth_accounts (not eth_requestAccounts) — silent, no popup
|
||||
const accounts = await provider.send("eth_accounts", []);
|
||||
if (accounts && accounts.length > 0) {
|
||||
const network = await provider.getNetwork();
|
||||
const signer = await provider.getSigner();
|
||||
const address = accounts[0] as string;
|
||||
setState({
|
||||
address,
|
||||
shortAddress: shortenAddress(address),
|
||||
isConnected: true,
|
||||
chainId: Number(network.chainId),
|
||||
provider,
|
||||
signer,
|
||||
isConnecting: false,
|
||||
error: null,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// Silently ignore — user hasn't connected yet
|
||||
}
|
||||
};
|
||||
autoDetect();
|
||||
}, []);
|
||||
|
||||
// Listen for account/chain changes
|
||||
useEffect(() => {
|
||||
if (!window.ethereum) return;
|
||||
|
|
@ -99,6 +129,7 @@ export function useWallet() {
|
|||
...s,
|
||||
address: accs[0],
|
||||
shortAddress: shortenAddress(accs[0]),
|
||||
isConnected: true,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -104,11 +104,18 @@ function StepBadge({ num, text }: { num: number; text: string }) {
|
|||
}
|
||||
|
||||
// ─── TRC20 Purchase Panel ─────────────────────────────────────────────────────
|
||||
function TRC20Panel({ usdtAmount, lang }: { usdtAmount: number; lang: Lang }) {
|
||||
function TRC20Panel({ usdtAmount, lang, connectedAddress }: { usdtAmount: number; lang: Lang; connectedAddress?: string }) {
|
||||
const { t } = useTranslation(lang);
|
||||
const tokenAmount = usdtAmount / PRESALE_CONFIG.tokenPrice;
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [evmAddress, setEvmAddress] = useState("");
|
||||
const [evmAddress, setEvmAddress] = useState(connectedAddress || "");
|
||||
|
||||
// Auto-fill EVM address when wallet connects
|
||||
useEffect(() => {
|
||||
if (connectedAddress && !evmAddress) {
|
||||
setEvmAddress(connectedAddress);
|
||||
}
|
||||
}, [connectedAddress]);
|
||||
const [evmAddrError, setEvmAddrError] = useState("");
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
|
||||
|
|
@ -1017,7 +1024,7 @@ export default function Home() {
|
|||
))}
|
||||
</div>
|
||||
</div>
|
||||
<TRC20Panel usdtAmount={parseFloat(trcUsdtAmount) || 0} lang={lang} />
|
||||
<TRC20Panel usdtAmount={parseFloat(trcUsdtAmount) || 0} lang={lang} connectedAddress={wallet.address || undefined} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
10
todo.md
10
todo.md
|
|
@ -38,6 +38,16 @@
|
|||
- [ ] 完整域名浏览器购买测试(pre-sale.newassetchain.io)
|
||||
- [ ] 部署到备份服务器并同步代码库
|
||||
|
||||
## v5 备份服务器部署
|
||||
- [x] 修复TRON面板EVM地址自动识别(已连接钱包地址预填入)
|
||||
- [ ] 构建生产版本(移除Manus内联)
|
||||
- [ ] 打包并上传到备份服务器 103.96.148.7
|
||||
- [ ] 备份服务器环境配置(Node.js 22、PM2、MySQL、Nginx)
|
||||
- [ ] 配置环境变量(DATABASE_URL、JWT_SECRET等)
|
||||
- [ ] 启动服务并验证运行状态
|
||||
- [ ] 同步代码到Gitea库(nacadmin/xic-presale)
|
||||
- [ ] 记录部署日志
|
||||
|
||||
## v5 钱包连接修复
|
||||
- [x] 将useWallet()提升到Home顶层,通过props传递给NavWalletButton和EVMPurchasePanel
|
||||
- [x] 验证导航栏和购买面板钱包状态同步
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ function vitePluginManusDebugCollector(): Plugin {
|
|||
};
|
||||
}
|
||||
|
||||
const plugins = [react(), tailwindcss(), jsxLocPlugin(), vitePluginManusRuntime(), vitePluginManusDebugCollector()];
|
||||
const plugins = [react(), tailwindcss(), jsxLocPlugin()];
|
||||
|
||||
export default defineConfig({
|
||||
plugins,
|
||||
|
|
|
|||
Loading…
Reference in New Issue