Skip to content

Commit

Permalink
resolve: conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Praashh committed Oct 16, 2024
2 parents d321232 + 9a4192f commit 6edab96
Show file tree
Hide file tree
Showing 45 changed files with 1,269 additions and 280 deletions.
91 changes: 81 additions & 10 deletions apps/client/app/(lobby)/event/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,83 @@
"use client"
import React from 'react'
import EventList from "../../components/EventList"
const page = () => {
import { EventCard } from "@/components/EventCard";

const Page = () => {
const events = [
{
icon: "/assets/event1.png",
traders: 31823,
question: "Centre to constitute the 8th Pay Commission?",
yesValue: 4,
noValue: 6,
},
{
icon: "/assets/event2.png",
traders: 6410,
question:
"Kane Williamson to announce his retirement from international T20 cricket?",
yesValue: 4.5,
noValue: 5.5,
},
{
icon: "/assets/event3.png",
traders: 7467,
question:
"Tesla to open their first showroom in India by the end of 2024?",
yesValue: 2.5,
noValue: 7.5,
},
{
icon: "/assets/event4.png",
traders: 1367,
question: "Red Bull Racing to win the F1 Constructors Championship 2024?",
yesValue: 5,
noValue: 5,
},
{
icon: "/assets/event1.png",
traders: 31823,
question: "Centre to constitute the 8th Pay Commission?",
yesValue: 4,
noValue: 6,
},
{
icon: "/assets/event2.png",
traders: 6410,
question:
"Kane Williamson to announce his retirement from international T20 cricket?",
yesValue: 4.5,
noValue: 5.5,
},
{
icon: "/assets/event3.png",
traders: 7467,
question:
"Tesla to open their first showroom in India by the end of 2024?",
yesValue: 2.5,
noValue: 7.5,
},
{
icon: "/assets/event4.png",
traders: 1367,
question: "Red Bull Racing to win the F1 Constructors Championship 2024?",
yesValue: 5,
noValue: 5,
},
];

return (
<div>
<EventList/>
</div>
)
}
<>
<div className="w-full lg:w-full p-8 flex justify-center items-center">
{/* Events Grid Section */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-2 gap-8 lg:w-1/2 w-full mt-8 lg:mt-0 overflow-y-auto">
{events.map((event, index) => (
<EventCard key={index} {...event} />
))}
</div>
</div>

</>
);
};


export default page
export default Page;
22 changes: 0 additions & 22 deletions apps/client/app/(lobby)/event/recharge/page.tsx

This file was deleted.

235 changes: 97 additions & 138 deletions apps/client/app/(lobby)/portfolio/page.tsx
Original file line number Diff line number Diff line change
@@ -1,147 +1,106 @@
"use client";
import React, { useCallback, useEffect, useState } from "react";
import { useSession } from "next-auth/react";
import { redirect } from "next/navigation";
import { getTrades } from "@/actions/Trade/getTrades";
import Portfolio from "../../../components/landing/Portfolio";
import { getEventDetails } from "@/actions/Event/getEventDetails";
import axios from "axios";
import { toast, Toaster } from "react-hot-toast";

export interface Trade {
id: string;
createdAt: Date;
portfolioId: string;
eventId: string;
price: number;
quantity: number;
side: "YES" | "NO";
title?: string;
gainloss: number | null;
status: "ACTIVE" | "PAST";
}
export interface Portfolio {
id: string;
userId: string;
currentBalances: number;
createdAt: Date;
updatedAt: Date;
trades: Trade[];
}
const Page = () => {
const [loading, setLoading] = useState<boolean>(true);
const [portfolioData, setPortfolioData] = useState<Portfolio | null>(null);
const [tradesWithTitles, setTradesWithTitles] = useState<Trade[]>([]);

const { data } = useSession();
console.log(data?.user);

useEffect(() => {
if (!data?.user) {
redirect("/api/auth/signin");
}
}, [data?.user]);
const userId = data?.user.id;

useEffect(() => {
if (userId) {
getPortfolioDetails(userId);
}
}, [userId]);

const { status } = useSession();
import React, { useState } from "react";
import { PortfolioSummary } from "@/components/PortfolioSummary";

const getPortfolioDetails = useCallback(async (userId: string) => {
setLoading(true);
try {
const portfolio = await getTrades(userId);
console.log("portfolio", portfolio);

setPortfolioData(portfolio);
if (portfolio) {
const updatedTrades = await fetchTitles(portfolio.trades);
setTradesWithTitles(updatedTrades);
}
} catch (e) {
console.log("Error fetching portfolio", e);
} finally {
setLoading(false);
}
}, []);

useEffect(() => {
if (status === "unauthenticated") {
redirect("/api/auth/signin");
}
if (status === "authenticated" && userId) {
getPortfolioDetails(userId);
}
}, [status, userId, getPortfolioDetails]);
const Page = () => {
const [activeTab, setActiveTab] = useState<string>("active");
const [returns, setReturns] = useState<number>(-268.65);
const [investment, setInvestment] = useState<number>(2096);
const [todayReturns, setTodayReturns] = useState<number>(0);
const [rank, setRank] = useState<number>(25750902);

async function fetchTitles(trades: Trade[]) {
const titles = await Promise.all(
trades.map(async (trade) => {
const event = await getEventDetails(trade.eventId);
return {
...trade,
title: event.title,
};
})
);
return titles;
}
const handleExit = async (tradeId: string) => {
if (window.confirm("Are you sure you want to sell your order")) {
try {
const tradeToSell = tradesWithTitles.find(
(trade) => trade.id == tradeId
);
if (tradeToSell) {
const response = await axios.post(
`${process.env.NEXT_PUBLIC_API_PREFIX_URL}/v1/order/sell-order`,
{
tradeId: tradeToSell.id,
eventId: tradeToSell.eventId,
price: tradeToSell.price,
quantity: tradeToSell.quantity,
side: tradeToSell.side == "YES" ? "yes" : "no",
}
);
toast.success(response.data.message || "Order sold successfully!");
} else {
toast.error("Trade not found.");
}
} catch (error) {
console.error("Error selling order", error);
toast.error("Failed to sell order.");
}
}
};
if (loading) {
return <div>Loading...</div>;
}
if (!portfolioData) {
return <div>No portfolio found.</div>;
}
const { currentBalances } = portfolioData;
const trades = [
{
icon: "/assets/event1.png",
question: "Centre to constitute the 8th Pay Commission?",
investment: 10,
returns: -10,
},
{
icon: "/assets/event2.png",
question:
"Kane Williamson to announce his retirement from international T20 cricket?",
investment: 10,
returns: 2.33,
},
{
icon: "/assets/event3.png",
question:
"Tesla to open their first showroom in India by the end of 2024?",
investment: 10,
returns: 11.73,
},
{
icon: "/assets/event4.png",
question: "Red Bull Racing to win the F1 Constructors Championship 2024?",
investment: 10,
returns: 5.86,
},
];

return (
<div className="w-full h-screen">
<Portfolio
currentReturns={currentBalances}
onExit={handleExit}
trades={tradesWithTitles.map((trade) => ({
id: trade.id,
title: trade.title || "Unknown Title",
price: trade.price,
quantity: trade.quantity,
type: trade.side,
gainloss: trade.gainloss,
status: trade.status,
}))}
/>
<Toaster position="top-center" />
</div>
<>
<div className="max-w-4xl mx-auto p-4">
<div className="flex justify-center mb-4 border-b">
<button
className={`px-4 py-2 ${activeTab === "active" ? "font-bold border-b-2 border-black" : ""}`}
onClick={() => setActiveTab("active")}
>
Active trades
</button>
<button
className={`px-4 py-2 ${activeTab === "closed" ? "font-bold border-b-2 border-black" : ""}`}
onClick={() => setActiveTab("closed")}
>
Closed trades
</button>
</div>
<PortfolioSummary
returns={returns}
investment={investment}
todayReturns={todayReturns}
rank={rank}
/>

<div className="overflow-x-auto">
<table className="min-w-full table-auto">
<thead>
<tr className="bg-gray-100 text-sm font-semibold">
<th className="px-4 py-4 text-left">Event</th>
<th className="px-2 py-4 text-left sm:px-4">Investment</th>
<th className="px-2 py-4 text-left sm:px-4">Returns</th>
<th className="px-2 py-4 text-left sm:px-4">Action</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200 bg-white rounded-lg">
{trades.map((trade, index) => (
<tr key={index} className="border-b">
<td className="px-4 py-6 flex items-center text-xs sm:text-sm">
<img src={trade.icon} alt="Icon" className="h-6 w-6 mr-2" />
<span className="line-clamp-2">{trade.question}</span>
</td>
<td className="px-2 py-6 sm:px-4">{trade.investment}</td>
<td
className={`px-2 py-6 sm:px-4 ${trade.returns >= 0 ? "text-green-500" : "text-red-500"}`}
>
{trade.returns}
</td>
<td className="px-2 py-6 sm:px-4">
<button
onClick={() => {}}
className="border px-3 py-1 rounded-full text-xs"
>
View
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</>
);
};

Expand Down
Loading

0 comments on commit 6edab96

Please sign in to comment.