1
1
"use client" ;
2
2
3
3
import { Footer } from "@/components/footer" ;
4
- import { LoginPopover } from "@/components/login-popover" ;
5
- import { Logo } from "@/components/logo" ;
6
- import ProfileDropdown from "@/components/profile-dropdown" ;
7
- import { Button , IconButton , TopBar , Typography } from "@mochi-ui/core" ;
4
+ import { Button , IconButton , Typography } from "@mochi-ui/core" ;
8
5
import { EyeHiddenSolid , EyeShowSolid } from "@mochi-ui/icons" ;
9
6
import { useLoginWidget } from "@mochi-web3/login-widget" ;
10
- import Image from "next/image" ;
11
7
import { Suspense , useEffect , useState } from "react" ;
12
8
import { FlexibleStakingCard } from "@/components/overview/FlexibleStakingCard" ;
13
9
import { FixedStakingCard } from "@/components/overview/FixedStakingCard" ;
14
10
import { NFTCard } from "@/components/overview/NFTCard" ;
15
11
import { useFlexibleStaking } from "@/store/flexible-staking" ;
16
12
import { utils } from "@consolelabs/mochi-formatter" ;
17
13
import { useTokenStaking } from "@/store/token-staking" ;
14
+ import { formatUnits , parseUnits } from "ethers/lib/utils" ;
15
+ import clsx from "clsx" ;
16
+ import { TokenImage } from "@/components/token-image" ;
17
+ import { Header } from "@/components/header/header" ;
18
18
19
19
const Overview = ( ) => {
20
20
const { isLoggedIn } = useLoginWidget ( ) ;
21
- const [ showInfo , setShowInfo ] = useState ( true ) ;
22
- const { balance, stakedAmount, totalEarnedRewards, tokenPrice } =
23
- useFlexibleStaking ( ) ;
24
- const { fetchStakingTokens } = useTokenStaking ( ) ;
21
+ const { stakingPools, fetchStakingPools } = useTokenStaking ( ) ;
22
+ const {
23
+ balance,
24
+ stakedAmount,
25
+ totalEarnedRewards,
26
+ stakingToken,
27
+ rewardToken,
28
+ } = useFlexibleStaking ( ) ;
29
+ const [ showInfo , setShowInfo ] = useState ( false ) ;
25
30
26
31
useEffect ( ( ) => {
27
- fetchStakingTokens ( ) ;
28
- } , [ fetchStakingTokens ] ) ;
32
+ fetchStakingPools ( ) ;
33
+ } , [ fetchStakingPools ] ) ;
34
+
35
+ useEffect ( ( ) => {
36
+ if ( ! ! balance && ! showInfo ) {
37
+ setShowInfo ( true ) ;
38
+ }
39
+ } , [ balance , showInfo ] ) ;
29
40
30
41
return (
31
42
< div className = "overflow-y-auto h-[calc(100vh-56px)]" >
32
43
< div className = "max-w-6xl pt-12 pb-16 px-4 mx-auto space-y-14" >
33
44
< div className = "flex gap-8 flex-col lg:flex-row items-center lg:items-start" >
34
- { isLoggedIn ? (
45
+ { ! isLoggedIn ? (
46
+ < Typography level = "h3" fontWeight = "lg" className = "flex-1 pb-3" >
47
+ Log in to see your available assets to stake
48
+ </ Typography >
49
+ ) : balance . isZero ( ) ? (
50
+ < Typography level = "h3" fontWeight = "lg" className = "flex-1 pb-3" >
51
+ You don't have available assets to stake in your wallet.
52
+ </ Typography >
53
+ ) : (
35
54
< Typography level = "h3" fontWeight = "lg" className = "flex-1" >
36
55
You have{ " " }
37
56
< span className = "text-primary-solid" >
38
- { showInfo ? utils . formatTokenDigit ( balance ) : "*****" }
39
- </ span > { " " }
40
- ICY and{ " " }
41
- < span className = "text-danger-solid" >
42
- { showInfo ? utils . formatTokenDigit ( 0 ) : "*****" }
43
- </ span > { " " }
44
- DFG and{ " " }
45
- < span className = "text-success-solid" >
46
- { utils . formatTokenDigit ( 0 ) }
57
+ { showInfo
58
+ ? utils . formatTokenDigit (
59
+ formatUnits ( balance , stakingToken ?. token_decimal )
60
+ )
61
+ : "*****" }
47
62
</ span > { " " }
48
- assets across < span className = "text-secondary-solid" > 1</ span > { " " }
49
- networks available to stake.
50
- </ Typography >
51
- ) : (
52
- < Typography level = "h3" fontWeight = "lg" className = "flex-1 pb-3" >
53
- Log in to see your available assets to stake
63
+ { stakingToken ?. token_symbol } across{ " " }
64
+ < span className = "text-secondary-solid" > 1</ span > networks available
65
+ to stake.
54
66
</ Typography >
55
67
) }
56
68
{ isLoggedIn && (
@@ -88,13 +100,28 @@ const Overview = () => {
88
100
</ Typography >
89
101
< Typography level = "h6" fontWeight = "lg" >
90
102
{ showInfo
91
- ? utils . formatUsdDigit ( stakedAmount * tokenPrice )
103
+ ? utils . formatUsdDigit (
104
+ formatUnits (
105
+ stakedAmount
106
+ . mul (
107
+ parseUnits (
108
+ String ( stakingToken ?. token_price || 1 )
109
+ )
110
+ )
111
+ . div ( parseUnits ( "1" ) ) ,
112
+ stakingToken ?. token_decimal
113
+ )
114
+ )
92
115
: "*********" }
93
116
</ Typography >
94
117
</ div >
95
118
< div className = "flex items-center space-x-1 ml-2" >
96
- < Image src = "/ICY.png" alt = "icy" width = { 20 } height = { 20 } />
97
- < Image src = "/DFG.png" alt = "dfg" width = { 20 } height = { 20 } />
119
+ { stakingPools . map ( ( each ) => (
120
+ < TokenImage
121
+ key = { each . guild_id }
122
+ symbol = { each . staking_token . token_symbol }
123
+ />
124
+ ) ) }
98
125
</ div >
99
126
</ div >
100
127
< div className = "grid grid-cols-2 gap-6 items-center py-3" >
@@ -104,7 +131,18 @@ const Overview = () => {
104
131
</ Typography >
105
132
< Typography level = "h6" fontWeight = "lg" color = "success" >
106
133
{ showInfo
107
- ? utils . formatUsdDigit ( totalEarnedRewards * tokenPrice )
134
+ ? utils . formatUsdDigit (
135
+ formatUnits (
136
+ totalEarnedRewards
137
+ . mul (
138
+ parseUnits (
139
+ String ( rewardToken ?. token_price || 1 )
140
+ )
141
+ )
142
+ . div ( parseUnits ( "1" ) ) ,
143
+ rewardToken ?. token_decimal
144
+ )
145
+ )
108
146
: "********" }
109
147
</ Typography >
110
148
</ div >
@@ -120,10 +158,21 @@ const Overview = () => {
120
158
</ div >
121
159
) }
122
160
</ div >
123
- < div className = "grid grid-cols-1 md:grid-cols-4 lg:grid-cols-3 w-fit mx-auto gap-4 md:[&>*]:col-span-2 md:[&>*:last-child]:col-start-2 lg:[&>*]:col-span-1 lg:[&>*:last-child]:col-start-auto" >
124
- < FlexibleStakingCard hidden = { isLoggedIn && ! showInfo } />
125
- < FixedStakingCard hidden = { isLoggedIn && ! showInfo } />
126
- < NFTCard hidden = { isLoggedIn && ! showInfo } />
161
+ < div
162
+ className = { clsx ( "grid grid-cols-1 mx-auto gap-4" , {
163
+ "md:grid-cols-2" : stakingPools . length >= 2 ,
164
+ "lg:grid-cols-3" : stakingPools . length >= 3 ,
165
+ } ) }
166
+ >
167
+ { stakingPools . some ( ( each ) => each . type === "flexible" ) && (
168
+ < FlexibleStakingCard hidden = { isLoggedIn && ! showInfo } />
169
+ ) }
170
+ { stakingPools . some ( ( each ) => each . type === "fixed" ) && (
171
+ < FixedStakingCard hidden = { isLoggedIn && ! showInfo } />
172
+ ) }
173
+ { stakingPools . some ( ( each ) => each . type === "nft" ) && (
174
+ < NFTCard hidden = { isLoggedIn && ! showInfo } />
175
+ ) }
127
176
</ div >
128
177
</ div >
129
178
< Footer />
@@ -132,14 +181,9 @@ const Overview = () => {
132
181
} ;
133
182
134
183
export default function Page ( ) {
135
- const { isLoggedIn } = useLoginWidget ( ) ;
136
-
137
184
return (
138
185
< main >
139
- < TopBar
140
- leftSlot = { < Logo /> }
141
- rightSlot = { ! isLoggedIn ? < LoginPopover /> : < ProfileDropdown /> }
142
- />
186
+ < Header />
143
187
< Suspense >
144
188
< Overview />
145
189
</ Suspense >
0 commit comments