update pay function
This commit is contained in:
@@ -36,8 +36,7 @@ import {
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { motion } from 'framer-motion';
|
||||
import { forumColors } from '@theme/forumTheme';
|
||||
import { getTopic } from '@services/predictionMarketService';
|
||||
import { getUserAccount } from '@services/creditSystemService';
|
||||
import { getTopicDetail, getUserAccount } from '@services/predictionMarketService.api';
|
||||
import { useAuth } from '@contexts/AuthContext';
|
||||
import TradeModal from './components/TradeModal';
|
||||
|
||||
@@ -63,13 +62,24 @@ const PredictionTopicDetail = () => {
|
||||
|
||||
// 加载话题数据
|
||||
useEffect(() => {
|
||||
const loadTopic = () => {
|
||||
const topicData = getTopic(topicId);
|
||||
if (topicData) {
|
||||
setTopic(topicData);
|
||||
} else {
|
||||
const loadTopic = async () => {
|
||||
try {
|
||||
const response = await getTopicDetail(topicId);
|
||||
if (response.success) {
|
||||
setTopic(response.data);
|
||||
} else {
|
||||
toast({
|
||||
title: '话题不存在',
|
||||
status: 'error',
|
||||
duration: 3000,
|
||||
});
|
||||
navigate('/value-forum');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取话题详情失败:', error);
|
||||
toast({
|
||||
title: '话题不存在',
|
||||
title: '加载失败',
|
||||
description: error.message,
|
||||
status: 'error',
|
||||
duration: 3000,
|
||||
});
|
||||
@@ -77,12 +87,21 @@ const PredictionTopicDetail = () => {
|
||||
}
|
||||
};
|
||||
|
||||
loadTopic();
|
||||
const loadAccount = async () => {
|
||||
if (!user) return;
|
||||
try {
|
||||
const response = await getUserAccount();
|
||||
if (response.success) {
|
||||
setUserAccount(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取账户失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
if (user) {
|
||||
setUserAccount(getUserAccount(user.id));
|
||||
}
|
||||
}, [topicId, user]);
|
||||
loadTopic();
|
||||
loadAccount();
|
||||
}, [topicId, user, toast, navigate]);
|
||||
|
||||
// 打开交易弹窗
|
||||
const handleOpenTrade = (mode) => {
|
||||
@@ -100,10 +119,21 @@ const PredictionTopicDetail = () => {
|
||||
};
|
||||
|
||||
// 交易成功回调
|
||||
const handleTradeSuccess = () => {
|
||||
const handleTradeSuccess = async () => {
|
||||
// 刷新话题数据
|
||||
setTopic(getTopic(topicId));
|
||||
setUserAccount(getUserAccount(user.id));
|
||||
try {
|
||||
const topicResponse = await getTopicDetail(topicId);
|
||||
if (topicResponse.success) {
|
||||
setTopic(topicResponse.data);
|
||||
}
|
||||
|
||||
const accountResponse = await getUserAccount();
|
||||
if (accountResponse.success) {
|
||||
setUserAccount(accountResponse.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('刷新数据失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
if (!topic) {
|
||||
|
||||
Reference in New Issue
Block a user