Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] feature-fe-#112 차트 실시간 데이터 등락 표시 #118

Merged
merged 59 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
1e762d0
fix: ask error fix
SeungGwan123 Nov 21, 2024
5c1f3e2
feat: candle 정보 수집 기능 구현
SeungGwan123 Nov 21, 2024
ebad1c5
feat: candle 정보 수집 기능 구현
SeungGwan123 Nov 21, 2024
efeceb9
fix: 매도 로직 변경
SeungGwan123 Nov 21, 2024
cd7a5b4
fix: 매도 로직 변경
SeungGwan123 Nov 21, 2024
c520dda
fix: 매수/매도 수정
SeungGwan123 Nov 21, 2024
0e74f3c
fix : 매도 매도 에러 수정
SeungGwan123 Nov 22, 2024
da7ce38
fix: 퍼센트 api 로직 에러 수정
SeungGwan123 Nov 22, 2024
af001bb
fix: 퍼센트 api 로직 에러 수정
SeungGwan123 Nov 22, 2024
f4d59b4
fix: trade, trade-history user-cascade 적용
SeongHyeon0409 Nov 22, 2024
f4d9fdb
chore: GUEST_ID_TTL const변수 적용 및 기한 수정
SeongHyeon0409 Nov 22, 2024
355ecdf
feat: auth refresh token 구현
SeongHyeon0409 Nov 22, 2024
27acfb1
feat: refresh 토큰 컨트롤러 및 구조 개선
SeongHyeon0409 Nov 22, 2024
ac2659a
feat: google oauth구현
SeongHyeon0409 Nov 22, 2024
a52ffdd
fix: guestId redis저장 누락 수정
SeongHyeon0409 Nov 22, 2024
c329067
feat: kakao oauth 로그인 구현
SeongHyeon0409 Nov 23, 2024
7e16374
chore: oauth로그인 배포
SeongHyeon0409 Nov 23, 2024
0ca63ae
fix: 캔들 데이터 수집 차단
SeungGwan123 Nov 24, 2024
9b25a76
fix: cors methos fix
SeungGwan123 Nov 25, 2024
3150e07
fix: cors methos fix
SeungGwan123 Nov 25, 2024
fd595ef
fix: cors methos fix
SeungGwan123 Nov 25, 2024
8938fff
fix: 개발환경 oauth 설정
SeongHyeon0409 Nov 25, 2024
5340b81
fix: 로컬 환경 oauth 설정 변경
SeongHyeon0409 Nov 25, 2024
6e47f2c
feat: 코인 현재가 rest api 구현
SeongHyeon0409 Nov 25, 2024
eecc28b
chore: 배포용 commit
SeongHyeon0409 Nov 25, 2024
ee1febf
chore: nginx 수정
SeongHyeon0409 Nov 25, 2024
03c1d1b
refactor: 구글 로그인 이미지 크기 변경
Nov 25, 2024
9e650df
refactor: sidebar css 변경
Nov 25, 2024
407d8f5
fix: 의존성 배열 요소 추가
Nov 25, 2024
cd0f112
refactor: css 수정
Nov 25, 2024
0b63396
refactor: krw로 리다이렉트
Nov 25, 2024
b5b2649
refactor: css 수정
Nov 25, 2024
73c54b1
refactor: css 수정
Nov 25, 2024
d9c1745
feat: suspense 정의
Nov 25, 2024
ac629a8
refactor: ActiveLink로 변경
Nov 25, 2024
1d36ddb
feat: 원화 거래 가능한 코인인지 확인하는 커스텀 훅 정의
Nov 25, 2024
4697c10
refactor: 토스트 길이 글자 길이에 맞도록 수정
Nov 25, 2024
b73a931
feat: 원화 거래 가능한 코인인지 확인하는 커스텀 훅 사용
Nov 25, 2024
e2b5f99
feat: 차트 현재가 분봉 등락 실시간 기능 정의
Nov 25, 2024
b33a540
refactor: 차트 기본 배율 수정
Nov 26, 2024
a9e87a7
refactor: 차트 기본 배율 수정
Nov 26, 2024
0bc969f
feat: 분봉 외 모든 시간 실시간 가격 차트 등락 구현
Nov 26, 2024
eb67723
refactor: 미국 시차 계산하여 한국 시간으로 변경
Nov 26, 2024
fb9b79e
refactor: 서버 응답값 변경
Nov 26, 2024
076116f
refactor: 서버 응답값 변경
Nov 26, 2024
4d933b0
chore: utils 파일들 폴더 분리
Nov 26, 2024
bc5bcae
chore: utlitiy 파일 분리에 따른 경로 변경
Nov 26, 2024
0b9fc18
refactor: 차트 설정 로직 커스텀 훅으로 분리
Nov 26, 2024
204f850
refactor: market ->chart 폴더로 위치 이동
Nov 26, 2024
7ee7bdb
feat: 실시간 차트 등락 로직 커스텀 훅으로 분리
Nov 26, 2024
e7c3578
chore: utlitiy 파일 분리에 따른 경로 변경
Nov 26, 2024
de35758
chore: utlitiy 파일 분리에 따른 경로 변경
Nov 26, 2024
fe6b2a6
refactor: 차트 주요 로직 커스텀 훅으로 분리
Nov 26, 2024
38de649
feat: 차트 실시간 데이터 변동 후 refetch 로직 추가
Nov 26, 2024
487a563
chore: utlitiy 파일 분리에 따른 경로 변경
Nov 26, 2024
17a8ca1
chore: utlitiy 파일 분리에 따른 경로 변경
Nov 26, 2024
0ffe1b7
chore: utlitiy 파일 분리에 따른 경로 변경
Nov 26, 2024
637ead4
refactor: 소수점 가격 구매 가능하도록 변경
Nov 26, 2024
0564339
refactor: css 수정
Nov 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
- dev
- dev-be
- feature-be-#51
- feature-be-#105
jobs:
build_and_deploy:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Origin 헤더 유지
proxy_set_header Origin $http_origin;

# CORS 설정 추가
add_header 'Access-Control-Allow-Origin' 'https://www.corinee.site' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
Expand Down
21 changes: 12 additions & 9 deletions packages/client/src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import Account from '@/pages/account/Account';
import Trade from '@/pages/trade/Trade';
import NotFound from '@/pages/not-found/NotFound';
import Redricet from '@/pages/auth/Redirect';
import { Suspense } from 'react';

function Router() {
return (
<Routes>
<Route element={<Layout />}>
<Route path="/" element={<Home />} />
<Route path="/account" element={<Account />} />
<Route path="/trade/:market" element={<Trade />} />
</Route>
<Route path="/auth/callback" element={<Redricet />} />
<Route path="*" element={<NotFound />} />
</Routes>
<Suspense>
<Routes>
<Route element={<Layout />}>
<Route path="/" element={<Home />} />
<Route path="/account" element={<Account />} />
<Route path="/trade/:market" element={<Trade />} />
</Route>
<Route path="/auth/callback" element={<Redricet />} />
<Route path="*" element={<NotFound />} />
</Routes>
</Suspense>
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/api/interceptors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authInstance, instance } from '@/api/instance';
import { Login } from '@/types/auth';
import { getCookie, removeCookie, setCookie } from '@/utility/cookies';
import { getCookie, removeCookie, setCookie } from '@/utility/storage/cookies';
import { AxiosResponse } from 'axios';

authInstance.interceptors.request.use(
Expand Down
28 changes: 17 additions & 11 deletions packages/client/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAuth } from '@/hooks/auth/useAuth';
import { Button, Navbar } from '@material-tailwind/react';
import { Link } from 'react-router-dom';
import { Link, NavLink } from 'react-router-dom';
import { useAuthStore } from '@/store/authStore';
import { useToast } from '@/hooks/ui/useToast';
import logoImage from '@asset/logo/corineeLogo.png';
Expand All @@ -22,7 +22,7 @@ function Header() {
<>
<Navbar
fullWidth={true}
className=" flex justify-between items-center sticky top-0 min-w-[1300px]"
className="w-full flex justify-between items-center sticky top-0 z-10"
shadow={false}
>
<div>
Expand All @@ -32,12 +32,22 @@ function Header() {
</Link>
</div>
<div className="flex gap-4">
<Link to={'/'} className="text-gray-600 hover:text-black">
<NavLink
to={'/'}
className={({ isActive }) =>
`${isActive ? 'text-black' : 'text-gray-600'} hover:text-black`
}
>
</Link>
<Link to={'/account'} className="text-gray-600 hover:text-black">
</NavLink>
<NavLink
to={'/account'}
className={({ isActive }) =>
`${isActive ? 'text-black' : 'text-gray-600'} hover:text-black`
}
>
내 계좌
</Link>
</NavLink>
</div>
<div>
{isAuthenticated ? (
Expand All @@ -63,11 +73,7 @@ function Header() {
<img alt="kakao_image" src={kakaLogo} className="w-10 h-10" />
</button>
<button onClick={() => handleLogin('google')}>
<img
alt="google_image"
src={googleLogo}
className="w-10 h-10"
/>
<img alt="google_image" src={googleLogo} className="w-9 h-9" />
</button>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/sidebar/RecentlyViewed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSSETicker } from '@/hooks/SSE/useSSETicker';
import { formatData } from '@/utility/format/formatSSEData';
import useRecentlyMarketStore from '@/store/recentlyViewed';
import { useRecentlyMarketList } from '@/hooks/market/useRecentlyMarket';
import { convertToQueryString } from '@/utility/queryString';
import { convertToQueryString } from '@/utility/api/queryString';
import { SidebarMarketData } from '@/types/market';

function RecentlyViewed() {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function Sidebar() {
];

return (
<div className="absolute sm:flex xl:sticky xl:z-0 top-0 right-0 bg-gray-100 h-screen z-50">
<div className="relative h-full flex">
<SideDrawer isOpen={isOpen} activeMenu={activeMenu} />
<div className="w-14 flex flex-col gap-3 items-center border-l border-gray-400 border-solid">
<div className="w-14 flex flex-col gap-3 items-center bg-gray-100 border-l border-gray-400 border-solid h-full">
{SIDEBAR_BUTTONS.map((button) => (
<SideBarButton
key={button.id}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/hooks/auth/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { guestLogin, logout } from '@/api/auth';
import { useAuthStore } from '@/store/authStore';
import { Login } from '@/types/auth';
import { removeCookie, setCookie } from '@/utility/cookies';
import { removeCookie, setCookie } from '@/utility/storage/cookies';
import { useMutation } from '@tanstack/react-query';

export function useAuth() {
Expand Down
40 changes: 40 additions & 0 deletions packages/client/src/hooks/chart/useChartSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
initializeChart,
setupCandlestickSeries,
} from '@/utility/chart/chartSetup';
import { useRef, useEffect } from 'react';
import { IChartApi, ISeriesApi } from 'lightweight-charts';
import { chartConfig } from '@/utility/chart/config';
import { handleResize } from '@/utility/chart/chartEvent';

export function useChartSetup() {
const chartRef = useRef<HTMLDivElement>(null);
const chartInstanceRef = useRef<IChartApi | null>(null);
const seriesRef = useRef<ISeriesApi<'Candlestick'> | null>(null);

useEffect(() => {
if (!chartRef.current) return;
chartInstanceRef.current = initializeChart(chartRef.current, chartConfig);
seriesRef.current = setupCandlestickSeries(
chartInstanceRef.current,
[],
chartConfig,
);
const resizeObserver = new ResizeObserver(() => {
handleResize(chartRef, chartInstanceRef);
});

if (chartRef.current.parentElement) {
resizeObserver.observe(chartRef.current.parentElement);
}

return () => {
if (chartInstanceRef.current) {
resizeObserver.disconnect();
chartInstanceRef.current.remove();
}
};
}, []);

return { chartRef, chartInstanceRef, seriesRef };
}
40 changes: 40 additions & 0 deletions packages/client/src/hooks/chart/usePeriodChart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getCandleByPeriod } from '@/api/market';
import { Candle, CandlePeriod, InfiniteCandle } from '@/types/chart';
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';

export function usePeriodChart(
market: string,
period: CandlePeriod,
minute?: number,
) {
const { data, fetchNextPage, hasNextPage, refetch } =
useSuspenseInfiniteQuery<
Candle[],
Error,
InfiniteCandle,
[string, string, CandlePeriod, number?],
string | undefined
>({
queryKey: ['candles', market, period, minute],
queryFn: ({ pageParam }) => {
return getCandleByPeriod(market, period, pageParam, minute);
},
getNextPageParam: (lastPage) => {
if (lastPage.length === 0) return undefined;
const oldestCandle = lastPage[lastPage.length - 1];
return oldestCandle?.candle_date_time_utc;
},
initialPageParam: undefined,
select: (data) => ({
candles: data.pages.flat(),
hasNextPage: data.pages[data.pages.length - 1]?.length === 200,
}),
});

return {
refetch,
data,
fetchNextPage,
hasNextPage,
};
}
52 changes: 52 additions & 0 deletions packages/client/src/hooks/chart/useRealTimeCandle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useEffect, useRef } from 'react';
import { CandleFormat, CandlePeriod } from '@/types/chart';
import { ISeriesApi } from 'lightweight-charts';
import { getCurrentCandleStartTime } from '@/utility/chart/chartTimeUtils';

type Props = {
seriesRef: React.RefObject<ISeriesApi<'Candlestick'>>;
currentPrice: number;
activePeriod: CandlePeriod;
refetch: () => Promise<unknown>;
minute?: number;
};
export function useRealTimeCandle({
seriesRef,
currentPrice,
activePeriod,
refetch,
minute,
}: Props) {
const lastCandleRef = useRef<CandleFormat | null>(null);

const updateRealTimeCandle = () => {
if (!seriesRef.current || !currentPrice || !lastCandleRef.current) return;

const currentCandleStartTime = getCurrentCandleStartTime(
activePeriod,
minute,
);
if (
!lastCandleRef.current ||
lastCandleRef.current.time !== currentCandleStartTime
) {
refetch();
} else {
const updatedCandle = {
...lastCandleRef.current,
close: currentPrice,
high: Math.max(lastCandleRef.current.high, currentPrice),
low: Math.min(lastCandleRef.current.low, currentPrice),
};
lastCandleRef.current = updatedCandle;
seriesRef.current.update(updatedCandle);
}
};

useEffect(() => {
if (!seriesRef.current || !currentPrice) return;
updateRealTimeCandle();
}, [currentPrice, minute, activePeriod]);

return { lastCandleRef };
}
38 changes: 0 additions & 38 deletions packages/client/src/hooks/market/usePeriodChart.ts

This file was deleted.

13 changes: 13 additions & 0 deletions packages/client/src/hooks/market/useValidCoin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMarketAll } from '@/hooks/market/useMarketAll';
import { useMemo } from 'react';
import { filterCoin } from '@/utility/validation/filter';
export function useValidCoin(market: string | undefined) {
const { data } = useMarketAll();
const KRW_Markets = useMemo(() => filterCoin(data, 'KRW'), [data]);
const isValidCoin = useMemo(() => {
if (!market || !KRW_Markets) return false;
return KRW_Markets.some((item) => item.market === market);
}, [KRW_Markets]);

return { isValidCoin };
}
2 changes: 1 addition & 1 deletion packages/client/src/hooks/ui/useSideDraw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { SideBarCategory } from '@/types/category';
import { isSideBarMenu } from '@/utility/typeGuard';
import { isSideBarMenu } from '@/utility/validation/typeGuard';

function useSideDrawer() {
const [activeMenu, setActiveMenu] = useState<SideBarCategory>(null);
Expand Down
6 changes: 6 additions & 0 deletions packages/client/src/hooks/ui/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export function useToast() {
pauseOnHover: false,
hideProgressBar: true,
transition: Zoom,
style: {
width: 'fit-content',
whiteSpace: 'nowrap',
display: 'inline-flex',
margin: '0 auto',
},
};

const showToast = {
Expand Down
5 changes: 2 additions & 3 deletions packages/client/src/hooks/useMyHistory.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { myHistory } from '@/api/history';
import { getCookie } from '@/utility/cookies';
import { getCookie } from '@/utility/storage/cookies';
import { useSuspenseQuery } from '@tanstack/react-query';

export function useMyHistory() {
const QUERY_KEY = 'MY_History';
const token = getCookie('access_token');
const {data} = useSuspenseQuery({
const { data } = useSuspenseQuery({
queryFn: () => myHistory(token),
queryKey: [QUERY_KEY],
refetchOnMount: 'always',
});


return data;
}
2 changes: 1 addition & 1 deletion packages/client/src/pages/account/balance/BalanceCoin.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Change, CoinTicker } from '@/types/ticker';
import colorClasses from '@/constants/priceColor';
import { AccountCoin } from '@/types/account';
import PORTFOLIO_EVALUATOR from '@/utility/portfolioEvaluator';
import PORTFOLIO_EVALUATOR from '@/utility/finance/portfolioEvaluator';
import { Link } from 'react-router-dom';

type BalanceCoinProps = {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/account/balance/BalanceTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BalanceInfo from '@/pages/account/balance/BalanceInfo';
import { BalanceMarket } from '@/types/market';
import { SSEDataType } from '@/types/ticker';
import PORTFOLIO_EVALUATOR from '@/utility/portfolioEvaluator';
import PORTFOLIO_EVALUATOR from '@/utility/finance/portfolioEvaluator';

type BalanceTableProps = {
KRW: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/auth/Redirect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSearchParams, useNavigate } from 'react-router-dom';
import { useEffect } from 'react';
import { setCookie } from '@/utility/cookies';
import { setCookie } from '@/utility/storage/cookies';
import { useAuthStore } from '@/store/authStore';

function Redirect() {
Expand Down
Loading