ALIEZ há 1 mês atrás
pai
commit
833faf98c9
1 ficheiros alterados com 15 adições e 1 exclusões
  1. 15 1
      src/app/[locale]/account/withdraw-apply/page.tsx

+ 15 - 1
src/app/[locale]/account/withdraw-apply/page.tsx

@@ -1,7 +1,7 @@
 "use client";
 
 import { Link } from "@/i18n/navigation";
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
 import { ArrowLeft, Loader2, Wallet, CheckCircle2, AlertCircle } from "lucide-react";
 import { fetchWalletBalance } from "@/lib/account-api";
 import {
@@ -379,6 +379,8 @@ export default function WithdrawApplyPage() {
     }
   }
 
+  const prevChannelGroupCountRef = useRef(-1);
+
   const channelGroups = useMemo(() => {
     const groups: Record<string, WithdrawChannel[]> = {};
     for (const item of channels) {
@@ -389,6 +391,18 @@ export default function WithdrawApplyPage() {
     return Object.entries(groups).sort((a, b) => groupOrder(a[0]) - groupOrder(b[0]));
   }, [channels]);
 
+  useLayoutEffect(() => {
+    const len = channelGroups.length;
+    const prevLen = prevChannelGroupCountRef.current;
+    if (len === 1) {
+      const onlyLabel = channelGroups[0]![0];
+      if (prevLen !== 1) {
+        setExpandedGroup(onlyLabel);
+      }
+    }
+    prevChannelGroupCountRef.current = len;
+  }, [channelGroups]);
+
   // 高定表单样式
   const InputCls = "mt-2 w-full rounded-xl border border-white/10 bg-[#0a1120] px-4 py-3.5 text-sm text-white placeholder-slate-600 focus:border-[#b89458] focus:outline-none focus:ring-1 focus:ring-[#b89458] transition-all";