Skip to content

Commit 057f1dc

Browse files
authored
fix(Dune): checking for the cached metadata first (#907)
1 parent 2026085 commit 057f1dc

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

src/providers/dune.rs

+39-26
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,6 @@ impl BalanceProvider for DuneProvider {
182182

183183
let mut balances_vec = Vec::new();
184184
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-
192185
// Build a CAIP-2 chain ID
193186
let caip2_chain_id = match f.chain_id {
194187
Some(cid) => format!("{}:{}", namespace, cid),
@@ -201,24 +194,6 @@ impl BalanceProvider for DuneProvider {
201194
},
202195
};
203196

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-
222197
// Build the CAIP-10 address
223198
let caip10_token_address_strict = if f.address == "native" {
224199
match namespace {
@@ -233,17 +208,55 @@ impl BalanceProvider for DuneProvider {
233208
format!("{}:{}", caip2_chain_id, f.address)
234209
};
235210

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+
236221
// 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
237224
let token_metadata =
238225
match get_cached_metadata(metadata_cache, &caip10_token_address_strict).await {
239226
Some(cached) => cached,
240227
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+
241253
let new_item = TokenMetadataCacheItem {
242254
name: name.clone(),
243255
symbol: symbol.clone(),
244256
icon_url: icon_url.clone(),
245257
};
246-
// Spawn a background task to set the cache without blocking
258+
259+
// Spawn a background task to update the cache without blocking
247260
{
248261
let metadata_cache = metadata_cache.clone();
249262
let address_key = caip10_token_address_strict.clone();

0 commit comments

Comments
 (0)