1
- import { useBalances } from '@/components/hooks' ;
2
- import type { ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb' ;
1
+ import { useBalances , useAddresses } from '@/components/hooks' ;
2
+ import type { ValueView , AddressView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb' ;
3
3
import { ValueViewComponent } from '@penumbra-zone/ui/ValueViewComponent' ;
4
+ import { AddressViewComponent } from '@penumbra-zone/ui/AddressViewComponent' ;
4
5
import type React from 'react' ;
6
+
5
7
export function Balances ( ) {
6
8
const { data : balances } = useBalances ( ) ;
9
+ const { data : addresses } = useAddresses ( 1 ) ;
10
+
11
+ const filteredBalances = balances ?. filter ( b =>
12
+ b . balanceView !== undefined &&
13
+ b . accountAddress ?. addressView . case === 'decoded' &&
14
+ b . accountAddress . addressView . value . index ?. account === 0
15
+ ) ;
16
+
17
+ if ( ! filteredBalances ?. length || ! addresses ?. length ) return null ;
7
18
8
- return balances ?. every ( ( b ) => b . balanceView !== undefined )
9
- ? balances . map ( ( { balanceView } ) => (
10
- < BalanceRow key = { balanceView ! . toJsonString ( ) } balance = { balanceView ! } />
11
- ) )
12
- : null ;
13
- }
19
+ const addressView : AddressView = {
20
+ addressView : {
21
+ case : 'decoded' ,
22
+ value : {
23
+ address : addresses [ 0 ] . address ,
24
+ index : {
25
+ account : 0 ,
26
+ randomizer : new Uint8Array ( )
27
+ }
28
+ }
29
+ }
30
+ } ;
14
31
15
- function BalanceRow ( {
16
- balance,
17
- } : {
18
- balance : ValueView ;
19
- } ) {
20
32
return (
21
- < div
22
- className = "mt-3 flex gap-3 items-center bg-gray-700 text-white p-3"
23
- key = { balance . toJsonString ( ) }
24
- >
25
- < ValueViewComponent valueView = { balance } />
33
+ < div className = "p-4" >
34
+ < div className = "flex flex-wrap gap-4 items-center" >
35
+ < AddressViewComponent addressView = { addressView } />
36
+ { filteredBalances . map ( ( { balanceView } ) => (
37
+ < ValueViewComponent
38
+ key = { balanceView ! . toJsonString ( ) }
39
+ valueView = { balanceView ! }
40
+ />
41
+ ) ) }
42
+ </ div >
26
43
</ div >
27
44
) ;
28
- }
45
+ }
0 commit comments