From 627fc6affb4aee0d1bba85b12b52d00aec4a811c Mon Sep 17 00:00:00 2001 From: novice1993 Date: Thu, 28 Sep 2023 23:14:12 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=82=B4=EC=9A=A9=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PR 관련 코드 리뷰 내용 반영하여 수정 - 이외 수정사항 : MainPage의 로그인/아웃 헤더관련 수정 미완이라 이전 코드 복구하여 임시 활용 (담당자에게 전달 완료함) Issues #165 --- .../CentralChart/CompareChartBtn.tsx | 7 +- .../components/CentralChart/CompareList.tsx | 5 +- .../MarketComponents/MarketKospiChart.tsx | 11 +- .../StockOrderSection/CancelConfirm.tsx | 25 ++-- .../StockOrderSection/OrderDecisionBtn.tsx | 11 +- .../StockOrderSection/OrderedStock.tsx | 3 +- .../StockOrderSection/PriceSetting.tsx | 85 ++++++------ .../StockOrderSection/StockOrder.tsx | 3 +- .../StockOrderSection/StockPrice.tsx | 2 +- .../StockOrderSection/VolumeSetteing.tsx | 2 +- .../StockOrderSection/WaitOrderIndicator.tsx | 2 +- client/src/constant/constant.ts | 2 + client/src/hooks/useCash.ts | 125 ++++++++++-------- client/src/hooks/useGetCash.ts | 1 - client/src/hooks/useGetCompanyList.ts | 1 - client/src/hooks/useGetKospiChart.ts | 101 -------------- client/src/hooks/useGetMemberId.ts | 4 +- client/src/hooks/useGetMemberInfo.ts | 5 +- client/src/hooks/useGetStockData.ts | 20 +-- client/src/hooks/useGetStockInfo.ts | 54 +------- client/src/hooks/useGetStockOrderRecord.ts | 6 - client/src/hooks/useGetStockholds.ts | 7 +- .../src/hooks/useGetWaitOrderSuccessInfo.ts | 47 ------- client/src/page/MainPage.tsx | 12 +- client/src/utils/setAutoLogoutAlarm.ts | 14 +- 25 files changed, 186 insertions(+), 369 deletions(-) create mode 100644 client/src/constant/constant.ts delete mode 100644 client/src/hooks/useGetKospiChart.ts delete mode 100644 client/src/hooks/useGetWaitOrderSuccessInfo.ts diff --git a/client/src/components/CentralChart/CompareChartBtn.tsx b/client/src/components/CentralChart/CompareChartBtn.tsx index 335bdc72..328ba751 100644 --- a/client/src/components/CentralChart/CompareChartBtn.tsx +++ b/client/src/components/CentralChart/CompareChartBtn.tsx @@ -29,11 +29,8 @@ const CompareChartBtn = () => { {compare && ( - {companyList?.map((company) => { - const corpName = company.korName; - const companyId = company.companyId; - - return ; + {companyList?.map(({ korName, companyId }) => { + return ; })} diff --git a/client/src/components/CentralChart/CompareList.tsx b/client/src/components/CentralChart/CompareList.tsx index 4345ab3e..c842fc79 100644 --- a/client/src/components/CentralChart/CompareList.tsx +++ b/client/src/components/CentralChart/CompareList.tsx @@ -10,10 +10,9 @@ const CompareList = (props: OwnProps) => { const currentCompanyid = useSelector((state: StateProps) => state.companyId); const handleSelectCompareStock = () => { - if (currentCompanyid === compareCompanyId) { - return; + if (currentCompanyid !== compareCompanyId) { + dispatch(setCompareStock(compareCompanyId)); } - dispatch(setCompareStock(compareCompanyId)); }; return {corpName}; diff --git a/client/src/components/MarketComponents/MarketKospiChart.tsx b/client/src/components/MarketComponents/MarketKospiChart.tsx index b13142e2..aa337988 100644 --- a/client/src/components/MarketComponents/MarketKospiChart.tsx +++ b/client/src/components/MarketComponents/MarketKospiChart.tsx @@ -2,7 +2,8 @@ import * as echarts from "echarts"; import { styled } from "styled-components"; import { useState, useEffect } from "react"; import { useQuery } from "react-query"; -import { getKospiData } from "../../hooks/useGetKospiChart.ts"; +import axios from "axios"; + const MarketkospiChart = () => { const [kospiData, setKospiData] = useState([]); @@ -117,6 +118,14 @@ const MarketkospiChart = () => { export default MarketkospiChart; +const getKospiData = async () => { + const res = await axios.get("http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/kospi"); + const chartData = res.data.output2; + const kospiData = chartData.reverse(); + + return kospiData; +}; + interface KospiProps { acml_tr_pbmn: string; acml_vol: string; diff --git a/client/src/components/StockOrderSection/CancelConfirm.tsx b/client/src/components/StockOrderSection/CancelConfirm.tsx index c607e544..82aefdf4 100644 --- a/client/src/components/StockOrderSection/CancelConfirm.tsx +++ b/client/src/components/StockOrderSection/CancelConfirm.tsx @@ -5,9 +5,12 @@ import { toast } from "react-toastify"; import { StateProps } from "../../models/stateProps"; import useDeleteStockOrder from "../../hooks/useDeleteStockOrder"; import { dummyLogo } from "../../dummy/dummyLogo"; +import { priceUnit, volumeUnit } from "../../constant/constant"; -const priceUnit: string = "원"; -const volumeUnit: string = "주"; +const directionType = { + Up: "Up", + Down: "Down", +}; const CancelConfirm = (props: CancelConfirmProps) => { const { corpName, orderType, orderPrice, orderVolume, orderId, setCancle } = props; @@ -16,24 +19,22 @@ const CancelConfirm = (props: CancelConfirmProps) => { const companyId = useSelector((state: StateProps) => state.companyId); const deleteOrder = useDeleteStockOrder(); - const orderCancleText: string = "취소"; + const cancelText: string = "취소"; const orderPriceText: string = "주문단가"; const cancleVolumeText: string = "취소수량"; const maximumCancleVolumeText01: string = "최대"; - const maximumCancleVolumeText02: string = "주"; const totalCancleAmountText: string = "총 취소금액"; const closeButtonText: string = "닫기"; const confirmButtonText: string = "확인"; - const toastText01: string = "취소"; - const toastText02: string = " 처리가 완료되었습니다"; + const toastText: string = " 처리가 완료되었습니다"; const price = orderPrice.toLocaleString(); const totalPrice = (orderPrice * cancleVolume).toLocaleString(); const handleChangeCancleVolume = (direction: string) => { - if (direction === "Up") { + if (direction === directionType.Up) { cancleVolume < orderVolume && setCancleVolume((previousState) => previousState + 1); } - if (direction === "Down") { + if (direction === directionType.Down) { 0 < cancleVolume && setCancleVolume((previousState) => previousState - 1); } }; @@ -83,9 +84,9 @@ const CancelConfirm = (props: CancelConfirmProps) => {
✓ {orderType} - {toastText01} + {cancelText} - {toastText02} + {toastText}
, { @@ -104,7 +105,7 @@ const CancelConfirm = (props: CancelConfirmProps) => {
{corpName} {orderType} - {orderCancleText} + {cancelText}
@@ -119,7 +120,7 @@ const CancelConfirm = (props: CancelConfirmProps) => { {maximumCancleVolumeText01} {orderVolume} - {maximumCancleVolumeText02} + {volumeUnit}
diff --git a/client/src/components/StockOrderSection/OrderDecisionBtn.tsx b/client/src/components/StockOrderSection/OrderDecisionBtn.tsx index fd99a706..c0c34487 100644 --- a/client/src/components/StockOrderSection/OrderDecisionBtn.tsx +++ b/client/src/components/StockOrderSection/OrderDecisionBtn.tsx @@ -6,11 +6,10 @@ import { StateProps } from "../../models/stateProps"; import { OrderTypeProps } from "../../models/orderTypeProps"; import { setStockOrderVolume } from "../../reducer/stockOrderVolume-Reducer"; import { openDecisionWindow } from "../../reducer/setDecisionWindow-Reducer"; +import { priceUnit } from "../../constant/constant"; -const availableMoneyText01: string = "최대"; -const availableMoneyText02: string = "원"; +const availableMoneyText: string = "최대"; const totalAmountText: string = "주문총액"; -const totalAmountUnit: string = "원"; const OrderDecisionBtn = () => { const { cashData } = useGetCash(); @@ -40,14 +39,14 @@ const OrderDecisionBtn = () => { return (
- {availableMoneyText01} + {availableMoneyText} {cash} - {availableMoneyText02} + {priceUnit}
{totalAmountText}
{totalOrderAmout.toLocaleString()}
-
{totalAmountUnit}
+
{priceUnit}
{orderBtnText} diff --git a/client/src/components/StockOrderSection/OrderedStock.tsx b/client/src/components/StockOrderSection/OrderedStock.tsx index 32b3fb93..5a691c04 100644 --- a/client/src/components/StockOrderSection/OrderedStock.tsx +++ b/client/src/components/StockOrderSection/OrderedStock.tsx @@ -3,9 +3,8 @@ import { styled } from "styled-components"; import useGetCompanyList from "../../hooks/useGetCompanyList"; import CancelConfirm from "./CancelConfirm"; import { dummyLogo } from "../../dummy/dummyLogo"; +import { priceUnit, volumeUnit } from "../../constant/constant"; -const priceUnit: string = "원"; -const volumeUnit: string = "주"; const cancelButtonText: string = "주문취소"; const OrderedStock = (props: OrderdStockProps) => { diff --git a/client/src/components/StockOrderSection/PriceSetting.tsx b/client/src/components/StockOrderSection/PriceSetting.tsx index d99423e3..0c43d294 100644 --- a/client/src/components/StockOrderSection/PriceSetting.tsx +++ b/client/src/components/StockOrderSection/PriceSetting.tsx @@ -4,10 +4,9 @@ import { styled } from "styled-components"; import { setStockOrderPrice, plusStockOrderPrice, minusStockOrderPrice } from "../../reducer/stockOrderPrice-Reducer"; import { StateProps } from "../../models/stateProps"; import { StockInfoProps } from "../../models/stockInfoProps"; +import { priceUnit } from "../../constant/constant"; const priceSettingTitle: string = "가격"; -const unitText: string = "원"; - const noVolumeNotification: string = " [거래량 없음] 주문 시 대기 처리 됩니다"; const existVolumeNotification: string = " [거래량 있음] 주문 시 체결 처리 됩니다"; @@ -16,50 +15,22 @@ const PriceSetting = (props: OwnProps) => { const dispatch = useDispatch(); const orderPrice = useSelector((state: StateProps) => state.stockOrderPrice); - - // 가격 조정 관련 타이머 상태 - const [priceChangeTimer, setPriceChangeTimer] = useState(null); - - // 초기 설정값 및 가격 변동폭 설정 - const { askp1, askp2, askp3, askp4, askp5, askp6, askp7, askp8, askp9, askp10 } = stockInfo; - const sellingInfo = [askp1, askp2, askp3, askp4, askp5, askp6, askp7, askp8, askp9, askp10]; - const sellingPrice = sellingInfo.map((price) => parseInt(price)); - const existSellingPrice = sellingPrice.filter((price) => price !== 0); // price 0인 경우 제거 - const defaultPrice = existSellingPrice[0]; - const priceInterval = existSellingPrice[1] - existSellingPrice[0]; - const orderType = useSelector((state: StateProps) => state.stockOrderType); const [orderPossibility, setOrderPossibility] = useState(true); + const [priceChangeTimer, setPriceChangeTimer] = useState(null); + // 매도/매수호가 정리 + const { askp1, askp2, askp3, askp4, askp5, askp6, askp7, askp8, askp9, askp10 } = stockInfo; const { bidp1, bidp2, bidp3, bidp4, bidp5, bidp6, bidp7, bidp8, bidp9, bidp10 } = stockInfo; - const buyingInfo = [bidp1, bidp2, bidp3, bidp4, bidp5, bidp6, bidp7, bidp8, bidp9, bidp10]; - const buyingPrice = buyingInfo.map((price) => parseInt(price)); - const existBuyingPrice = buyingPrice.filter((price) => price !== 0); // price 0인 경우 제거 + const sellingPrice = [askp1, askp2, askp3, askp4, askp5, askp6, askp7, askp8, askp9, askp10].map((price) => parseInt(price)); + const buyingPrice = [bidp1, bidp2, bidp3, bidp4, bidp5, bidp6, bidp7, bidp8, bidp9, bidp10].map((price) => parseInt(price)); + const existSellingPrice = sellingPrice.filter((price) => price !== 0); + const existBuyingPrice = buyingPrice.filter((price) => price !== 0); - // 거래 가능여부 판별 함수 - const handleCheckTradePossibility = () => { - if (orderType) { - // 매수 주문 - if (orderPrice !== 0 && !existBuyingPrice.includes(orderPrice)) { - setOrderPossibility(false); - } else { - setOrderPossibility(true); - } - } else { - // 매도 주문 - if (orderPrice !== 0 && !existSellingPrice.includes(orderPrice)) { - setOrderPossibility(false); - } else { - setOrderPossibility(true); - } - } - }; - - useEffect(() => { - handleCheckTradePossibility(); - }, [orderPrice, orderType]); + // 호가 간 가격 차 + const priceInterval = existSellingPrice[1] - existSellingPrice[0]; - // 거래가 증가/감소 + // 거래가 변경 시 const handlePlusOrderPrice = () => { dispatch(plusStockOrderPrice(priceInterval)); }; @@ -68,7 +39,6 @@ const PriceSetting = (props: OwnProps) => { dispatch(minusStockOrderPrice(priceInterval)); }; - // 위-아래 방향키 입력 시 const handleInputArrowBtn = (event: React.KeyboardEvent) => { if (event.code === "ArrowUp") { handlePlusOrderPrice(); @@ -77,7 +47,6 @@ const PriceSetting = (props: OwnProps) => { } }; - // 거래가 직접 기입 시 const handleWriteOrderPrice = (event: React.ChangeEvent) => { const inputPrice = event.target.value; const numberInputPrice = parseInt(inputPrice, 10); @@ -92,7 +61,7 @@ const PriceSetting = (props: OwnProps) => { // priceInterval로 나누어 떨어지지 않는 값을 기입 시 -> 0.8초 후에 나누어 떨어지는 값으로 변경 if (priceChangeTimer !== null) { - clearTimeout(priceChangeTimer); + clearTimeout(priceChangeTimer); // 이전 입력으로 인한 비동기 작업 존재할 시 -> 제거 } dispatch(setStockOrderPrice(numberInputPrice)); @@ -108,9 +77,33 @@ const PriceSetting = (props: OwnProps) => { } }; - // 종목이 달리지면 -> 가격도 변경 + // 거래 가능여부 판별 함수 (거래량 유무에 따라) + const handleCheckTradePossibility = () => { + if (orderType) { + // 매수 + if (orderPrice !== 0 && !existBuyingPrice.includes(orderPrice)) { + setOrderPossibility(false); + } else { + setOrderPossibility(true); + } + } + + if (!orderType) { + // 메도 + if (orderPrice !== 0 && !existSellingPrice.includes(orderPrice)) { + setOrderPossibility(false); + } else { + setOrderPossibility(true); + } + } + }; + + useEffect(() => { + handleCheckTradePossibility(); + }, [orderPrice, orderType]); + useEffect(() => { - dispatch(setStockOrderPrice(defaultPrice)); + dispatch(setStockOrderPrice(existSellingPrice[0])); }, [companyId]); return ( @@ -120,7 +113,7 @@ const PriceSetting = (props: OwnProps) => {
- {unitText} + {priceUnit}