fix: 修改充值提现配置和充值接口
This commit is contained in:
@@ -3,7 +3,9 @@ import { useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { createDeposit } from '@/api'
|
||||
import { DataLoadingIndicator } from '@/components/ui/data-loading-indicator'
|
||||
import { DEFAULT_WITHDRAW_CONFIG } from '@/constants'
|
||||
import { useDepositTierList } from '@/hooks/use-deposit-tier-list'
|
||||
import { useDepositWithdrawConfig } from '@/hooks/use-deposit-withdraw-config'
|
||||
import { notify } from '@/lib/notify'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { DepositTierItem } from '@/type'
|
||||
@@ -17,21 +19,39 @@ function formatNumber(value: number) {
|
||||
|
||||
function MobileTopup() {
|
||||
const { t } = useTranslation()
|
||||
const depositWithdrawConfigQuery = useDepositWithdrawConfig()
|
||||
const tierListQuery = useDepositTierList()
|
||||
const depositWithdrawConfig =
|
||||
depositWithdrawConfigQuery.data ?? DEFAULT_WITHDRAW_CONFIG
|
||||
const isLoading =
|
||||
tierListQuery.isLoading || depositWithdrawConfigQuery.isLoading
|
||||
const isError = tierListQuery.isError || depositWithdrawConfigQuery.isError
|
||||
const tiers = tierListQuery.data ?? []
|
||||
const createDepositInFlightRef = useRef(false)
|
||||
const pendingPayWindowRef = useRef<Window | null>(null)
|
||||
const createDepositMutation = useMutation({
|
||||
mutationFn: ({
|
||||
channelCode,
|
||||
depositBank,
|
||||
depositBankAccount,
|
||||
depositFromAddress,
|
||||
paymentType,
|
||||
tierId,
|
||||
}: {
|
||||
channelCode: string
|
||||
depositBank?: string
|
||||
depositBankAccount?: string
|
||||
depositFromAddress?: string
|
||||
paymentType: string
|
||||
tierId: string
|
||||
}) =>
|
||||
createDeposit({
|
||||
channel_code: channelCode,
|
||||
deposit_bank: depositBank,
|
||||
deposit_bank_account: depositBankAccount,
|
||||
deposit_from_address: depositFromAddress,
|
||||
idempotency_key: String(Date.now()),
|
||||
payment_type: paymentType,
|
||||
tier_id: tierId,
|
||||
}),
|
||||
})
|
||||
@@ -41,13 +61,34 @@ function MobileTopup() {
|
||||
return
|
||||
}
|
||||
|
||||
const channelCode = tier.payChannelCode ?? tier.channels[0]?.code ?? ''
|
||||
const channelCode =
|
||||
tier.payChannelCode ??
|
||||
tier.channels[0]?.code ??
|
||||
(tier.currency
|
||||
? depositWithdrawConfig.deposit.defaultChannelByCurrency[tier.currency]
|
||||
: undefined) ??
|
||||
depositWithdrawConfig.defaultDepositChannelCode
|
||||
const selectedPaymentMethod =
|
||||
depositWithdrawConfig.deposit.methods.find(
|
||||
(method) => method.currencyCode === tier.currency,
|
||||
) ?? depositWithdrawConfig.deposit.methods[0]
|
||||
const paymentType = selectedPaymentMethod?.code ?? ''
|
||||
const depositBank = selectedPaymentMethod?.requiresBank
|
||||
? depositWithdrawConfig.deposit.banks.find(
|
||||
(bank) => bank.currencyCode === tier.currency,
|
||||
)?.code
|
||||
: undefined
|
||||
|
||||
if (!channelCode) {
|
||||
notify.error(t('commonUi.toast.configError'))
|
||||
return
|
||||
}
|
||||
|
||||
if (!paymentType) {
|
||||
notify.error(t('commonUi.toast.configError'))
|
||||
return
|
||||
}
|
||||
|
||||
createDepositInFlightRef.current = true
|
||||
const payWindow = window.open('', '_blank')
|
||||
|
||||
@@ -63,6 +104,8 @@ function MobileTopup() {
|
||||
try {
|
||||
const result = await createDepositMutation.mutateAsync({
|
||||
channelCode,
|
||||
depositBank,
|
||||
paymentType,
|
||||
tierId: tier.id,
|
||||
})
|
||||
const payUrl = result.pay_url.trim()
|
||||
@@ -105,12 +148,12 @@ function MobileTopup() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{tierListQuery.isLoading ? (
|
||||
{isLoading ? (
|
||||
<DataLoadingIndicator
|
||||
label={t('gameDesktop.topup.tier.loading')}
|
||||
className="h-full min-h-0 rounded-[calc(var(--design-unit)*6)] border border-[rgba(103,227,239,0.18)] bg-[rgba(6,24,35,0.52)]"
|
||||
/>
|
||||
) : tierListQuery.isError ? (
|
||||
) : isError ? (
|
||||
<div className="flex h-full min-h-0 items-center justify-center rounded-[calc(var(--design-unit)*6)] border border-[rgba(185,63,68,0.28)] bg-[rgba(34,13,16,0.42)] px-design-12 text-center text-design-14 text-[#F4A9AE]">
|
||||
{t('gameDesktop.topup.tier.failed')}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user