Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions web/src/components/topup/modals/TopupHistoryModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '@douyinfe/semi-illustrations';
import { Coins } from 'lucide-react';
import { IconSearch } from '@douyinfe/semi-icons';
import { API, timestamp2string } from '../../../helpers';
import { API, timestamp2string, convertUSDToCurrency, convertCNYToCurrency } from '../../../helpers';
import { isAdmin } from '../../../helpers/utils';
import { useIsMobile } from '../../../hooks/common/useIsMobile';
const { Text } = Typography;
Expand All @@ -56,6 +56,25 @@ const PAYMENT_METHOD_MAP = {
wxpay: '微信',
};

// Providers that store Money in CNY; all others store Money in USD.
const CNY_PROVIDERS = new Set(['epay']);
const CNY_METHODS = new Set(['alipay', 'wxpay']);

function renderPaymentAmount(money, record) {
if (money == null || isNaN(money)) {
return <Text type='danger'>-</Text>;
}
const provider = record?.payment_provider || '';
const method = record?.payment_method || '';
const isCNY =
CNY_PROVIDERS.has(provider) ||
(provider === '' && CNY_METHODS.has(method));
const display = isCNY
? convertCNYToCurrency(money)
: convertUSDToCurrency(money);
return <Text type='danger'>{display}</Text>;
}

const TopupHistoryModal = ({ visible, onCancel, t }) => {
const [loading, setLoading] = useState(false);
const [topups, setTopups] = useState([]);
Expand Down Expand Up @@ -207,7 +226,7 @@ const TopupHistoryModal = ({ visible, onCancel, t }) => {
title: t('支付金额'),
dataIndex: 'money',
key: 'money',
render: (money) => <Text type='danger'>¥{money.toFixed(2)}</Text>,
render: (money, record) => renderPaymentAmount(money, record),
},
{
title: t('状态'),
Expand Down
20 changes: 20 additions & 0 deletions web/src/helpers/render.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,26 @@ export function convertUSDToCurrency(usdAmount, digits = 2) {
return symbol + convertedAmount.toFixed(digits);
}

/**
* 将人民币金额转换为当前选择的货币
* @param {number} cnyAmount - 人民币金额
* @param {number} digits - 小数位数
* @returns {string} - 格式化后的货币字符串
*/
export function convertCNYToCurrency(cnyAmount, digits = 2) {
const { symbol, type } = getCurrencyConfig();
if (type === 'CNY') {
return symbol + Number(cnyAmount).toFixed(digits);
}
// Convert CNY → USD using usd_exchange_rate, then to display currency
let usdExchangeRate = 7;
try {
const s = JSON.parse(localStorage.getItem('status') || '{}');
usdExchangeRate = s?.usd_exchange_rate || 7;
} catch (e) {}
return convertUSDToCurrency(cnyAmount / usdExchangeRate, digits);
}

export function renderQuota(quota, digits = 2) {
let quotaPerUnit = localStorage.getItem('quota_per_unit');
const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD';
Expand Down
Loading