refactor(constants): 提取常量并优化国际化配置
- 创建API相关常量文件,包括响应码、HTTP状态码、请求头等 - 将认证相关常量从auth模块提取到独立的常量文件 - 在API客户端中使用新定义的常量替换硬编码值 - 更新认证API和服务中对常量的引用 - 在国际化配置中创建统一的文案常量以减少重复 - 将认证表单验证规则改为使用常量配置
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { FINANCE_API_ENDPOINTS } from '@/constants'
|
||||
import {
|
||||
API_SUCCESS_CODE,
|
||||
DEFAULT_LIST_PAGE_SIZE,
|
||||
FINANCE_API_ENDPOINTS,
|
||||
} from '@/constants'
|
||||
import { api } from '@/lib/api/api-client'
|
||||
import { ApiError } from '@/lib/api/api-error'
|
||||
import type { ApiResponse } from '@/type'
|
||||
@@ -30,7 +34,7 @@ function unwrapFinanceEnvelope<T>(
|
||||
response: ApiResponse<T>,
|
||||
fallbackMessage = 'Finance request failed',
|
||||
) {
|
||||
if (response.code === 1) {
|
||||
if (response.code === API_SUCCESS_CODE) {
|
||||
return response.data
|
||||
}
|
||||
|
||||
@@ -194,7 +198,7 @@ function normalizeFinanceOrderList(dto: FinanceOrderListDto): FinanceOrderList {
|
||||
list: (dto.list ?? []).map(normalizeFinanceOrderItem),
|
||||
pagination: {
|
||||
page: dto.pagination?.page ?? 1,
|
||||
page_size: dto.pagination?.page_size ?? 20,
|
||||
page_size: dto.pagination?.page_size ?? DEFAULT_LIST_PAGE_SIZE,
|
||||
total: dto.pagination?.total ?? 0,
|
||||
},
|
||||
}
|
||||
@@ -237,7 +241,8 @@ function normalizeWalletRecordList(dto: WalletRecordListDto): WalletRecordList {
|
||||
list: (dto.list ?? []).map(normalizeWalletRecordItem),
|
||||
pagination: {
|
||||
page: dto.pagination?.page ?? dto.page ?? 1,
|
||||
page_size: dto.pagination?.page_size ?? dto.page_size ?? 20,
|
||||
page_size:
|
||||
dto.pagination?.page_size ?? dto.page_size ?? DEFAULT_LIST_PAGE_SIZE,
|
||||
total: dto.pagination?.total ?? dto.total ?? 0,
|
||||
},
|
||||
}
|
||||
@@ -301,7 +306,7 @@ export async function getDepositOrderList(params?: {
|
||||
{
|
||||
searchParams: {
|
||||
page: String(params?.page ?? 1),
|
||||
page_size: String(params?.pageSize ?? 20),
|
||||
page_size: String(params?.pageSize ?? DEFAULT_LIST_PAGE_SIZE),
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -322,7 +327,7 @@ export async function getWithdrawOrderList(params?: {
|
||||
{
|
||||
searchParams: {
|
||||
page: String(params?.page ?? 1),
|
||||
page_size: String(params?.pageSize ?? 20),
|
||||
page_size: String(params?.pageSize ?? DEFAULT_LIST_PAGE_SIZE),
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -344,7 +349,7 @@ export async function getWalletRecordList(params?: {
|
||||
{
|
||||
searchParams: {
|
||||
page: String(params?.page ?? 1),
|
||||
page_size: String(params?.pageSize ?? 20),
|
||||
page_size: String(params?.pageSize ?? DEFAULT_LIST_PAGE_SIZE),
|
||||
type: params?.type ?? 'payout',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { GAME_API_ENDPOINTS } from '@/constants'
|
||||
import {
|
||||
API_SUCCESS_CODE,
|
||||
DEFAULT_LIST_PAGE_SIZE,
|
||||
GAME_API_ENDPOINTS,
|
||||
} from '@/constants'
|
||||
import { api } from '@/lib/api/api-client'
|
||||
import { ApiError } from '@/lib/api/api-error'
|
||||
import type { ApiResponse } from '@/type'
|
||||
@@ -51,7 +55,7 @@ function unwrapGameEnvelope<T>(
|
||||
response: ApiResponse<T>,
|
||||
fallbackMessage = 'Game request failed',
|
||||
) {
|
||||
if (response.code === 1) {
|
||||
if (response.code === API_SUCCESS_CODE) {
|
||||
return response.data
|
||||
}
|
||||
|
||||
@@ -424,7 +428,7 @@ export async function getNoticeList(params?: {
|
||||
const response = await api.get<NoticeListDto>(GAME_API_ENDPOINTS.noticeList, {
|
||||
searchParams: {
|
||||
page: String(params?.page ?? 1),
|
||||
page_size: String(params?.pageSize ?? 20),
|
||||
page_size: String(params?.pageSize ?? DEFAULT_LIST_PAGE_SIZE),
|
||||
},
|
||||
})
|
||||
const dto = unwrapGameEnvelope(
|
||||
@@ -478,7 +482,7 @@ export async function getGameBetMyOrders(params: {
|
||||
{
|
||||
json: {
|
||||
page: params.page ?? 1,
|
||||
page_size: params.pageSize ?? 20,
|
||||
page_size: params.pageSize ?? DEFAULT_LIST_PAGE_SIZE,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GAME_API_ENDPOINTS } from '@/constants'
|
||||
import { API_SUCCESS_CODE, GAME_API_ENDPOINTS } from '@/constants'
|
||||
import { api } from '@/lib/api/api-client'
|
||||
import { ApiError } from '@/lib/api/api-error'
|
||||
import type { ApiResponse } from '@/type'
|
||||
@@ -16,7 +16,7 @@ interface GamePeriodHistoryDto {
|
||||
function unwrapPeriodHistoryEnvelope(
|
||||
response: ApiResponse<GamePeriodHistoryDto>,
|
||||
) {
|
||||
if (response.code === 1) {
|
||||
if (response.code === API_SUCCESS_CODE) {
|
||||
return response.data
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { startTransition, useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { MOBILE_LAYOUT_BREAKPOINT_PX } from '@/constants'
|
||||
import { getGameLobbyInit } from '@/features/game'
|
||||
import { EntryNoticeGateModal } from '@/features/game/components'
|
||||
import { MobileEntry } from '@/features/game/entry/mobile-entry.tsx'
|
||||
@@ -74,7 +75,8 @@ export function EntryPage() {
|
||||
return false
|
||||
}
|
||||
|
||||
return window.matchMedia('(max-width: 768px)').matches
|
||||
return window.matchMedia(`(max-width: ${MOBILE_LAYOUT_BREAKPOINT_PX}px)`)
|
||||
.matches
|
||||
})
|
||||
|
||||
useDocumentMetadata({
|
||||
@@ -189,7 +191,9 @@ export function EntryPage() {
|
||||
return
|
||||
}
|
||||
|
||||
const mediaQuery = window.matchMedia('(max-width: 768px)')
|
||||
const mediaQuery = window.matchMedia(
|
||||
`(max-width: ${MOBILE_LAYOUT_BREAKPOINT_PX}px)`,
|
||||
)
|
||||
const syncLayout = (event?: MediaQueryListEvent) => {
|
||||
setIsMobile(event?.matches ?? mediaQuery.matches)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { DEFAULT_APP_LANGUAGE } from '@/constants'
|
||||
import {
|
||||
DEFAULT_APP_LANGUAGE,
|
||||
FINANCE_CONFIG_QUERY_STALE_TIME_MS,
|
||||
} from '@/constants'
|
||||
import { getDepositTierList } from '@/features/game/api'
|
||||
|
||||
export function useDepositTierList() {
|
||||
@@ -12,6 +15,6 @@ export function useDepositTierList() {
|
||||
return useQuery({
|
||||
queryKey: ['finance', 'deposit-tier-list', language],
|
||||
queryFn: () => getDepositTierList(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
staleTime: FINANCE_CONFIG_QUERY_STALE_TIME_MS,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { DEFAULT_APP_LANGUAGE } from '@/constants'
|
||||
import {
|
||||
DEFAULT_APP_LANGUAGE,
|
||||
FINANCE_CONFIG_QUERY_STALE_TIME_MS,
|
||||
} from '@/constants'
|
||||
import { getDepositWithdrawConfig } from '@/features/game/api'
|
||||
|
||||
export function useDepositWithdrawConfig() {
|
||||
@@ -12,6 +15,6 @@ export function useDepositWithdrawConfig() {
|
||||
return useQuery({
|
||||
queryKey: ['finance', 'deposit-withdraw-config', language],
|
||||
queryFn: () => getDepositWithdrawConfig(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
staleTime: FINANCE_CONFIG_QUERY_STALE_TIME_MS,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ import { useInfiniteQuery } from '@tanstack/react-query'
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { DEFAULT_LIST_PAGE_SIZE } from '@/constants'
|
||||
import { getDepositOrderList, getWithdrawOrderList } from '@/features/game/api'
|
||||
|
||||
export type FinanceRecordType = 'deposit' | 'withdraw'
|
||||
|
||||
const FINANCE_RECORD_PAGE_SIZE = 20
|
||||
|
||||
const FINANCE_RECORD_TYPE_OPTIONS: Array<{
|
||||
key: FinanceRecordType
|
||||
labelKey: string
|
||||
@@ -46,11 +45,11 @@ export function useFinanceRecordsVm({ enabled }: { enabled: boolean }) {
|
||||
recordType === 'deposit'
|
||||
? getDepositOrderList({
|
||||
page: pageParam,
|
||||
pageSize: FINANCE_RECORD_PAGE_SIZE,
|
||||
pageSize: DEFAULT_LIST_PAGE_SIZE,
|
||||
})
|
||||
: getWithdrawOrderList({
|
||||
page: pageParam,
|
||||
pageSize: FINANCE_RECORD_PAGE_SIZE,
|
||||
pageSize: DEFAULT_LIST_PAGE_SIZE,
|
||||
}),
|
||||
enabled,
|
||||
getNextPageParam: (lastPage) => {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import {
|
||||
CONNECTION_LATENCY_FAIR_MS,
|
||||
CONNECTION_LATENCY_GOOD_MS,
|
||||
CONNECTION_LATENCY_POOR_MS,
|
||||
} from '@/constants'
|
||||
import { useAppLanguage } from '@/features/game/hooks/use-app-language'
|
||||
import {
|
||||
isDesktopFullscreen,
|
||||
@@ -74,7 +79,7 @@ function resolveSignalPresentation(input: {
|
||||
} satisfies SignalPresentation
|
||||
}
|
||||
|
||||
if (input.latencyMs <= 80) {
|
||||
if (input.latencyMs <= CONNECTION_LATENCY_GOOD_MS) {
|
||||
return {
|
||||
activeBars: 4,
|
||||
latencyLabel: String(input.latencyMs),
|
||||
@@ -82,7 +87,7 @@ function resolveSignalPresentation(input: {
|
||||
} satisfies SignalPresentation
|
||||
}
|
||||
|
||||
if (input.latencyMs <= 150) {
|
||||
if (input.latencyMs <= CONNECTION_LATENCY_FAIR_MS) {
|
||||
return {
|
||||
activeBars: 3,
|
||||
latencyLabel: String(input.latencyMs),
|
||||
@@ -90,7 +95,7 @@ function resolveSignalPresentation(input: {
|
||||
} satisfies SignalPresentation
|
||||
}
|
||||
|
||||
if (input.latencyMs <= 300) {
|
||||
if (input.latencyMs <= CONNECTION_LATENCY_POOR_MS) {
|
||||
return {
|
||||
activeBars: 2,
|
||||
latencyLabel: String(input.latencyMs),
|
||||
|
||||
@@ -3,9 +3,9 @@ import dayjs from 'dayjs'
|
||||
import { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { DEFAULT_LIST_PAGE_SIZE } from '@/constants'
|
||||
import { getWalletRecordList } from '@/features/game/api'
|
||||
|
||||
const WALLET_RECORD_PAGE_SIZE = 20
|
||||
const WALLET_RECORD_TYPE = 'payout'
|
||||
|
||||
function formatWalletAmount(value: string, locale: string) {
|
||||
@@ -47,7 +47,7 @@ export function useWalletRecordsVm({ enabled }: { enabled: boolean }) {
|
||||
queryFn: ({ pageParam }) =>
|
||||
getWalletRecordList({
|
||||
page: pageParam,
|
||||
pageSize: WALLET_RECORD_PAGE_SIZE,
|
||||
pageSize: DEFAULT_LIST_PAGE_SIZE,
|
||||
type: WALLET_RECORD_TYPE,
|
||||
}),
|
||||
enabled,
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { DEFAULT_WITHDRAW_CONFIG, QUICK_FIAT_AMOUNTS } from '@/constants'
|
||||
import {
|
||||
DEFAULT_CURRENCY_CODE,
|
||||
DEFAULT_WITHDRAW_CONFIG,
|
||||
QUICK_FIAT_AMOUNTS,
|
||||
WITHDRAW_EMAIL_PATTERN,
|
||||
WITHDRAW_PHONE_PATTERN,
|
||||
} from '@/constants'
|
||||
import type { DepositWithdrawConfig } from '@/features/game/api'
|
||||
import { useDepositWithdrawConfig } from '@/features/game/hooks/use-deposit-withdraw-config'
|
||||
import { useAuthStore } from '@/store'
|
||||
@@ -47,7 +53,7 @@ function isValidEmail(value: string) {
|
||||
return false
|
||||
}
|
||||
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim())
|
||||
return WITHDRAW_EMAIL_PATTERN.test(value.trim())
|
||||
}
|
||||
|
||||
function isValidPhone(value: string) {
|
||||
@@ -57,7 +63,7 @@ function isValidPhone(value: string) {
|
||||
return false
|
||||
}
|
||||
|
||||
return /^\+?\d{6,20}$/.test(normalized)
|
||||
return WITHDRAW_PHONE_PATTERN.test(normalized)
|
||||
}
|
||||
|
||||
export function useWithdrawVm() {
|
||||
@@ -88,7 +94,7 @@ export function useWithdrawVm() {
|
||||
const [amount, setAmountState] = useState(0)
|
||||
const [hasInitializedAmount, setHasInitializedAmount] = useState(false)
|
||||
const [currencyCode, setCurrencyCode] = useState(
|
||||
config.currencies[0]?.code ?? 'MYR',
|
||||
config.currencies[0]?.code ?? DEFAULT_CURRENCY_CODE,
|
||||
)
|
||||
const [paymentChannelCode, setPaymentChannelCode] = useState('')
|
||||
const [bankCode, setBankCode] = useState('')
|
||||
@@ -207,7 +213,7 @@ export function useWithdrawVm() {
|
||||
}, [locale, maxWithdrawAmount, selectedCurrency.code, selectedRate])
|
||||
|
||||
const resetForm = useCallback(() => {
|
||||
const nextCurrencyCode = config.currencies[0]?.code ?? 'MYR'
|
||||
const nextCurrencyCode = config.currencies[0]?.code ?? DEFAULT_CURRENCY_CODE
|
||||
const nextCurrency = getActiveCurrencyCode(
|
||||
config.currencies,
|
||||
nextCurrencyCode,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { CenterModal } from '@/components/center-modal.tsx'
|
||||
import { SmartBackground } from '@/components/smart-background.tsx'
|
||||
import { Input } from '@/components/ui/input.tsx'
|
||||
import { Switch } from '@/components/ui/switch.tsx'
|
||||
import { AUTO_HOSTING_DEFAULT_SINGLE_WIN_THRESHOLD } from '@/constants'
|
||||
import { notify } from '@/lib/notify'
|
||||
import { useModalStore } from '@/store'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
@@ -51,7 +52,9 @@ function DesktopAutoSettingModal() {
|
||||
const [balanceLimitEnabled, setBalanceLimitEnabled] = useState(false)
|
||||
const [balanceLimitValue, setBalanceLimitValue] = useState('0')
|
||||
const [singleWinLimitEnabled, setSingleWinLimitEnabled] = useState(false)
|
||||
const [singleWinLimitValue, setSingleWinLimitValue] = useState('50000')
|
||||
const [singleWinLimitValue, setSingleWinLimitValue] = useState(
|
||||
String(AUTO_HOSTING_DEFAULT_SINGLE_WIN_THRESHOLD),
|
||||
)
|
||||
const [jackpotStopEnabled, setJackpotStopEnabled] = useState(false)
|
||||
|
||||
function handleClose() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import userInfoBg from '@/assets/system/userInfo-bg.webp'
|
||||
import { CenterModal } from '@/components/center-modal.tsx'
|
||||
import { SmartBackground } from '@/components/smart-background.tsx'
|
||||
import { SmartImage } from '@/components/smart-image.tsx'
|
||||
import { REGISTER_INVITE_CODE_QUERY_PARAM } from '@/constants'
|
||||
import { logoutWithPassword } from '@/features/auth/api/auth-api'
|
||||
import DesktopFinanceRecordsTab from '@/features/game/modal/desktop/desktop-finance-records-tab'
|
||||
import DesktopWalletRecordsTab from '@/features/game/modal/desktop/desktop-wallet-records-tab'
|
||||
@@ -47,8 +48,6 @@ const USER_INFO_TABS: Array<{
|
||||
},
|
||||
]
|
||||
|
||||
const REGISTER_INVITE_CODE_QUERY_PARAM = 'registerInviteCode'
|
||||
|
||||
function createRegisterInviteUrl(inviteCode: string) {
|
||||
const url = new URL(window.location.href)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user