@@ -182,13 +182,6 @@ impl BalanceProvider for DuneProvider {
182
182
183
183
let mut balances_vec = Vec :: new ( ) ;
184
184
for f in balance_response. balances {
185
- // Skip if missing required fields as a possible spam token
186
- let ( Some ( symbol) , Some ( price_usd) , Some ( decimals) ) =
187
- ( f. symbol , f. price_usd , f. decimals )
188
- else {
189
- continue ;
190
- } ;
191
-
192
185
// Build a CAIP-2 chain ID
193
186
let caip2_chain_id = match f. chain_id {
194
187
Some ( cid) => format ! ( "{}:{}" , namespace, cid) ,
@@ -201,24 +194,6 @@ impl BalanceProvider for DuneProvider {
201
194
} ,
202
195
} ;
203
196
204
- // Determine name
205
- let name = if f. address == "native" {
206
- f. chain . clone ( )
207
- } else {
208
- symbol. clone ( )
209
- } ;
210
-
211
- // Determine icon URL
212
- let icon_url = if f. address == "native" {
213
- NATIVE_TOKEN_ICONS . get ( & symbol) . unwrap_or ( & "" ) . to_string ( )
214
- } else {
215
- // If there's no token_metadata or no logo, skip
216
- match & f. token_metadata {
217
- Some ( m) => m. logo . clone ( ) ,
218
- None => continue ,
219
- }
220
- } ;
221
-
222
197
// Build the CAIP-10 address
223
198
let caip10_token_address_strict = if f. address == "native" {
224
199
match namespace {
@@ -233,17 +208,55 @@ impl BalanceProvider for DuneProvider {
233
208
format ! ( "{}:{}" , caip2_chain_id, f. address)
234
209
} ;
235
210
211
+ // Skip if no decimals were provided
212
+ // as a possible spam token
213
+ let Some ( decimals) = f. decimals else {
214
+ continue ;
215
+ } ;
216
+
217
+ // Force to use zero price if the price is not determined
218
+ // instead of not showing the asset
219
+ let price_usd = f. price_usd . unwrap_or ( 0.0 ) ;
220
+
236
221
// Get token metadata from the cache or update it
222
+ // Skip the asset if no cached metadata from other providers were added
223
+ // and the current response metadata is empty as a possible spam token
237
224
let token_metadata =
238
225
match get_cached_metadata ( metadata_cache, & caip10_token_address_strict) . await {
239
226
Some ( cached) => cached,
240
227
None => {
228
+ // Skip if missing required fields and no such metadata
229
+ // as a possible spam token
230
+ let Some ( symbol) = f. symbol else {
231
+ continue ;
232
+ } ;
233
+
234
+ // Determine name
235
+ let name = if f. address == "native" {
236
+ f. chain . clone ( )
237
+ } else {
238
+ symbol. clone ( )
239
+ } ;
240
+
241
+ // Determine icon URL
242
+ let icon_url = if f. address == "native" {
243
+ NATIVE_TOKEN_ICONS . get ( & symbol) . unwrap_or ( & "" ) . to_string ( )
244
+ } else {
245
+ // If there's no token_metadata or no logo, skip the asset
246
+ // as a possible spam token
247
+ match & f. token_metadata {
248
+ Some ( m) => m. logo . clone ( ) ,
249
+ None => continue ,
250
+ }
251
+ } ;
252
+
241
253
let new_item = TokenMetadataCacheItem {
242
254
name : name. clone ( ) ,
243
255
symbol : symbol. clone ( ) ,
244
256
icon_url : icon_url. clone ( ) ,
245
257
} ;
246
- // Spawn a background task to set the cache without blocking
258
+
259
+ // Spawn a background task to update the cache without blocking
247
260
{
248
261
let metadata_cache = metadata_cache. clone ( ) ;
249
262
let address_key = caip10_token_address_strict. clone ( ) ;
0 commit comments