'use client'; import { useState, useEffect, useRef } from 'react'; import Image from 'next/image'; // 数字增长动画Hook function useCountUp(end: number, duration: number = 1500, startRangePercent: number = 0.75) { const [mounted, setMounted] = useState(false); const [count, setCount] = useState(end); const [hasAnimated, setHasAnimated] = useState(false); const elementRef = useRef(null); const startValueRef = useRef(end); useEffect(() => { setMounted(true); startValueRef.current = Math.floor(end * (startRangePercent + Math.random() * 0.15)); setCount(startValueRef.current); }, [end, startRangePercent]); useEffect(() => { if (!mounted) return; const observer = new IntersectionObserver( (entries) => { if (entries[0].isIntersecting && !hasAnimated) { setHasAnimated(true); const start = startValueRef.current; const startTime = Date.now(); const timer = setInterval(() => { const elapsed = Date.now() - startTime; const progress = Math.min(elapsed / duration, 1); const easeOutCubic = 1 - Math.pow(1 - progress, 3); const currentCount = Math.floor(start + (end - start) * easeOutCubic); setCount(currentCount); if (progress === 1) { setCount(end); clearInterval(timer); } }, 16); return () => clearInterval(timer); } }, { threshold: 0.1 } ); if (elementRef.current) { observer.observe(elementRef.current); } return () => observer.disconnect(); }, [end, duration, hasAnimated, mounted]); return { count, elementRef }; } export default function HowItWorksSection() { const [mounted, setMounted] = useState(false); const [visible, setVisible] = useState(false); const [activeStep, setActiveStep] = useState(1); // 默认第1步激活 const sectionRef = useRef(null); // 数字动画 const investAmount = useCountUp(100000, 1500, 0.85); const earnAmount = useCountUp(5150, 1500, 0.85); useEffect(() => { setMounted(true); const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting && !visible) { setVisible(true); } }); }, { threshold: 0.1, } ); if (sectionRef.current) { observer.observe(sectionRef.current); } return () => { if (sectionRef.current) { observer.unobserve(sectionRef.current); } }; }, [visible]); const steps = [ { number: 1, title: 'Deposit & Mint WUSD', description: 'Connect your wallet and deposit USDC to swap WUSD. This serves as the native stablecoin and gateway to the entire AssetX ecosystem.', hasLine: true }, { number: 2, title: 'Dual Investment Options', description: 'Choose your strategy: use WUSD to purchase specific Yield-Bearing Assets for real-world returns, or provide liquidity in DeFi Pools to earn trading fees.', hasLine: true }, { number: 3, title: 'Earn & Boost', description: 'Receive daily yield distributions. Use Asset Tokens as collateral to borrow WUSD and leverage up to 2.5x for maximized returns.', hasLine: false } ]; return (
{/* .container20 - Main container */}
{/* Left Side - Steps (.container21) */}
{/* Title (.heading-2) */}

How it works

{/* Steps Container (.frame-34) */}
{steps.map((step, index) => { const isActive = activeStep === step.number; return (
setActiveStep(step.number)} className={`flex flex-row gap-6 items-start justify-start flex-shrink-0 relative cursor-pointer transition-all duration-300 ease-out hover:opacity-80 ${ mounted && visible ? 'translate-x-0 opacity-100' : '-translate-x-12 opacity-0' }`} style={{ transitionDelay: `${index * 150}ms` }} > {/* Number and Line Container */}
{/* Number Badge */} {isActive ? ( // Active step (black background)
{step.number}
) : ( // Inactive step (border)
{step.number}
)} {/* Connecting Line */} {step.hasLine && (
)}
{/* Text Content */}

{step.title}

{step.description}

); })}
{/* Right Side - Calculator Card */}
{/* Coin Images Container - Rotated Card */}
{/* USDC Logo */} USDC {/* WUSD Logo */}
WUSD
{/* Calculator Card */}
{/* Header */}
Portfolio
Portfolio Overview Simulator
+5.2% APY
{/* Investment Amount */}
If you invest ${investAmount.count.toLocaleString()}
{/* Range Slider */}
{/* Earnings */}
You earn per year
Earn +${earnAmount.count.toLocaleString()}
); }