@@ -6,11 +6,21 @@ import Image from "next/image";
66import { useState } from "react" ;
77import { useEffect } from "react" ;
88import { Container } from "@mui/material" ;
9+ import { useMetamaskAuth } from "../../auth/authConfig" ;
10+ import Loader from "../Loader/Loader" ;
11+ import { getUsdtBalance , getMaticBalance } from "../../apis/balances" ;
912const https = require ( "https" ) ;
1013
14+
15+ const randPriceFluctuations = range => Number ( ( Math . random ( ) * ( range * 2 + 1 ) - range ) . toFixed ( 2 ) ) ;
16+
1117const DashLeft = ( ) => {
12- const [ maticVal , setMaticVal ] = useState ( { } ) ;
13- const [ usdVal , setUsdVal ] = useState ( { } ) ;
18+ const [ maticVal , setMaticVal ] = useState ( { rate : 1500 + randPriceFluctuations ( 3 ) } ) ;
19+ const [ usdVal , setUsdVal ] = useState ( { rate : 1 + Number ( ( randPriceFluctuations ( 1 ) / 100 ) . toFixed ( 2 ) ) } ) ;
20+ const [ maticBalance , setMaticBalance ] = useState ( 0 ) ;
21+ const [ usdtBalance , setUsdtBalance ] = useState ( 0 ) ;
22+ const { profile, isLoggedIn, isProcessingLogin } = useMetamaskAuth ( ) ;
23+
1424 const dummyMatic = "3260.351432121505620812986766" ;
1525 var myHeaders = new Headers ( ) ;
1626 myHeaders . append ( "X-CoinAPI-Key" , "272E2537-42DC-4DE3-BB31-89072ACE051D" ) ;
@@ -22,17 +32,31 @@ const DashLeft = () => {
2232 } ;
2333
2434 useEffect ( ( ) => {
25- fetch ( "https://rest.coinapi.io/v1/exchangerate/BTC/MATIC /" , requestOptions )
26- . then ( ( response ) => response . text ( ) )
27- . then ( ( result ) => setMaticVal ( JSON . parse ( result ) ) )
28- . catch ( ( error ) => console . log ( "error" , error ) ) ;
29-
30- fetch ( "https://rest.coinapi.io/v1/exchangerate/BTC /USD/" , requestOptions )
31- . then ( ( response ) => response . text ( ) )
32- . then ( ( result ) => setUsdVal ( JSON . parse ( result ) ) )
33- . catch ( ( error ) => console . log ( "error" , error ) ) ;
35+ // fetch("https://rest.coinapi.io/v1/exchangerate/ETH/USD /", requestOptions)
36+ // .then((response) => response.text())
37+ // .then((result) => setMaticVal(JSON.parse(result)))
38+ // .catch((error) => console.log("error", error))
39+
40+ // fetch("https://rest.coinapi.io/v1/exchangerate/USDT /USD/", requestOptions)
41+ // .then((response) => response.text())
42+ // .then((result) => setUsdVal(JSON.parse(result)))
43+ // .catch((error) => console.log("error", error))
3444 } , [ ] ) ;
3545
46+ console . log ( maticVal ) ;
47+ console . log ( usdVal ) ;
48+
49+ useEffect ( ( ) => {
50+ if ( ! profile ) return ;
51+ getMaticBalance ( profile . address )
52+ . then ( setMaticBalance ) ;
53+ getUsdtBalance ( profile . address )
54+ . then ( setUsdtBalance ) ;
55+ } , [ profile ] ) ;
56+
57+ if ( ! isLoggedIn || isProcessingLogin || ! profile )
58+ return < Loader size = "80px" />
59+
3660 return (
3761 < div className = "w-[100%] h-[100%] font-inter overflow-auto" style = { { backgroundColor : '#12131A' } } >
3862 { /* PROFILE */ }
@@ -45,32 +69,111 @@ const DashLeft = () => {
4569 height = "50"
4670 style = { { borderRadius : "50px" } }
4771 />
48- < div className = "text-3xl ml-3" > Vansh</ div >
72+ < div className = "text-3xl ml-3" >
73+ { profile . name }
74+ </ div >
75+ </ div >
76+ < div >
77+ { profile . address }
4978 </ div >
50- < div > wallet address</ div >
5179 </ Container >
5280
5381 { /* CARDS */ }
5482 < Container
55- className = "bg-slate-300 m-10 p-5"
83+ className = "bg-slate-300 m-10 p-5 rounded-xl "
5684 style = { {
5785 maxWidth : "90%" ,
5886 backgroundColor : "#1b1e29" ,
59- borderRadius : "20px" ,
87+ // borderRadius: "20px",
6088 color : "#c7cad9" ,
6189 } }
6290 >
6391 < div >
6492 < div className = "flex justify-between" >
93+ < div className = "flex items-center" >
94+ { /* <Image
95+ src={matic}
96+ alt="matic"
97+ width="50"
98+ height="50"
99+ style={{ borderRadius: "50px" }}
100+ /> */ }
101+ < div className = "flex flex-row items-center gap-x-[10px] text-[14px] text-white w-auto h-[50px] p-[5px] px-[8px] rounded-[20px] font-medium pr-[15px] ml-[10px] bg-[#404557]" >
102+ < div className = "flex justify-center w-[40px] h-[40px] rounded-full bg-white p-[4px] box-border" >
103+ < img src = "./assets/matic.svg" alt = "maticLogo" />
104+ </ div >
105+ MATIC
106+ </ div >
107+ { /* <span className="m-2">MATIC</span> */ }
108+ </ div >
109+ < div >
110+ < div style = { { color : "#696c80" } } > Price</ div >
111+ < div >
112+ { maticVal . rate . toFixed ( 2 ) }
113+ </ div >
114+ </ div >
115+ </ div >
116+ < div className = "m-2 text-[#4489ff] text-[12px] overflow-ellipsis overflow-hidden" > </ div >
117+ </ div >
118+ < hr style = { { background : "#C77DFF" , height : "0.05px" } } />
119+
120+ < div >
121+ < div className = "flex justify-between mt-3" >
65122 < div className = "flex" >
66- < Image
123+ { /* <Image
124+ src={usdc}
125+ alt="matic"
126+ width="50"
127+ height="50"
128+ style={{ borderRadius: "50px" }}
129+ /> */ }
130+ < div className = "flex flex-row items-center gap-x-[10px] text-[14px] text-white w-auto h-[50px] p-[5px] px-[8px] rounded-[20px] font-medium pr-[15px] ml-[10px] bg-[#404557]" >
131+ < img className = "w-[40px] h-[40px] rounded-full" src = "./assets/usdc.svg" alt = "usdcLogo" />
132+ USDT
133+ </ div >
134+ { /* <span className="m-2">MATIC</span> */ }
135+ </ div >
136+ < div >
137+ < div > Price</ div >
138+ < div >
139+ { usdVal . rate . toFixed ( 2 ) }
140+ </ div >
141+ </ div >
142+ </ div >
143+ < div className = "m-2 text-[#4489ff] text-[12px] overflow-ellipsis overflow-hidden" > 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270</ div >
144+ </ div >
145+ </ Container >
146+
147+ < Container
148+ className = "bg-slate-300 m-10 p-5 rounded-xl"
149+ style = { {
150+ maxWidth : "90%" ,
151+ backgroundColor : "#1b1e29" ,
152+ // borderRadius: "20px",
153+ color : "#c7cad9" ,
154+ } }
155+ >
156+ < div >
157+ < div className = "flex justify-between mb-5" style = { { color : "#696c80" } } >
158+ < div className = "pl-[28px]" > My tokens</ div >
159+ < div > Current Value</ div >
160+ </ div >
161+ < div className = "flex justify-between mb-4" >
162+ < div className = "flex items-center" >
163+ { /* <Image
67164 src={matic}
68165 alt="matic"
69166 width="50"
70167 height="50"
71168 style={{ borderRadius: "50px" }}
72- />
73- < span className = "m-2" > MATIC</ span >
169+ /> */ }
170+ < div className = "flex flex-row items-center gap-x-[10px] text-[14px] text-white w-auto h-[50px] p-[5px] px-[8px] rounded-[20px] font-medium pr-[15px] ml-[10px] bg-[#404557]" >
171+ < div className = "flex justify-center w-[40px] h-[40px] rounded-full bg-white p-[4px] box-border" >
172+ < img src = "./assets/matic.svg" alt = "maticLogo" />
173+ </ div >
174+ MATIC
175+ </ div >
176+ { /* <span className="m-2">MATIC</span> */ }
74177 </ div >
75178 < div >
76179 < div style = { { color : "#696c80" } } > Price</ div >
@@ -81,21 +184,25 @@ const DashLeft = () => {
81184 </ div >
82185 </ div >
83186 </ div >
84- < div className = "m-2" > code </ div >
187+ { /* <div className="m-2 text-[#4489ff] text-[12px] overflow-ellipsis overflow-hidden">0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270 </div> */ }
85188 </ div >
86189 < hr style = { { background : "#C77DFF" , height : "0.05px" } } />
87190
88191 < div >
89- < div className = "flex justify-between mt-3" >
192+ < div className = "flex justify-between mt-3 mb-2 " >
90193 < div className = "flex" >
91- < Image
194+ { /* <Image
92195 src={usdc}
93196 alt="matic"
94197 width="50"
95198 height="50"
96199 style={{ borderRadius: "50px" }}
97- />
98- < span className = "m-2" > MATIC</ span >
200+ /> */ }
201+ < div className = "flex flex-row items-center gap-x-[10px] text-[14px] text-white w-auto h-[50px] p-[5px] px-[8px] rounded-[20px] font-medium pr-[15px] ml-[10px] bg-[#404557]" >
202+ < img className = "w-[40px] h-[40px] rounded-full" src = "./assets/usdc.svg" alt = "usdcLogo" />
203+ USDC
204+ </ div >
205+ { /* <span className="m-2">MATIC</span> */ }
99206 </ div >
100207 < div >
101208 < div > Price</ div >
@@ -106,12 +213,12 @@ const DashLeft = () => {
106213 </ div >
107214 </ div >
108215 </ div >
109- < div className = "mt-2" > code </ div >
216+ { /* <div className="m-2 text-[#4489ff] text-[12px] overflow-ellipsis overflow-hidden">0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270 </div> */ }
110217 </ div >
111218 </ Container >
112219
113220 { /* User's balance details */ }
114- < Container
221+ { /* <Container
115222 className="bg-slate-300 m-10 rounded-xl p-5 "
116223 style={{
117224 maxWidth: "90%",
@@ -138,14 +245,12 @@ const DashLeft = () => {
138245 </div>
139246 <div>
140247 <div></div>
141- < div >
142- { maticVal . rate !== undefined
143- ? maticVal . rate
144- : Math . round ( dummyMatic ) . toFixed ( 2 ) }
248+ <div className="mt-1">
249+ { maticBalance.toFixed(4) } (${ (maticVal.rate * maticBalance).toFixed(2) })
145250 </div>
146251 </div>
147252 </div>
148- < div className = "m-2" > code </ div >
253+ <div className="m-2 text-[#4489ff] text-[12px] overflow-ellipsis overflow-hidden">0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270 </div>
149254 </div>
150255 <hr style={{ background: "#C77DFF", height: "0.05px" }} />
151256 <div>
@@ -158,19 +263,17 @@ const DashLeft = () => {
158263 height="50"
159264 style={{ borderRadius: "50px" }}
160265 />
161- < span className = "m-2" > MATIC </ span >
266+ <span className="m-2">USDT </span>
162267 </div>
163268 <div>
164- < div >
165- { usdVal . rate !== undefined
166- ? usdVal . rate
167- : Math . round ( dummyMatic ) . toFixed ( 2 ) }
269+ <div className="mt-2">
270+ { usdtBalance.toFixed(2) } (${ (usdVal.rate * usdtBalance).toFixed(2) })
168271 </div>
169272 </div>
170273 </div>
171- < div className = "mt-2" > code </ div >
274+ <div className="mt-2"></div>
172275 </div>
173- </ Container >
276+ </Container> */ }
174277 </ div >
175278 ) ;
176279} ;
0 commit comments