Skip to content

Commit 34fbceb

Browse files
committed
refactor: 체결알림 코드 수정
1 parent 2b28f25 commit 34fbceb

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

src/app/root.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { Route } from './+types/root';
1212

1313
import './app.css';
1414
import { Slide } from 'react-toastify';
15-
import useTradeNotification from '~/features/trade/hooks/useTradeNotification';
1615
import StompProvider from './provider/StompProvider';
1716
import UserIdProvider from './provider/UserInfoProvider';
1817

@@ -76,11 +75,6 @@ export function Layout({ children }: { children: React.ReactNode }) {
7675
);
7776
}
7877

79-
function TradeNotificationHandler() {
80-
useTradeNotification();
81-
return null;
82-
}
83-
8478
export default function App() {
8579
return (
8680
<UserIdProvider>

src/app/routes/trade.$ticker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import { AIChatBot } from '~/features/chat';
99
import { CoinListWithSearchBar } from '~/features/coin-search-list';
1010
import { OrderForm, OrderFormFallback } from '~/features/order';
1111
import { ExecutionList } from '~/features/order-execution-list';
12+
import useTradeNotification from '~/features/trade/hooks/useTradeNotification';
1213
import { Orderbook, StockChart } from '~/features/tradeview';
1314
import Container from '~/shared/ui/Container';
1415
import ContainerTitle from '~/shared/ui/ContainerTitle';
1516
import { NavBar, SideBar } from '~/widgets/navbar';
17+
import { useUserId } from '../provider/UserInfoProvider';
1618
import type { Route } from './+types/trade.$ticker';
1719

1820
export async function loader({ request, params }: Route.LoaderArgs) {
@@ -41,6 +43,8 @@ export async function clientAction() {
4143
export default function TradeRouteComponent({
4244
loaderData,
4345
}: Route.ComponentProps) {
46+
const { userId } = useUserId();
47+
useTradeNotification(userId || 0);
4448
const [isMenuOpen, setIsMenuOpen] = useState(false);
4549
const { coinInfo, coinList, isLoggedIn } = loaderData;
4650
const coinListWithIcon = coinList.map((coinInfo) => ({

src/features/trade/hooks/useTradeNotification.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect } from 'react';
22
import { toast } from 'react-toastify/unstyled';
33

44
import { useStompClient } from '~/app/provider/StompProvider';
5-
import { api as userApi } from '~/entities/user';
6-
import type { UserInfoResponse } from '~/entities/user/types/user.type';
75

86
type TradeNotification = {
97
ticker: string;
@@ -13,24 +11,8 @@ type TradeNotification = {
1311
tradedTime: string;
1412
};
1513

16-
export default function useTradeNotification() {
14+
export default function useTradeNotification(userId: number) {
1715
const { client, connected } = useStompClient();
18-
const [userId, setUserId] = useState<number | null>(null);
19-
20-
useEffect(() => {
21-
const fetchUserInfo = async () => {
22-
try {
23-
const response = await userApi.getUserInfo();
24-
const { data } = await (response.json() as Promise<UserInfoResponse>);
25-
setUserId(data.userId);
26-
} catch (error) {
27-
console.error('Failed to fetch user info:', error);
28-
toast.error('사용자 정보를 가져오는데 실패했습니다.');
29-
}
30-
};
31-
32-
fetchUserInfo();
33-
}, []);
3416

3517
useEffect(() => {
3618
if (!client || !connected || !userId) return;

0 commit comments

Comments
 (0)