Skip to content

Commit

Permalink
Adding extra fix
Browse files Browse the repository at this point in the history
  • Loading branch information
leboiko committed Dec 21, 2024
1 parent bfc24a3 commit 62a44f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
17 changes: 11 additions & 6 deletions consumer/src/mode/decoded/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,24 @@ pub async fn get_or_create_account_with_atom_id(
atom_id: U256Wrapper,
decoded_consumer_context: &DecodedConsumerContext,
) -> Result<Account, ConsumerError> {
if let Some(mut account) =
if let Some(account) =
Account::find_by_id(id.clone(), &decoded_consumer_context.pg_pool).await?
{
if account.account_type == AccountType::AtomWallet {
info!("Account already exists and is an atom wallet, nothing to do...");
Ok(account)
} else {
info!("Account already exists but is not an atom wallet, updating...");
account.atom_id = Some(atom_id);
account.account_type = AccountType::AtomWallet;
account.label = short_id(&id);
account.upsert(&decoded_consumer_context.pg_pool).await?;
Ok(account)
let updated_account = Account::builder()
.id(account.id)
.account_type(AccountType::AtomWallet)
.label(short_id(&id))
.atom_id(atom_id)
.build()
.upsert(&decoded_consumer_context.pg_pool)
.await?;
info!("Updated account: {:?}", updated_account);
Ok(updated_account)
}
} else {
info!("Creating account with atom_id for: {}, {}", id, atom_id);
Expand Down
14 changes: 10 additions & 4 deletions consumer/src/mode/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use alloy::primitives::Address;
use models::{
account::Account,
account::{Account, AccountType},
atom::{Atom, AtomType},
traits::SimpleCrud,
};
Expand Down Expand Up @@ -69,9 +69,15 @@ impl ResolverMessageType {
let ens = Ens::get_ens(Address::from_str(&account.id)?, resolver_consumer_context).await?;
if let Some(name) = ens.name.clone() {
info!("ENS for account: {:?}", ens);
account.label = name.clone();
account.image = ens.image.clone();
account.upsert(&resolver_consumer_context.pg_pool).await?;
Account::builder()
.id(account.id.clone())
.label(name.clone())
.image(ens.image.clone().unwrap_or_default())
.account_type(account.account_type.clone())
.atom_id(account.atom_id.clone().unwrap_or_default())
.build()
.upsert(&resolver_consumer_context.pg_pool)
.await?;
} else {
info!("No ENS found for account: {:?}", account);
}
Expand Down

0 comments on commit 62a44f0

Please sign in to comment.