@@ -2,6 +2,7 @@ import { StatusBar } from "expo-status-bar";
2
2
import {
3
3
ActivityIndicator ,
4
4
Button ,
5
+ Pressable ,
5
6
ScrollView ,
6
7
StyleSheet ,
7
8
Text ,
@@ -10,12 +11,18 @@ import {
10
11
import { useFacade } from "../../data/facades" ;
11
12
import { useEffect , useState } from "react" ;
12
13
import { LinkButton } from "../../components/LinkButton" ;
14
+ import { useQueries } from "@tanstack/react-query" ;
15
+ import { Asset } from "../../data/facades/chain/types" ;
13
16
14
17
export default function Balances ( ) {
15
18
const facade = useFacade ( ) ;
16
19
17
20
const [ account , setAccount ] = useState < string > ( "" ) ;
18
21
22
+ const [ visibleView , setVisibleView ] = useState < "transactions" | "assets" > (
23
+ "transactions" ,
24
+ ) ;
25
+
19
26
const getTransactionsResult = facade . getTransactions . useQuery (
20
27
{ accountName : account } ,
21
28
{
@@ -30,6 +37,23 @@ export default function Balances() {
30
37
} ,
31
38
) ;
32
39
40
+ const getCustomAssets = useQueries ( {
41
+ queries :
42
+ getAccountResult . data ?. balances . custom . map ( ( b ) => {
43
+ return {
44
+ refetchInterval : 1000 ,
45
+ queryFn : ( ) => facade . getAsset . resolver ( { assetId : b . assetId } ) ,
46
+ queryKey : facade . getAsset . buildQueryKey ( { assetId : b . assetId } ) ,
47
+ } ;
48
+ } ) ?? [ ] ,
49
+ } ) ;
50
+ const assetMap = new Map < string , Asset > ( ) ;
51
+ for ( const asset of getCustomAssets ) {
52
+ if ( asset . data ) {
53
+ assetMap . set ( asset . data . id , asset . data ) ;
54
+ }
55
+ }
56
+
33
57
const getIronAsset = facade . getAsset . useQuery (
34
58
{
35
59
assetId : getAccountResult . data ?. balances . iron . assetId ?? "" ,
@@ -125,18 +149,56 @@ export default function Balances() {
125
149
< LinkButton href = "/send/" title = "Send" />
126
150
< LinkButton href = "/address/" title = "Receive" />
127
151
</ View >
128
- < Text style = { { fontWeight : 700 , fontSize : 24 } } > Transactions</ Text >
152
+ < View style = { { display : "flex" , flexDirection : "row" , gap : 16 } } >
153
+ < Pressable onPress = { ( ) => setVisibleView ( "transactions" ) } >
154
+ < Text style = { { fontWeight : 700 , fontSize : 24 } } > Transactions</ Text >
155
+ </ Pressable >
156
+ < Pressable onPress = { ( ) => setVisibleView ( "assets" ) } >
157
+ < Text style = { { fontWeight : 700 , fontSize : 24 } } > Assets</ Text >
158
+ </ Pressable >
159
+ </ View >
129
160
< ScrollView >
130
- { getTransactionsResult . data ?. map ( ( transaction ) => (
131
- < View key = { transaction . hash } style = { { marginBottom : 8 } } >
132
- < Text style = { { fontSize : 14 } } > { transaction . hash } </ Text >
133
- < Text > Block Sequence: { transaction . blockSequence } </ Text >
134
- < Text > Timestamp: { transaction . timestamp . toString ( ) } </ Text >
135
- < Text >
136
- { `Notes (${ transaction . notes . length } ): ${ transaction . notes . map ( ( n ) => n . value ) . join ( ", " ) } ` }
137
- </ Text >
161
+ { visibleView === "transactions" &&
162
+ getTransactionsResult . data ?. map ( ( transaction ) => (
163
+ < View key = { transaction . hash } style = { { marginBottom : 8 } } >
164
+ < Text style = { { fontSize : 14 } } > { transaction . hash } </ Text >
165
+ < Text > Block Sequence: { transaction . blockSequence } </ Text >
166
+ < Text > Timestamp: { transaction . timestamp . toString ( ) } </ Text >
167
+ < Text >
168
+ { `Notes (${ transaction . notes . length } ): ${ transaction . notes . map ( ( n ) => n . value ) . join ( ", " ) } ` }
169
+ </ Text >
170
+ </ View >
171
+ ) ) }
172
+ { visibleView === "assets" && getAccountResult . data && (
173
+ < View >
174
+ < View >
175
+ < Text >
176
+ { getIronAsset . data
177
+ ? getIronAsset . data . verification . status === "verified"
178
+ ? `${ getIronAsset . data . verification . symbol } (Verified)`
179
+ : `${ getIronAsset . data . name } (Unverified)`
180
+ : getAccountResult . data . balances . iron . assetId }
181
+ </ Text >
182
+ < Text > { getAccountResult . data . balances . iron . confirmed } </ Text >
183
+ </ View >
184
+ { getAccountResult . data . balances . custom . map ( ( balance ) => {
185
+ const asset = assetMap . get ( balance . assetId ) ;
186
+
187
+ return (
188
+ < View key = { balance . assetId } >
189
+ < Text >
190
+ { asset
191
+ ? asset . verification . status === "verified"
192
+ ? `${ asset . verification . symbol } (Verified)`
193
+ : `${ asset . name } (Unverified)`
194
+ : balance . assetId }
195
+ </ Text >
196
+ < Text > { balance . confirmed } </ Text >
197
+ </ View >
198
+ ) ;
199
+ } ) }
138
200
</ View >
139
- ) ) }
201
+ ) }
140
202
</ ScrollView >
141
203
< StatusBar style = "auto" />
142
204
</ View >
0 commit comments