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 #138 - 사이드바 내 투자 기능 구현 #140

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
55 changes: 55 additions & 0 deletions packages/client/src/components/sidebar/MyInvestment.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,64 @@
import NotLogin from '@/components/NotLogin';
import SidebarCoin from '@/components/sidebar/SidebarCoin';
import { useSSETicker } from '@/hooks/SSE/useSSETicker';
import { useMyAccount } from '@/hooks/auth/useMyAccount';
import { useAuthStore } from '@/store/authStore';
import { formatData } from '@/utility/format/formatSSEData';
import { useMemo } from 'react';
import Lottie from 'lottie-react';
import Wallet from '@asset/lotties/Wallet.json';

function MyInvestment() {
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
const { data } = useMyAccount();
const balanceMarketList = useMemo(
() =>
data.coins.map((coin) => {
return {
market: `KRW-${coin.market}`,
quantity: Number(coin.quantity),
};
}),
[data.coins],
);
const { sseData } = useSSETicker(balanceMarketList);

const formatters = formatData('KRW');

if (!isAuthenticated) return <NotLogin size="sm" />;

return (
<div className="flex flex-col h-full overflow-y-auto [&::-webkit-scrollbar]:hidden p-4">
<div>
<span className="text-lg font-semibold">내 투자</span>
</div>
<div className="border border-solid border-gray-300 my-3"></div>
{data.coins.length > 0 ? (
data.coins.map((coin, index) => (
<SidebarCoin
key={coin.market}
listNumber={index + 1}
formatters={formatters}
sseData={sseData}
image_url={coin.img_url}
korean_name={coin.koreanName}
market={`KRW-${coin.market}`}
/>
))
) : (
<>
<Lottie
animationData={Wallet}
loop={true}
autoPlay={true}
/>
<p className="text-center text-gray-600 font-semibold">
투자한 종목이 없어요 !
</p>
</>
)}
</div>
);
}

export default MyInvestment;
4 changes: 3 additions & 1 deletion packages/client/src/components/sidebar/SidebarCoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type SidebarCoinProps = {
korean_name: string;
listNumber: number;
formatters: Formatters;
sseData: SSEDataType;
sseData: SSEDataType | undefined | null;
market: string;
};

Expand All @@ -24,6 +24,8 @@ function SidebarCoin({
const navigate = useNavigate();
const { addRecentlyViewedMarket } = useRecentlyMarketStore();

if (!sseData) return;

const handleClick = () => {
addRecentlyViewedMarket(market);
navigate(`/trade/${market}`);
Expand Down
24 changes: 15 additions & 9 deletions packages/client/src/pages/account/balance/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ function Balance() {
<div className="flex-[1]">손익</div>
</div>
</div>
{data.coins.map((coin) => {
return (
<BalanceCoin
key={coin.market}
coin={coin}
sseData={sseData ? sseData[`KRW-${coin.market}`] : null}
/>
);
})}
{data.coins.length > 0 ? (
data.coins.map((coin) => {
return (
<BalanceCoin
key={coin.market}
coin={coin}
sseData={sseData ? sseData[`KRW-${coin.market}`] : null}
/>
);
})
) : (
<div className="mt-20 flex justify-center">
<p className="font-semibold text-gray-700">보유한 종목이 없습니다.</p>
</div>
)}
</div>
);
}
Expand Down
14 changes: 11 additions & 3 deletions packages/client/src/pages/account/history/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ function History() {
<div className="flex-[2]">주문시간</div>
</div>

{filteredHistories.reverse().map((history) => (
<HistoryInfo key={history.tradeHistoryId} {...history} />
))}
{filteredHistories.length > 0 ? (
filteredHistories
.reverse()
.map((history) => (
<HistoryInfo key={history.tradeHistoryId} {...history} />
))
) : (
<div className="mt-20 flex justify-center">
<p className='font-semibold text-gray-700'>거래 내역이 없습니다.</p>
</div>
)}
</div>
</>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/pages/account/history/HistoryOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function HistoryOption({ option, handleOption }: HistoryOptionProps) {
className={`py-3 px-4 w-20 border-solid border-gray-400
${
option === 'TOTAL'
? 'border-2 border-blue-700 text-blue-800'
? 'border-2 border-blue-600 text-blue-800'
: option === 'BUY'
? 'border-y border-l'
: 'border'
Expand All @@ -31,7 +31,7 @@ function HistoryOption({ option, handleOption }: HistoryOptionProps) {
className={`py-3 px-4 w-20 border-solid border-gray-400
${
option === 'BUY'
? 'border-2 border-blue-700 text-blue-800'
? 'border-2 border-blue-600 text-blue-800'
: option === 'SELL'
? 'border-y'
: 'border-y border-r'
Expand All @@ -44,7 +44,7 @@ function HistoryOption({ option, handleOption }: HistoryOptionProps) {
</div>
<div
className={`py-3 px-4 w-20 border-solid border-gray-400
${option === 'SELL' ? 'border-2 border-blue-700 text-blue-800' : 'border-y border-r'}`}
${option === 'SELL' ? 'border-2 border-blue-600 text-blue-800' : 'border-y border-r'}`}
onClick={() => {
handleOption('SELL');
}}
Expand Down
10 changes: 5 additions & 5 deletions packages/client/src/pages/account/history/HistoryPeriod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function HistoryPeriod({ period, handlePeriod }: HistoryPeriodProps) {
className={`py-3 px-4 w-20 border-solid border-gray-400
${
period === 'ONE_WEEK'
? 'border-2 border-blue-700 text-blue-800'
? 'border-2 border-blue-600 text-blue-800'
: period === 'ONE_MONTH'
? 'border-y border-l'
: 'border'
Expand All @@ -37,7 +37,7 @@ function HistoryPeriod({ period, handlePeriod }: HistoryPeriodProps) {
className={`py-3 px-4 w-20 border-solid border-gray-400
${
period === 'ONE_MONTH'
? 'border-2 border-blue-700 text-blue-800'
? 'border-2 border-blue-600 text-blue-800'
: period === 'THREE_MONTH'
? 'border-y'
: 'border-y border-r'
Expand All @@ -52,7 +52,7 @@ function HistoryPeriod({ period, handlePeriod }: HistoryPeriodProps) {
className={`py-3 px-4 w-20 border-solid border-gray-400
${
period === 'THREE_MONTH'
? 'border-2 border-blue-700 text-blue-800'
? 'border-2 border-blue-600 text-blue-800'
: period === 'SIX_MONTH'
? 'border-y'
: 'border-y border-r'
Expand All @@ -67,7 +67,7 @@ function HistoryPeriod({ period, handlePeriod }: HistoryPeriodProps) {
className={`py-3 px-4 w-20 border-solid border-gray-400
${
period === 'SIX_MONTH'
? 'border-2 border-blue-700 text-blue-800'
? 'border-2 border-blue-600 text-blue-800'
: period === 'TOTAL'
? 'border-y'
: 'border-y border-r'
Expand All @@ -80,7 +80,7 @@ function HistoryPeriod({ period, handlePeriod }: HistoryPeriodProps) {
</div>
<div
className={`py-3 px-4 w-24 border-solid border-gray-400
${period === 'TOTAL' ? 'border-2 border-blue-700 text-blue-800' : 'border-y border-r'}`}
${period === 'TOTAL' ? 'border-2 border-blue-600 text-blue-800' : 'border-y border-r'}`}
onClick={() => {
handlePeriod('TOTAL');
}}
Expand Down
16 changes: 13 additions & 3 deletions packages/client/src/pages/account/waitOrders/WaitOrders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ function WaitOrders() {
<div className="w-[10%]">주문취소</div>
</div>

{waitOrders.reverse().map((waitOrder) => (
<WaitOrderInfo key={waitOrder.tradeId} {...waitOrder} />
))}
{waitOrders.length > 0 ? (
waitOrders
.reverse()
.map((waitOrder) => (
<WaitOrderInfo key={waitOrder.tradeId} {...waitOrder} />
))
) : (
<div className="mt-20 flex justify-center">
<p className="font-semibold text-gray-700">
미체결 주문이 없습니다.
</p>
</div>
)}
</div>
</>
);
Expand Down