Skip to content

Commit

Permalink
Add some mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
lq0-github committed Mar 1, 2024
1 parent aacb61a commit 22732d5
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 177 deletions.
160 changes: 2 additions & 158 deletions screens/MarginTrading/components/MyTrading/MyTradingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import React, { useState } from "react";
import Link from "next/link";
import { AddCollateral, Export } from "../Icon";
import TradingTable from "../../../Trading/components/Table";

const MyMarginTradingPage = () => {
const [selectedTab, setSelectedTab] = useState("positions");

const handleTabClick = (tabNumber) => {
setSelectedTab(tabNumber);
};
return (
<div className="flex flex-col items-center justify-center w-full">
<div className="flex justify-between items-center w-full h-[100px] border border-dark-50 bg-gray-800 rounded-md mb-7">
Expand Down Expand Up @@ -36,159 +30,9 @@ const MyMarginTradingPage = () => {
</div>
</div>
</div>
<div className="w-full border border-dark-50 bg-gray-800 rounded-md">
<div className="w-full border-b border-dark-50 flex">
<Tab
tabName="Positions"
isSelected={selectedTab === "positions"}
onClick={() => handleTabClick("positions")}
/>
<Tab
tabName="History"
isSelected={selectedTab === "history"}
onClick={() => handleTabClick("history")}
/>
</div>
<div className="py-4">
{selectedTab === "positions" && (
<table className="w-full text-left">
<thead>
<tr className="text-gray-300 text-sm font-normal">
<th className="pl-5">Market</th>
<th>Size</th>
<th>Net Value</th>
<th>Collateral</th>
<th>Entry Price</th>
<th>Index Price</th>
<th>Liq. Price</th>
<th>PLN & ROE</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<Link href="/trading">
<tr className="text-base hover:bg-dark-100 cursor-pointer font-normal">
<td className="py-5 pl-5 ">
NEAR/USDC.e <span className="text-primary text-xs">Long 1.5X</span>
</td>
<td>$149.35</td>
<td>$100</td>
<td>
<div className="flex items-center">
<p className="mr-2.5"> 100 USDC.e </p>
<AddCollateral />
</div>
</td>
<td>$3.25</td>
<td>$3.24</td>
<td>$1.23</td>
<td>
<div className="flex items-center">
<p className="text-gray-1000"> +$0.2248</p>
<span className="text-gray-400 text-xs">(+0.01%)</span>
</div>
</td>
<td className="pr-5">
<div className="text-gray-300 text-sm border border-dark-300 text-center h-6 rounded flex justify-center items-center">
Close
</div>
</td>
</tr>
</Link>
{/* <tr className="text-base hover:bg-dark-100 cursor-pointer font-normal">
<td className="py-5 pl-5 ">
NEAR/USDC.e <span className="text-red-50 text-xs">Short 1.5X</span>
</td>
<td>$149.35</td>
<td>$100</td>
<td>
<div className="flex items-center">
<p className="mr-2.5"> 100 USDC.e </p>
<AddCollateral />
</div>
</td>
<td>$3.25</td>
<td>$3.24</td>
<td>$1.23</td>
<td>
<div className="flex items-center">
<p className="text-red-150"> -$0.0689</p>
<span className="text-gray-400 text-xs">(-2.01%)</span>
</div>
</td>
<td className="pr-5">
<div className="text-gray-300 text-sm border border-dark-300 text-center h-6 rounded flex justify-center items-center">
Close
</div>
</td>
</tr> */}
</tbody>
</table>
)}
{selectedTab === "history" && (
<table className="w-full text-left">
<thead>
<tr className="text-gray-300 text-sm font-normal">
<th className="pl-5">Market</th>
<th>Operation</th>
<th>Side</th>
<th>Price</th>
<th>Amount</th>
<th>Fee</th>
<th>Realized PNL & ROE</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<Link href="/trading">
<tr className="text-base hover:bg-dark-100 cursor-pointer font-normal">
<td className="py-5 pl-5 ">NEAR/USDC.e</td>
<td>Open Short</td>
<td className="text-red-50">Sell</td>
<td>$3.24</td>
<td>100 NEAR</td>
<td>$1.80</td>
<td>--</td>
<td className="pr-5">
<div>
2024-01-16, 13:23
{/* <Export /> */}
</div>
</td>
</tr>
</Link>
{/* <tr className="text-base hover:bg-dark-100 cursor-pointer font-normal">
<td className="py-5 pl-5 ">NEAR/USDC.e</td>
<td>Open Short</td>
<td className="text-primary">Buy</td>
<td>$3.24</td>
<td>45.2435 NEAR</td>
<td>$0.89</td>
<td>--</td>
<td className="pr-5">
<div>
2024-01-16, 13:23 */}
{/* <Export /> */}
{/* </div>
</td>
</tr> */}
</tbody>
</table>
)}
</div>
</div>
<TradingTable />
</div>
);
};
const Tab = ({ tabName, isSelected, onClick }) => (
<div
className={`pt-6 pl-10 pb-4 pr-7 text-gray-300 text-lg cursor-pointer ${
isSelected ? "border-b-2 border-primary text-white" : ""
}`}
onClick={onClick}
>
{tabName}
</div>
);

export default MyMarginTradingPage;
211 changes: 211 additions & 0 deletions screens/Trading/components/ChangeCollateralMobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { useState, createContext } from "react";
import { Modal as MUIModal, Box, useTheme } from "@mui/material";
import { useAppDispatch } from "../../../redux/hooks";
import { Wrapper } from "../../../components/Modal/style";
import { DEFAULT_POSITION } from "../../../utils/config";
import { CloseIcon } from "../../../components/Modal/svg";
import { RefLogoIcon, RightArrow, RightShoulder } from "./TradingIcon";
import { TestNearIcon } from "../../MarginTrading/components/Icon";

export const ModalContext = createContext(null) as any;
const ChangeCollateralMobile = ({ open, onClose }) => {
const dispatch = useAppDispatch();
const theme = useTheme();
const [selectedCollateralType, setSelectedCollateralType] = useState(DEFAULT_POSITION);
const [ChangeCollateralTab, setChangeCollateralTab] = useState("Add");
const handleChangeCollateralTabClick = (tab) => {
setChangeCollateralTab(tab);
};
const [selectedLever, setSelectedLever] = useState(null);
const handleLeverClick = (value) => {
setSelectedLever(value);
};
const leverData = [
{ label: "25%", value: "25" },
{ label: "50%", value: "50" },
{ label: "75%", value: "75" },
{ label: "Max", value: "Max" },
];

return (
<MUIModal open={open} onClose={onClose}>
<Wrapper
sx={{
"& *::-webkit-scrollbar": {
backgroundColor: theme.custom.scrollbarBg,
},
}}
>
<ModalContext.Provider
value={{
position: selectedCollateralType,
}}
>
<Box sx={{ p: ["20px", "20px"] }}>
<div className="flex items-center justify-between">
<div className="flex items-center justify-center">
<p className="text-lg mr-2">Change Collateral</p>
<div className="bg-opacity-10 text-xs py-0.5 pl-2.5 pr-1.5 rounded bg-primary text-primary ">
Long NEAR
</div>
</div>
<div className="cursor-pointer">
<CloseIcon onClick={onClose} />
</div>
</div>
<div className="flex justify-center items-center border-b border-dark-700 -mx-5 -px-5 mt-6 px-5">
<div
className={`py-2 w-1/2 text-center cursor-pointer text-gray-300 text-lg ${
ChangeCollateralTab === "Add" ? "text-primary border-b border-primary" : ""
}`}
onClick={() => handleChangeCollateralTabClick("Add")}
>
Add
</div>
<div
className={`pb-3.5 w-1/2 text-center cursor-pointer text-gray-300 text-lg ${
ChangeCollateralTab === "Remove" ? "text-red-50 border-b border-red-50" : ""
}`}
onClick={() => handleChangeCollateralTabClick("Remove")}
>
Remove
</div>
</div>
<div className="mt-4">
{ChangeCollateralTab === "Add" && (
<div className="py-2">
<div className=" bg-dark-600 border border-dark-500 pt-3 pb-2.5 pr-3 pl-2.5 rounded-md flex items-center justify-between mb-1.5">
<div>
<input type="text" value={0} />
<p className="text-gray-300 text-xs mt-1.5">Add: $0.00</p>
</div>
<div>
<div className="flex items-center justify-end">
<TestNearIcon />
<p className="text-base ml-1">USDC</p>
</div>
<p className="text-xs text-gray-300 mt-1.5">
Max Available: <span className="text-white">123.23</span>
</p>
</div>
</div>
<div className="flex items-center justify-end mb-7">
{leverData.map((item, index) => (
<div
key={index}
className={`bg-dark-600 border border-dark-500 py-1 px-2 rounded-md text-xs text-gray-300 mr-2 cursor-pointer hover:bg-gray-700 ${
selectedLever === item.value ? "bg-gray-700" : ""
}`}
onClick={() => handleLeverClick(item.value)}
>
{item.label}
</div>
))}
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Position Size</div>
<div>
45.2435 NEAR
<span className="text-xs text-gray-300 ml-1.5">($149.35)</span>
</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Collateral (USDC)</div>
<div>$1.23</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Leverage</div>
<div>1.5X</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Entry Price</div>
<div>$3.23</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Liq. Price</div>
<div>$1.78</div>
</div>
<div className="flex items-center bg-primary justify-between text-dark-200 text-base rounded-md h-12 text-center cursor-pointer">
<div className="flex-grow">Add Collateral</div>
</div>
</div>
)}
{ChangeCollateralTab === "Remove" && (
<div className="py-2">
<div className=" bg-dark-600 border border-dark-500 pt-3 pb-2.5 pr-3 pl-2.5 rounded-md flex items-center justify-between mb-1.5">
<div>
<input type="text" value={0} />
<p className="text-gray-300 text-xs mt-1.5">Add: $0.00</p>
</div>
<div>
<div className="flex items-center justify-end">
<TestNearIcon />
<p className="text-base ml-1">USDC</p>
</div>
<p className="text-xs text-gray-300 mt-1.5">
Max Available: <span className="text-white">123.23</span>
</p>
</div>
</div>
<div className="flex items-center justify-end mb-7">
{leverData.map((item, index) => (
<div
key={index}
className={`bg-dark-600 border border-dark-500 py-1 px-2 rounded-md text-xs text-gray-300 mr-2 cursor-pointer hover:bg-gray-700 ${
selectedLever === item.value ? "bg-gray-700" : ""
}`}
onClick={() => handleLeverClick(item.value)}
>
{item.label}
</div>
))}
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Position Size</div>
<div>
45.2435 NEAR
<span className="text-xs text-gray-300 ml-1.5">($149.35)</span>
</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Collateral</div>
<div className="flex items-center justify-center">
<span className="text-gray-300 mr-2 line-through">$101.23</span>
<RightArrow />
<p className="ml-2">$1.23</p>
</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Leverage</div>
<div className="flex items-center justify-center">
<span className="text-gray-300 mr-2 line-through">1.1X</span>
<RightArrow />
<p className="ml-2">1.5X</p>
</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Entry Price</div>
<div>$3.23</div>
</div>
<div className="flex items-center justify-between text-sm mb-4">
<div className="text-gray-300">Liq. Price</div>
<div className="flex items-center justify-center">
<span className="text-gray-300 mr-2 line-through">$1.78</span>
<RightArrow />
<p className="ml-2">$3.02</p>
</div>
</div>
<div className="flex items-center bg-red-50 justify-between text-dark-200 text-base rounded-md h-12 text-center cursor-pointer">
<div className="flex-grow">Remove Collateral</div>
</div>
</div>
)}
</div>
</Box>
</ModalContext.Provider>
</Wrapper>
</MUIModal>
);
};

export default ChangeCollateralMobile;
Loading

0 comments on commit 22732d5

Please sign in to comment.