Skip to main content

eth_icons/
source.rs

1use crate::{
2    Error, IconFetcher,
3    identity::{Address, NetworkId},
4    result::IconResult,
5};
6
7#[derive(Debug, Clone)]
8pub enum IconQuery {
9    // Ethereum Mainnet, Sepolia, etc.
10    Network(NetworkId),
11    // ETH, sepETH, etc.
12    Native(NetworkId),
13    // wETH, etc.
14    ERC20(NetworkId, Address),
15}
16
17#[async_trait::async_trait]
18pub trait IconSource: Send + Sync {
19    fn name(&self) -> &'static str;
20
21    fn url(&self, query: &IconQuery) -> Option<String>;
22
23    async fn fetch(&self, fetcher: &IconFetcher, query: &IconQuery) -> Result<IconResult, Error> {
24        match self.url(query) {
25            Some(url) => fetcher.fetch_image_url(&url).await,
26            None => Ok(IconResult::Unsupported),
27        }
28    }
29}