import { useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { WorldGeo } from "./components/world-geo"; import Web3BoxPng from "@/assets/image/home/web3-box.png"; import Web3Box2Png from "@/assets/image/home/web3-box2.png"; import web3BoxGif from "@/assets/gif/web3-box-bg.gif"; import VectorSlideSvg from "@/assets/svg/home/vector-solide.svg?react"; import { Apps, CONST_TOOLTIP_TYPE } from "@/pages/anti-forensics-forwarding"; import { cn } from "@/lib/utils"; import { commands } from "@/bindings"; import type { AppDispatch, RootState } from "@/store"; import "./index.scss"; import { getPassAuthentication, getTrafficObfuscation, getNestedEncryption, getDynamicRouteGeneration, getApplicationDiversion, } from "@/api/flying-line"; import { errorToast } from "@/components/GlobalToast"; import { toast } from "@/components/ui/use-toast"; import { disableProxy, enableProxy } from "@/store/serviceSlice"; export const DIALOGTYPE = { ADDNode: { title: "添加节点", desc: "", successText: "添加", }, AddNetwork: { title: "构建网络", desc: "", successText: "构建", }, }; export const NODEDIALOGTYPE = { ClearFailNode: { title: "清除掉线节点", desc: "", successText: "清除", }, ClearWargingNode: { title: "恶意节点", desc: "", successText: "清除", }, }; const NewHome = () => { const dispatch = useDispatch(); const { web3List, web3List2 } = useSelector( (state: RootState) => state.web3Reducer ); const { isProxyEnabled, isCoreRunning } = useSelector( (state: RootState) => state.serviceReducer ); const [isProxyLoading, setIsProxyLoading] = useState(false); const [selectedApp, setSelectedApp] = useState(null); const [tooltipClosed, setTooltipClosed] = useState(true); const [tooltipType, setTooltipType] = useState( CONST_TOOLTIP_TYPE.NESTED_ENCRYPTION.type ); // 模拟日志数据 const [nestedEncryptionLogs, setNestedEncryptionLogs] = useState( [] ); const [trafficObfuscationLogs, setTrafficObfuscationLogs] = useState< string[] >([]); const newWeb3List = useMemo(() => { // 展示最新的6个节点 return web3List.slice(-6); }, [web3List]); const handleClickApp = (item: any) => { setSelectedApp(item); }; const [dataInfo, setDataInfo] = useState({ passAuthentication: { type: "PASS_AUTHENTICATION", name: "通信认证", startPoint: "GL", endPoint: "CA", authenticationPoint: [ [-103.346771, 54.130366], [-120.346771, 52.130366], [-108.346771, 48.130366], [-98.346771, 46.130366], [-106.346771, 48.450366], [-101.346771, 53.130366], [-123.346771, 58.130366], [-111.346771, 65.443366], [-108.346771, 54.130366], [-116.346771, 59.130366], [-97.346771, 61.130366], [-95.346771, 63.130366], [-113.346771, 58.840366], [-99.346771, 59.130366], [-102.346771, 68.130366], ], data: [ { country_code: "gl", ingress_country_code: "dz", }, { country_code: "br", ingress_country_code: "dz", }, { country_code: "dz", ingress_country_code: "ru", }, { country_code: "dz", ingress_country_code: "cn", }, { country_code: "ru", ingress_country_code: "za", }, ], isLine: true, }, trafficObfuscation: [], nestedEncryption: [], dynamicRouteGeneration: [], applicationDiversion: [], }); const appDiversion = useMemo(() => { return Apps.map((item) => { const findApp = dataInfo.applicationDiversion.find( (appItem: any) => item.name === appItem.name ); return { ...item, ...findApp, }; }); }, [dataInfo.applicationDiversion]); // 处理代理开关 const handleProxyToggle = useCallback( async (isProxyEnabled: boolean, isCoreRunning: boolean) => { // console.log(isProxyLoading, "isProxyLoadingisProxyLoading"); if (isProxyLoading) return; try { // 如果核心未运行,先启动核心 if (!isCoreRunning) { await commands.startCore(); } setIsProxyLoading(true); // 切换代理状态 await dispatch(isProxyEnabled ? disableProxy() : enableProxy()).unwrap(); setIsProxyLoading(false); console.log(`Proxy ${isProxyEnabled ? "关闭成功" : "开启成功"}`); } catch (error) { const errorMessage = isProxyEnabled ? "关闭代理失败!" : "开启代理失败,请检查节点配置、或重新尝试开启"; errorToast(errorMessage, toast); console.error("Proxy toggle failed:", error); } finally { setIsProxyLoading(false); } }, [dispatch, isProxyLoading, isCoreRunning, isProxyEnabled] ); const initData = async () => { const passAuthentication = await getPassAuthentication(); const trafficObfuscation = await getTrafficObfuscation(); const nestedEncryption = await getNestedEncryption(); const applicationDiversion = await getApplicationDiversion(); const dynamicRouteGeneration = await getDynamicRouteGeneration(); setNestedEncryptionLogs(nestedEncryption.logs); setTrafficObfuscationLogs(trafficObfuscation.logs); setDataInfo({ passAuthentication: passAuthentication.data, trafficObfuscation: [trafficObfuscation.data], nestedEncryption: [nestedEncryption.data], applicationDiversion: applicationDiversion.data, dynamicRouteGeneration: dynamicRouteGeneration.data, }); }; useEffect(() => { initData(); }, []); // useEffect(() => { // console.log(dataInfo, "awaidataInfodataInfotawait"); // }, [dataInfo]); return (
{/* */} {/*
*/}
{newWeb3List.map((item, index) => { // 随机0-10的整数 const randomDelay = Math.floor(Math.random() * 35) * 1; return (
{/*
*/}
{/*
{item.transactions}
*/} {/*
{item?.balanceToFixed} SOL
*/}
#{item.height}
{item.timerstamp}
{item.txs.length}次记录
); })}
{web3List2.map((item, index) => { const randomDelay = Math.floor(Math.random() * 35) * 1; return (
#{item.height}
{item.timerstamp}
{item.numberTransactions}次记录
); })}
{ handleProxyToggle(isProxyEnabled, isCoreRunning); }} > {isProxyEnabled ? "关闭匿名服务" : "开启匿名服务"}
{/*
{ setTooltipType( CONST_TOOLTIP_TYPE.NESTED_ENCRYPTION.type ); setTooltipClosed(true); }} > 嵌套加密
{ setTooltipType( CONST_TOOLTIP_TYPE.TRAFFIC_OBFUSCATION.type ); setTooltipClosed(true); }} > 流量混淆
*/} {appDiversion.map((item) => { return (
handleClickApp(item)} > {selectedApp?.name === item?.name ? ( ) : ( )}
); })}
); }; export default NewHome;