11import { API_URL } from '@/env'
2- import { formatNearAmount } from '@/lib/utils'
32import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query'
4- import { useMemo } from 'react'
53import LogOutIcon from '../assets/log-out'
64import NEAR_ICON from '../assets/near-gray.svg'
7- import { Balance , RewardAmount , TXenUser } from '../types'
5+ import { Balance , TXenUser } from '../types'
86import HistoryMainPageModule from './HistoryMainPageModule'
97import Spinner from './Spinner'
108
11- const WALLET_URL = 'https://app.mynearwallet.com/' // ToDo: hardcode
12-
139const queryFn = ( name : string , isLoggedIn ?: boolean ) => async ( ) => {
1410 if ( isLoggedIn === false ) return
1511 if ( ! window . Telegram . WebApp . initData ) {
@@ -73,11 +69,6 @@ const Wallet = () => {
7369 queryFn : queryFn ( 'getBalance' , isLoggedIn ) ,
7470 } )
7571
76- const { data : rewardAmount } = useQuery < RewardAmount > ( {
77- queryKey : [ 'reward-amount' ] ,
78- queryFn : queryFn ( 'getRewardAmount' ) ,
79- } )
80-
8172 const handleLogout = useMutation ( {
8273 mutationFn : mutationFn ( 'logout' ) ,
8374 onSuccess : ( ) => {
@@ -94,60 +85,28 @@ const Wallet = () => {
9485 } ,
9586 } )
9687
97- const amountInNearRounded = useMemo ( ( ) => {
98- if ( ! rewardAmount ?. total ) return null
99- const amountInNear = formatNearAmount ( rewardAmount . total )
100- return amountInNear . slice ( 0 , amountInNear . indexOf ( '.' ) + 4 )
101- } , [ rewardAmount ?. total ] )
102-
103- const availableToClaimRounded = useMemo ( ( ) => {
104- if ( ! rewardAmount ?. availableToClaim ) return null
105- const amountInNear = formatNearAmount ( rewardAmount . availableToClaim )
106- return amountInNear . slice ( 0 , amountInNear . indexOf ( '.' ) + 4 )
107- } , [ rewardAmount ?. availableToClaim ] )
108-
10988 return user && isLoggedIn ? (
110- < div className = "z-1 flex w-full flex-col gap-1 overflow-hidden rounded-xl border border-(--color-opposite-text) p-2.5 backdrop-blur-3xl backdrop-opacity-80 dark:border-(--color-main-text)/30" >
111- < div className = "ms-5 me-1 flex items-center justify-between gap-3 py-0.5 text-[22px]/7 font-normal wrap-anywhere" >
89+ < div className = "z-1 flex w-full flex-wrap items-center justify-between gap-2.5 overflow-hidden rounded-xl border border-(--color-opposite-text) p-2.5 backdrop-blur-3xl backdrop-opacity-80 dark:border-(--color-main-text)/30" >
90+ < div className = "flex shrink-0 justify-between gap-3 text-[22px]/[150%] font-semibold" >
91+ < img src = { NEAR_ICON } alt = "near" />
92+ { balance ?. formatted . available ?? '-' }
93+ </ div >
94+ < div className = "me-1 flex items-center justify-between gap-3 text-[22px]/[150%] font-normal wrap-anywhere" >
11295 < a
113- href = { WALLET_URL }
96+ href = "https://app.mynearwallet.com/"
11497 target = "_blank"
11598 rel = "noreferrer"
11699 className = "cursor-pointer underline decoration-(--color-current-mix-50) underline-offset-[3px] transition hover:decoration-(--color-current-mix-20) focus:decoration-(--color-current-mix-20)"
117100 >
118101 { user . nearAccountId }
119102 </ a >
120103 < button
121- className = "flex cursor-pointer p-1 text-(--color-gray-text) transition hover:text-(--color-main-text)"
104+ className = "flex cursor-pointer p-1.5 text-(--color-gray-text) transition hover:text-(--color-main-text)"
122105 onClick = { ( ) => handleLogout . mutate ( ) }
123106 >
124107 < LogOutIcon />
125108 </ button >
126109 </ div >
127- < div className = "flex shrink-0 flex-wrap items-center justify-between gap-x-2.5 gap-y-0" >
128- < div className = "flex shrink-0 gap-2 text-[22px]/normal font-semibold" >
129- < img src = { NEAR_ICON } alt = "near" />
130- { balance ?. formatted . available ?? '-' }
131- </ div >
132- < div className = "flex shrink-0 flex-col text-xs/tight font-semibold text-(--color-gray-text)" >
133- < div className = "flex gap-1" >
134- Total revenue:{ ' ' }
135- < span className = "text-(--color-my-primary)" >
136- { amountInNearRounded && amountInNearRounded !== '0' ? `+${ amountInNearRounded } ` : '0' }
137- </ span > { ' ' }
138- < img className = "w-2.5" src = { NEAR_ICON } alt = "near" />
139- </ div >
140- < div className = "flex gap-1" >
141- Available to claim:{ ' ' }
142- < span className = "text-(--color-my-primary)" >
143- { availableToClaimRounded && availableToClaimRounded !== '0'
144- ? `+${ availableToClaimRounded } `
145- : '0' }
146- </ span > { ' ' }
147- < img className = "w-2.5" src = { NEAR_ICON } alt = "near" />
148- </ div >
149- </ div >
150- </ div >
151110 < HistoryMainPageModule />
152111 </ div >
153112 ) : (
@@ -156,40 +115,7 @@ const Wallet = () => {
156115 < Spinner />
157116 ) : (
158117 < div className = "flex w-full items-center justify-between" >
159- < div className = "flex shrink-0 flex-col gap-1 text-xs/tight font-semibold text-(--color-gray-text)" >
160- { availableToClaimRounded && availableToClaimRounded !== '0' ? (
161- < >
162- < div className = "flex flex-col text-sm text-(--color-main-text)" >
163- < p > Available to claim:</ p >
164- < div className = "flex gap-1 text-2xl/tight" >
165- < p className = "text-(--color-my-primary)" > { `+${ availableToClaimRounded } ` } </ p >
166- < img className = "w-4" src = { NEAR_ICON } alt = "near" />
167- </ div >
168- </ div >
169- < div className = "flex gap-1" >
170- Total revenue:{ ' ' }
171- < span className = "text-(--color-my-primary)" >
172- { amountInNearRounded && amountInNearRounded !== '0'
173- ? `+${ amountInNearRounded } `
174- : '0' }
175- </ span > { ' ' }
176- < img className = "w-2.5" src = { NEAR_ICON } alt = "near" />
177- </ div >
178- </ >
179- ) : (
180- < div className = "flex flex-col text-sm text-(--color-main-text)" >
181- < p > Total revenue:</ p >
182- < div className = "flex gap-1 text-2xl/tight" >
183- < p className = "text-(--color-my-primary)" >
184- { amountInNearRounded || amountInNearRounded !== '0'
185- ? `+${ amountInNearRounded } `
186- : '0' }
187- </ p >
188- < img className = "w-4" src = { NEAR_ICON } alt = "near" />
189- </ div >
190- </ div >
191- ) }
192- </ div >
118+ < div className = "text-[18px]/[150%] font-semibold" > No wallet connected</ div >
193119 < button
194120 className = "flex w-[118px] cursor-pointer flex-nowrap items-center justify-center rounded-xl bg-(--color-my-primary) py-2 text-(--color-opposite-text) dark:bg-[#f8f9ff] dark:text-(--color-opposite-text)"
195121 onClick = { ( ) => handleLogin . mutate ( ) }
0 commit comments