feat: 增强钱包 API 与玩家会话管理

- 新增钱包 API 函数:getWalletLogs(获取钱包日志)、postWalletTransferIn(充值)及 postWalletTransferOut(提现)
- 更新钱包相关类型定义,提升类型安全性
- 改进玩家会话管理:若当前无玩家资料,则自动拉取玩家信息
- 增强入口网关对过期会话的错误处理能力
- 更新 UI 组件,以适配新的结构与功能
This commit is contained in:
2026-05-09 15:22:08 +08:00
parent 14c297fe1a
commit 7743c14e83
28 changed files with 1719 additions and 33 deletions

View File

@@ -0,0 +1,154 @@
"use client";
import { ArrowDownLeft, ArrowUpRight } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {
TransferInPanel,
TransferOutPanel,
} from "@/features/wallet/wallet-transfer-forms";
import { cn } from "@/lib/utils";
type BaseProps = {
currency: string;
onSuccess: () => Promise<void>;
/** 避免同页多实例 input id 冲突 */
idPrefix?: string;
};
const defaultInTrigger =
"!bg-[#52c41a] !text-white shadow-none hover:!bg-[#52c41a]/90";
const defaultOutTrigger = "flex-1";
/** 高保真稿:蓝底白字 */
const hallInTrigger =
"rounded-lg border-0 !bg-[#1677ff] !text-white shadow-sm hover:!bg-[#1677ff]/90";
/** 高保真稿:白底红框红字 */
const hallOutTrigger =
"rounded-lg !border-2 !border-[#ff4d4f] !bg-white !text-[#ff4d4f] shadow-sm hover:!bg-red-50 dark:!bg-card dark:hover:!bg-red-950/30";
export function TransferInDialog({
currency,
lotteryMinor,
onSuccess,
idPrefix = "",
triggerClassName,
triggerVariant = "wallet",
triggerLabel = "转入",
}: BaseProps & {
lotteryMinor: number;
triggerClassName?: string;
triggerVariant?: "wallet" | "hall";
triggerLabel?: string;
}) {
const [open, setOpen] = useState(false);
const triggerCombined = cn(
"inline-flex h-10 min-h-10 w-full min-w-0 flex-1 items-center justify-center gap-1.5 px-3 text-sm font-medium",
triggerVariant === "hall" ? hallInTrigger : defaultInTrigger,
triggerClassName,
);
return (
<Dialog open={open} onOpenChange={setOpen}>
<Button
type="button"
variant="ghost"
className={triggerCombined}
onClick={() => setOpen(true)}
>
<ArrowDownLeft className="size-4 shrink-0" />
{triggerLabel}
</Button>
<DialogContent showCloseButton>
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
1.00{" "}
{currency}
</DialogDescription>
</DialogHeader>
<TransferInPanel
variant="dialog"
currency={currency}
lotteryMinor={lotteryMinor}
idPrefix={idPrefix}
onCancel={() => setOpen(false)}
onSuccess={async () => {
await onSuccess();
setOpen(false);
}}
/>
</DialogContent>
</Dialog>
);
}
export function TransferOutDialog({
currency,
availableMinor,
onSuccess,
idPrefix = "",
triggerClassName,
triggerVariant = "wallet",
triggerLabel = "转出",
}: BaseProps & {
availableMinor: number;
triggerClassName?: string;
triggerVariant?: "wallet" | "hall";
triggerLabel?: string;
}) {
const [open, setOpen] = useState(false);
const triggerCombined = cn(
"inline-flex h-10 min-h-10 w-full min-w-0 flex-1 items-center justify-center gap-1.5 px-3 text-sm font-medium",
triggerVariant === "hall"
? hallOutTrigger
: cn(
"!border-2 !border-input !bg-secondary !text-secondary-foreground hover:!bg-secondary/80",
defaultOutTrigger,
),
triggerClassName,
);
return (
<Dialog open={open} onOpenChange={setOpen}>
<Button
type="button"
variant="ghost"
className={triggerCombined}
onClick={() => setOpen(true)}
>
<ArrowUpRight className="size-4 shrink-0" />
{triggerLabel}
</Button>
<DialogContent showCloseButton>
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
</DialogDescription>
</DialogHeader>
<TransferOutPanel
variant="dialog"
currency={currency}
availableMinor={availableMinor}
idPrefix={idPrefix}
onCancel={() => setOpen(false)}
onSuccess={async () => {
await onSuccess();
setOpen(false);
}}
/>
</DialogContent>
</Dialog>
);
}