Skip to content

Commit

Permalink
[feat](search): add Avatar Url
Browse files Browse the repository at this point in the history
  • Loading branch information
woxjro committed Oct 28, 2023
1 parent a7eadd5 commit e1bb72c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ log = "0.4.20"
simplelog = "0.12.1"
toml = "0.8.4"
serde = "1.0.189"
url = "2.4.1"

[dependencies.crossterm]
version = "0.26.1"
Expand Down
2 changes: 2 additions & 0 deletions src/ethers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod types {
use ethers_core::types::{Address, Transaction, TransactionReceipt, U256};
use url::Url;

#[derive(Clone, Debug, PartialEq)]
pub struct AddressInfo {
pub address: Address,
pub ens_id: Option<String>,
pub avatar_url: Option<Url>,
pub balance: U256,
}

Expand Down
11 changes: 10 additions & 1 deletion src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ impl<'a> Network<'a> {
) -> Result<Option<AddressInfo>, Box<dyn Error>> {
let provider = Provider::<Http>::try_from(endpoint)?;
let address = provider.resolve_name(ens_id).await.ok().unwrap();
let avatar_url = provider.resolve_avatar(ens_id).await.ok();
let balance = provider.get_balance(address, None /* TODO */).await?;
//TODO: Not Found
//TODO: Not Found (impl LazyEtherscanError)
Ok(Some(AddressInfo {
address,
balance,
avatar_url,
ens_id: Some(ens_id.to_owned()),
}))
}
Expand All @@ -145,11 +147,18 @@ impl<'a> Network<'a> {
) -> Result<Option<AddressInfo>, Box<dyn Error>> {
let provider = Provider::<Http>::try_from(endpoint)?;
let ens_id = provider.lookup_address(address).await.ok();

let mut avatar_url = None;
if let Some(ens_id) = ens_id.as_ref() {
avatar_url = provider.resolve_avatar(&ens_id).await.ok();
}
let balance = provider.get_balance(address, None /* TODO */).await?;

//TODO: Not Found
Ok(Some(AddressInfo {
address,
balance,
avatar_url,
ens_id,
}))
}
Expand Down
6 changes: 6 additions & 0 deletions src/ui/home/address_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ pub fn render<B: Backend>(
));
}

if let Some(avatar_url) = address_info.avatar_url {
details.push(Line::from(
Span::raw(format!("{:<17}: {avatar_url}", "AVATAR URL")).fg(Color::White),
));
}

details.push(Line::from(
Span::raw(format!(
"{:<17}: {} ETH",
Expand Down

0 comments on commit e1bb72c

Please sign in to comment.