feat: 接入公开币种目录并统一多币种金额与语言初始化处理

This commit is contained in:
2026-05-21 15:14:00 +08:00
parent 626914feb6
commit 6b18e25766
27 changed files with 277 additions and 94 deletions

View File

@@ -6,6 +6,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import { getWalletBalance } from "@/api/wallet";
import { TransferInPage } from "@/features/wallet/wallet-transfer-forms";
import { Skeleton } from "@/components/ui/skeleton";
import { resolvePlayerCurrency } from "@/lib/player-currency";
import { usePlayerSessionStore } from "@/stores/player-session-store";
import type { WalletBalanceData } from "@/types/api/wallet-balance";
@@ -17,9 +18,8 @@ export function TransferInScreen() {
const [loading, setLoading] = useState(true);
const currency = useMemo(
() =>
(balance?.currency_code ?? profile?.default_currency ?? "NPR").toUpperCase(),
[balance?.currency_code, profile?.default_currency],
() => resolvePlayerCurrency(profile, balance),
[balance, profile],
);
const load = useCallback(async () => {

View File

@@ -6,6 +6,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import { getWalletBalance } from "@/api/wallet";
import { TransferOutPage } from "@/features/wallet/wallet-transfer-forms";
import { Skeleton } from "@/components/ui/skeleton";
import { resolvePlayerCurrency } from "@/lib/player-currency";
import { usePlayerSessionStore } from "@/stores/player-session-store";
import type { WalletBalanceData } from "@/types/api/wallet-balance";
@@ -17,9 +18,8 @@ export function TransferOutScreen() {
const [loading, setLoading] = useState(true);
const currency = useMemo(
() =>
(balance?.currency_code ?? profile?.default_currency ?? "NPR").toUpperCase(),
[balance?.currency_code, profile?.default_currency],
() => resolvePlayerCurrency(profile, balance),
[balance, profile],
);
const load = useCallback(async () => {

View File

@@ -7,6 +7,7 @@ import { getWalletLogs } from "@/api/wallet";
import { Button } from "@/components/ui/button";
import { PlayerPanel } from "@/components/layout/player-panel";
import { WalletLogsBlock } from "@/features/wallet/wallet-logs-block";
import { resolvePlayerCurrency } from "@/lib/player-currency";
import { formatWalletClientError } from "@/lib/wallet-api-error";
import { usePlayerSessionStore } from "@/stores/player-session-store";
import { getWalletLogsLastPage, type WalletLogsData } from "@/types/api/wallet-logs";
@@ -25,8 +26,8 @@ export function WalletLogsScreen() {
const loadMoreRef = useRef<HTMLDivElement | null>(null);
const currency = useMemo(
() => (profile?.default_currency ?? "NPR").toUpperCase(),
[profile?.default_currency],
() => resolvePlayerCurrency(profile),
[profile],
);
const fetchPassRef = useRef(true);

View File

@@ -15,6 +15,7 @@ import {
} from "@/features/wallet/wallet-transfer-dialogs";
import { WalletLogsBlock } from "@/features/wallet/wallet-logs-block";
import { formatMinorAsCurrency } from "@/lib/money";
import { resolvePlayerCurrency } from "@/lib/player-currency";
import { formatWalletClientError } from "@/lib/wallet-api-error";
import { usePlayerSessionStore } from "@/stores/player-session-store";
import type { WalletBalanceData } from "@/types/api/wallet-balance";
@@ -34,13 +35,10 @@ export function WalletScreen() {
const [error, setError] = useState<string | null>(null);
const loadMoreRef = useRef<HTMLDivElement | null>(null);
const currency = useMemo(() => {
return (
balance?.currency_code ??
profile?.default_currency ??
"NPR"
).toUpperCase();
}, [balance?.currency_code, profile?.default_currency]);
const currency = useMemo(
() => resolvePlayerCurrency(profile, balance),
[balance, profile],
);
const fetchPassRef = useRef(true);

View File

@@ -18,7 +18,12 @@ import {
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { PlayerPanel } from "@/components/layout/player-panel";
import { formatMinorAsCurrency, parseDecimalInputToMinor } from "@/lib/money";
import {
formatMinorAsCurrency,
getCurrencyDecimalPlaces,
parseDecimalInputToMinor,
} from "@/lib/money";
import { useCurrencyCatalog } from "@/hooks/use-currency-catalog";
import { formatWalletClientError } from "@/lib/wallet-api-error";
import { LotteryApiBizError } from "@/types/api/errors";
@@ -64,14 +69,15 @@ export function TransferInPanel({
variant?: PanelVariant;
}) {
const { t } = useTranslation("player");
useCurrencyCatalog();
const [amountText, setAmountText] = useState("");
const [submitting, setSubmitting] = useState(false);
const [localError, setLocalError] = useState<string | null>(null);
const tid = `${idPrefix}in-amount`;
const parsedMinor = useMemo(
() => parseDecimalInputToMinor(amountText),
[amountText],
() => parseDecimalInputToMinor(amountText, currency),
[amountText, currency],
);
const previewAfter =
parsedMinor != null ? lotteryMinor + parsedMinor : lotteryMinor;
@@ -204,14 +210,15 @@ export function TransferOutPanel({
variant?: PanelVariant;
}) {
const { t } = useTranslation("player");
useCurrencyCatalog();
const [amountText, setAmountText] = useState("");
const [submitting, setSubmitting] = useState(false);
const [localError, setLocalError] = useState<string | null>(null);
const tid = `${idPrefix}out-amount`;
const parsedMinor = useMemo(
() => parseDecimalInputToMinor(amountText),
[amountText],
() => parseDecimalInputToMinor(amountText, currency),
[amountText, currency],
);
const previewAfter =
parsedMinor != null
@@ -219,8 +226,9 @@ export function TransferOutPanel({
: availableMinor;
const fillAll = () => {
const major = availableMinor / 100;
setAmountText(major.toFixed(2));
const decimals = getCurrencyDecimalPlaces(currency);
const major = availableMinor / 10 ** decimals;
setAmountText(major.toFixed(decimals));
};
const submit = async () => {