1
1
'use client' ;
2
2
3
- import { useExchangeRates , useOrdinalsMarketcap } from '@/hooks/api' ;
3
+ import {
4
+ useAccountTokens ,
5
+ useExchangeRates ,
6
+ useOrdinalsMarketcap ,
7
+ } from '@/hooks/api' ;
4
8
import type { OverviewProps } from './types' ;
5
9
import * as React from 'react' ;
6
10
import * as S from '@/styles/table' ;
@@ -10,19 +14,28 @@ import CustomPagination from '@/components/custom-pagination';
10
14
11
15
const MotionTableRow = motion ( TableRow ) ;
12
16
13
- export default function AccountOverview ( { tokens } : OverviewProps ) {
17
+ export default function AccountOverview ( { account } : OverviewProps ) {
14
18
const [ page , setPage ] = React . useState ( 0 ) ;
15
19
const rowsPerPage = 5 ;
16
20
const exchangeRatesQuery = useExchangeRates ( ) ;
17
21
const ordinalsMarketcapQuery = useOrdinalsMarketcap ( ) ;
22
+ const accountTokensQuery = useAccountTokens ( { account, limit : 999 } ) ;
18
23
const [ totalValue , setTotalValue ] = React . useState ( 0 ) ;
19
24
20
25
const fetchData = ( ) => {
21
- if ( exchangeRatesQuery . isLoading || ordinalsMarketcapQuery . isLoading ) {
26
+ if (
27
+ exchangeRatesQuery . isLoading ||
28
+ ordinalsMarketcapQuery . isLoading ||
29
+ accountTokensQuery . isLoading
30
+ ) {
22
31
return { loading : true } ;
23
32
}
24
33
25
- if ( exchangeRatesQuery . isError || ordinalsMarketcapQuery . isError ) {
34
+ if (
35
+ exchangeRatesQuery . isError ||
36
+ ordinalsMarketcapQuery . isError ||
37
+ accountTokensQuery . isError
38
+ ) {
26
39
return {
27
40
error :
28
41
exchangeRatesQuery . error ?. message +
@@ -33,15 +46,17 @@ export default function AccountOverview({ tokens }: OverviewProps) {
33
46
34
47
const exchangeRates = exchangeRatesQuery . data ;
35
48
const ordinalsMarketcap = ordinalsMarketcapQuery . data ;
49
+ const accountTokens = accountTokensQuery . data ;
36
50
37
- return { exchangeRates, ordinalsMarketcap } ;
51
+ return { exchangeRates, ordinalsMarketcap, accountTokens } ;
38
52
} ;
39
53
40
54
const dataResult = fetchData ( ) ;
41
- const { exchangeRates, ordinalsMarketcap } = dataResult ;
55
+ const { exchangeRates, ordinalsMarketcap, accountTokens } = dataResult ;
56
+ const tokens = accountTokens ?. tokens ;
42
57
43
58
const sortedTokens = React . useMemo ( ( ) => {
44
- if ( ! exchangeRates ) return false ;
59
+ if ( ! exchangeRates || ! tokens ) return false ;
45
60
46
61
const sorted = [ ...tokens ] . sort ( ( a , b ) => {
47
62
const aValue = ( a . amount || 0 ) * ( exchangeRates [ a . symbol ] || 0 ) ;
@@ -52,7 +67,7 @@ export default function AccountOverview({ tokens }: OverviewProps) {
52
67
} ) ;
53
68
54
69
const filtered = sorted . filter (
55
- ( token ) => token . contract !== 'ord.libre' && token . amount !== 0
70
+ ( token ) => token . contract !== 'ord.libre' && token . amount !== 0 ,
56
71
) ;
57
72
58
73
return filtered ;
@@ -74,7 +89,7 @@ export default function AccountOverview({ tokens }: OverviewProps) {
74
89
const exchangeRates = exchangeRatesQuery . data ;
75
90
let total = 0 ;
76
91
77
- tokens . forEach ( ( token ) => {
92
+ tokens ? .forEach ( ( token ) => {
78
93
const value = token . amount * exchangeRates [ token . symbol ] ;
79
94
if ( ! isNaN ( value ) ) {
80
95
total += value ;
@@ -139,40 +154,42 @@ export default function AccountOverview({ tokens }: OverviewProps) {
139
154
< img
140
155
src = { `/images/symbols/${ token . symbol } .svg` }
141
156
alt = { token . symbol }
142
- className = 'block h-15 w-15 shrink-0 object-contain mr-2 '
157
+ className = 'h-15 w-15 mr-2 block shrink-0 object-contain'
143
158
onError = { ( e ) => {
144
159
// @ts -ignore
145
160
if ( e . target instanceof HTMLElement ) {
146
161
e . target . style . display = 'none' ; // SVG görüntüsünü gizle
147
162
const container = document . createElement ( 'div' ) ;
148
- container . className = 'flex items-center space-x-2 mr-2' ; // İçeriği yatay hizalamak için flex kullanın
163
+ container . className =
164
+ 'flex items-center space-x-2 mr-2' ; // İçeriği yatay hizalamak için flex kullanın
149
165
const textContainer = document . createElement ( 'div' ) ;
150
- textContainer . className = 'rounded-full w-8 h-8 bg-[#4F4FDE] flex items-center justify-center ' ;
166
+ textContainer . className =
167
+ 'rounded-full w-8 h-8 bg-[#4F4FDE] flex items-center justify-center ' ;
151
168
textContainer . style . fontSize = '8px' ; // Küçük font boyutu ayarlayın
152
169
textContainer . style . overflow = 'hidden' ; // İçeriği kırp
153
170
textContainer . style . color = 'white' ; // Metin rengini beyaz yapın
154
171
textContainer . innerText = token . symbol ; // Token adını içeriğe ekleyin
155
172
container . appendChild ( textContainer ) ; // Yazıyı içeriğe ekleyin
156
173
if ( e . target . parentNode ) {
157
- e . target . parentNode . insertBefore ( container , e . target . nextSibling ) ; // İçeriği ekleyin
174
+ e . target . parentNode . insertBefore (
175
+ container ,
176
+ e . target . nextSibling ,
177
+ ) ; // İçeriği ekleyin
158
178
}
159
179
}
160
180
} }
161
181
/>
162
182
163
-
164
-
165
-
166
-
167
- < div className = 'flex items-center' >
168
- < span className = 'font-semibold' > { token . symbol } </ span >
169
- { [ 'PBTC' , 'LIBRE' , 'PUSDT' , 'BTCLIB' , 'BTCUSD' ] . includes ( token . symbol ) ? null : (
170
- < div className = 'bg-[#4F4FDE] text-white px-2 py-1 rounded-full text-xs ml-2' >
171
- BRC20
172
- </ div >
173
- ) }
174
- </ div >
175
-
183
+ < div className = 'flex items-center' >
184
+ < span className = 'font-semibold' > { token . symbol } </ span >
185
+ { [ 'PBTC' , 'LIBRE' , 'PUSDT' , 'BTCLIB' , 'BTCUSD' ] . includes (
186
+ token . symbol ,
187
+ ) ? null : (
188
+ < div className = 'ml-2 rounded-full bg-[#4F4FDE] px-2 py-1 text-xs text-white' >
189
+ BRC20
190
+ </ div >
191
+ ) }
192
+ </ div >
176
193
</ div >
177
194
</ S . StyledTableCell >
178
195
< S . StyledTableCell size = 'medium' >
@@ -187,7 +204,7 @@ export default function AccountOverview({ tokens }: OverviewProps) {
187
204
{ (
188
205
token . amount *
189
206
( ordinalsMarketcap . tokens . find (
190
- ( t ) => t . mappedName === token . symbol
207
+ ( t ) => t . mappedName === token . symbol ,
191
208
) ?. price ?? 0 ) *
192
209
BTCPrice
193
210
) . toLocaleString ( 'en-US' , {
0 commit comments