@@ -55,14 +55,14 @@ export async function queryBalances(chain: Chain, address: string) {
55
55
await updateBalancesCosmos ( chain , address )
56
56
break
57
57
case "aptos" :
58
- await updateBalancesAptos ( chain , address )
58
+ await updateBalancesAptos ( chain , address as Address )
59
59
// console.error("aptos balance fetching currently unsupported")
60
60
break
61
61
default :
62
62
console . error ( "invalid rpc type in balance fetching" )
63
63
}
64
64
}
65
- export async function updateBalancesAptos ( chain : Chain , address : string ) {
65
+ export async function updateBalancesAptos ( chain : Chain , address : Address ) {
66
66
// Optionally mark expected tokens as "loading" (if chain.tokens exists)
67
67
if ( chain . tokens && chain . tokens . length ) {
68
68
chain . tokens . forEach ( token =>
@@ -91,54 +91,60 @@ export async function updateBalancesAptos(chain: Chain, address: string) {
91
91
` ;
92
92
const variables = {
93
93
owner_address : address ,
94
- limit : 100 ,
95
- offset : 0 ,
94
+ limit : 200 ,
95
+ offset : 0
96
96
} ;
97
97
98
98
// Set up the fetch options with appropriate headers.
99
99
const fetchOptions : RequestInit = {
100
100
method : "POST" ,
101
- headers : {
102
- "Content-Type" : "application/json" ,
103
- "X-Indexer-Client" : "movement-explorer" ,
104
- "X-Aptos-Client" : "aptos-typescript-sdk/1.35.0" ,
105
- "X-Aptos-Typescript-Sdk-Origin-Method" : "queryIndexer" ,
106
- } ,
107
101
body : JSON . stringify ( { query, variables } ) ,
108
102
} ;
109
103
110
104
try {
111
105
// Send the request to the Aptos indexer.
112
- const response = await fetchJson ( "https://indexer.testnet.movementnetwork.xyz/v1/graphql" , fetchOptions ) ;
106
+ const response = await fetchJson (
107
+ "https://indexer.testnet.movementnetwork.xyz/v1/graphql" ,
108
+ fetchOptions
109
+ )
113
110
if ( response . isErr ( ) ) {
114
- throw new Error ( response . error . message ) ;
111
+ throw new Error ( response . error . message )
115
112
}
116
-
117
113
const data = response . value . data ;
118
114
if ( ! data || ! data . current_fungible_asset_balances ) {
119
115
throw new Error ( "Invalid response data" ) ;
120
116
}
121
117
122
- // Process each token balance from the response.
123
- data . current_fungible_asset_balances . forEach ( ( token : any ) => {
124
- // Here, asset_type can be used as the key for storing the balance.
125
- const tokenKey = token . asset_type ;
126
- const amount = token . amount ;
127
- updateBalance ( chain . chain_id , tokenKey , { kind : "balance" , amount, timestamp : Date . now ( ) } ) ;
128
- } ) ;
118
+ const aptosBalances = data . current_fungible_asset_balances
119
+ . filter ( ( token : any ) => token . metadata . token_standard === "v2" )
120
+ . map ( ( token : any ) => ( {
121
+ denom : token . asset_type ,
122
+ amount : token . amount
123
+ } ) )
124
+
125
+ console . info ( "aptosBalances: " , aptosBalances )
126
+ aptosBalances . forEach ( token => {
127
+ updateBalance ( chain . chain_id , token . denom , {
128
+ kind : "balance" ,
129
+ amount : token . amount ,
130
+ timestamp : Date . now ( )
131
+ } )
132
+ } )
129
133
} catch ( error : any ) {
130
- console . error ( "Error fetching Aptos balances" , error ) ;
134
+ console . error ( "Error fetching Aptos balances" , error )
131
135
// On error, update the balances for all tokens with an error state.
132
136
if ( chain . tokens && chain . tokens . length ) {
133
137
chain . tokens . forEach ( token =>
134
- updateBalance ( chain . chain_id , token . denom , { kind : "error" , error : error . message , timestamp : Date . now ( ) } )
135
- ) ;
138
+ updateBalance ( chain . chain_id , token . denom , {
139
+ kind : "error" ,
140
+ error : error . message ,
141
+ timestamp : Date . now ( )
142
+ } )
143
+ )
136
144
}
137
145
}
138
146
}
139
147
140
-
141
-
142
148
export async function updateBalancesEvm ( chain : Chain , address : Address ) {
143
149
const denoms = chain . tokens . filter ( tokens => isAddress ( tokens . denom ) ) . map ( token => token . denom )
144
150
balances . update ( val => {
0 commit comments