1
1
import React , { useState , useEffect } from "react" ;
2
- import { Card , CardContent } from "../../components/ui/card" ;
3
2
import { useNavigate } from "react-router-dom" ;
3
+ import { ContractSummary } from "../ContractDetailsPage/components" ;
4
4
5
5
const positions = [
6
6
{
@@ -21,17 +21,27 @@ const positions = [
21
21
duration : "00:05:00" ,
22
22
isOpen : false ,
23
23
} ,
24
+ {
25
+ id : 3 ,
26
+ type : "Rise" ,
27
+ market : "Volatility 100 (1s) Index" ,
28
+ stake : "10.00 USD" ,
29
+ profit : "+0.00 USD" ,
30
+ duration : "00:05:00" ,
31
+ isOpen : false ,
32
+ } ,
24
33
] ;
25
34
26
35
const PositionsPage : React . FC = ( ) => {
36
+ const navigate = useNavigate ( ) ;
27
37
const [ activeTab , setActiveTab ] = useState < "open" | "closed" > ( "open" ) ;
28
38
const [ swipedCard , setSwipedCard ] = useState < number | null > ( null ) ;
29
39
30
40
const handleTouchStart = ( ) => {
31
41
setSwipedCard ( null ) ;
32
42
} ;
33
43
34
- const handleTouchMove = ( e : React . TouchEvent , id : number ) => {
44
+ const handleTouchMove = ( e : React . TouchEvent < HTMLDivElement > , id : number ) => {
35
45
const touch = e . touches [ 0 ] ;
36
46
if ( touch . clientX < 250 ) {
37
47
setSwipedCard ( id ) ;
@@ -56,13 +66,13 @@ const PositionsPage: React.FC = () => {
56
66
} , [ swipedCard ] ) ;
57
67
58
68
return (
59
- < div className = "flex flex-col flex-1 h-full bg-white" >
69
+ < div className = "flex flex-col flex-1 h-full bg-white" >
60
70
{ /* Tabs */ }
61
71
< div className = "flex sticky top-0 z-10 px-4 bg-white border-b border-border" >
62
72
< button
63
73
className = { `flex-1 py-3 border-b-2 transition-colors ${
64
- activeTab === "open"
65
- ? "border-primary text-primary"
74
+ activeTab === "open"
75
+ ? "border-primary text-primary"
66
76
: "border-transparent text-muted-foreground"
67
77
} `}
68
78
onClick = { ( ) => setActiveTab ( "open" ) }
@@ -71,8 +81,8 @@ const PositionsPage: React.FC = () => {
71
81
</ button >
72
82
< button
73
83
className = { `flex-1 py-3 border-b-2 transition-colors ${
74
- activeTab === "closed"
75
- ? "border-primary text-primary"
84
+ activeTab === "closed"
85
+ ? "border-primary text-primary"
76
86
: "border-transparent text-muted-foreground"
77
87
} `}
78
88
onClick = { ( ) => setActiveTab ( "closed" ) }
@@ -84,51 +94,43 @@ const PositionsPage: React.FC = () => {
84
94
{ /* Positions List */ }
85
95
< div className = "flex-1 overflow-y-auto px-2 pb-4 pt-2 space-y-2 bg-gray-100" >
86
96
{ positions
87
- . filter ( ( position ) => ( activeTab === "open" ? position . isOpen : ! position . isOpen ) )
88
- . map ( ( position ) => {
89
- const navigate = useNavigate ( ) ;
90
- return (
97
+ . filter ( ( position ) =>
98
+ activeTab === "open" ? position . isOpen : ! position . isOpen
99
+ )
100
+ . map ( ( position ) => (
101
+ < div
102
+ key = { position . id }
103
+ className = "relative flex transition-transform duration-300"
104
+ onTouchStart = { handleTouchStart }
105
+ onTouchMove = { ( e ) => handleTouchMove ( e , position . id ) }
106
+ onTouchEnd = { handleTouchEnd }
107
+ onMouseEnter = { ( ) => setSwipedCard ( position . id ) }
108
+ onMouseLeave = { ( ) => setSwipedCard ( null ) }
109
+ >
91
110
< div
92
- key = { position . id }
93
- className = "relative flex transition-transform duration-300"
94
- onTouchStart = { handleTouchStart }
95
- onTouchMove = { ( e ) => handleTouchMove ( e , position . id ) }
96
- onTouchEnd = { handleTouchEnd }
97
- onMouseEnter = { ( ) => setSwipedCard ( position . id ) }
98
- onMouseLeave = { ( ) => setSwipedCard ( null ) }
111
+ className = { `relative flex transition-transform duration-300 w-full cursor-pointer ${
112
+ swipedCard === position . id
113
+ ? "translate-x-[-4rem]"
114
+ : "translate-x-0"
115
+ } `}
116
+ onClick = { ( ) => {
117
+ navigate ( `/contract/${ position . id } ` ) ;
118
+ } }
99
119
>
100
- < div className = { `relative flex transition-transform duration-300 w-full ${ swipedCard === position . id ? "-translate-x-0" : "translate-x-0" } ` } >
101
- < Card className = { `w-full lg:w-full cursor-pointer flex transition-all duration-300 ${
102
- swipedCard === position . id ? "translate-x-[-4rem]" : "translate-x-0"
103
- } `}
104
- onClick = { ( ) => navigate ( `/contract/${ position . id } ` ) }
105
- >
106
- < CardContent className = "p-4 w-full" >
107
- < div className = "flex justify-between" >
108
- < div >
109
- < div className = "text-red-500 font-bold" > { position . type } </ div >
110
- < div className = "text-gray-500 text-sm" > { position . market } </ div >
111
- </ div >
112
- < div className = "text-right" >
113
- < div className = "text-gray-700" > { position . stake } </ div >
114
- < div className = "text-green-500" > { position . profit } </ div >
115
- </ div >
116
- </ div >
117
- < div className = "text-gray-500 text-sm mt-2" > { position . duration } </ div >
118
- </ CardContent >
119
- </ Card >
120
+ < div className = "w-full" >
121
+ < ContractSummary />
122
+ </ div >
120
123
</ div >
121
- < button
122
- className = { `absolute right-0 h-full w-16 bg-red-600 text-white font-bold flex items-center justify-center transition-all duration-300 rounded-tr-lg rounded-br-lg ${
123
- swipedCard === position . id ? "flex" : "hidden"
124
- } `}
125
- onClick = { ( ) => console . log ( "Close action triggered" ) }
126
- >
127
- Close
128
- </ button >
129
- </ div >
130
- ) ;
131
- } ) }
124
+ < button
125
+ className = { `absolute right-0 h-[104px] w-16 bg-red-600 text-xs text-white font-bold flex items-center justify-center transition-all duration-300 rounded-r-lg ${
126
+ swipedCard === position . id ? "flex" : "hidden"
127
+ } `}
128
+ onClick = { ( ) => console . log ( "Close action triggered" ) }
129
+ >
130
+ Close
131
+ </ button >
132
+ </ div >
133
+ ) ) }
132
134
</ div >
133
135
</ div >
134
136
) ;
0 commit comments