import { useMutation } from '@tanstack/react-query' import { useTranslation } from 'react-i18next' import { createWithdraw } from '@/api' import { notify } from '@/lib/notify' import type { WithdrawCreateRequestDto } from '@/type' export function useWithdrawSubmit() { const { i18n, t } = useTranslation() const locale = i18n.resolvedLanguage ?? i18n.language ?? 'en-US' return useMutation({ mutationFn: (payload: WithdrawCreateRequestDto) => createWithdraw(payload), onError: (error) => { notify.error( error instanceof Error ? error.message : t('commonUi.toast.requestFailed'), ) }, onSuccess: (data) => { const formatter = new Intl.NumberFormat(locale, { maximumFractionDigits: 2, }) notify.success(t('gameDesktop.withdraw.submitSuccess'), { description: [ t('gameDesktop.withdraw.success.orderNo', { orderNo: data.order_no, }), t('gameDesktop.withdraw.success.actualArrivalCoin', { amount: formatter.format(data.actual_arrival_coin), }), t('gameDesktop.withdraw.success.feeCoin', { amount: formatter.format(data.fee_coin), }), t('gameDesktop.withdraw.success.reviewRequired', { value: data.risk_review_required ? t('commonUi.dialog.yes') : t('commonUi.dialog.no'), }), ].join('\n'), }) }, }) }