diff --git a/orm/src/balances.rs b/orm/src/balances.rs index 91ee539ff..fc2024a3a 100644 --- a/orm/src/balances.rs +++ b/orm/src/balances.rs @@ -2,10 +2,8 @@ use std::str::FromStr; use bigdecimal::BigDecimal; use diesel::{Insertable, Queryable, Selectable}; -use shared::{ - balance::{Amount, Balance}, - id::Id, -}; +use shared::balance::{Amount, Balance}; +use shared::id::Id; use crate::schema::balances; diff --git a/webserver/src/handler/balance.rs b/webserver/src/handler/balance.rs index 5addbf72f..0ca544e92 100644 --- a/webserver/src/handler/balance.rs +++ b/webserver/src/handler/balance.rs @@ -2,7 +2,6 @@ use axum::extract::{Path, State}; use axum::http::HeaderMap; use axum::Json; use axum_macros::debug_handler; -use shared::balance::DenominatedAmount; use crate::error::api::ApiError; use crate::response::balance::AddressBalance; @@ -16,15 +15,8 @@ pub async fn get_address_balance( ) -> Result>, ApiError> { let balances = state.balance_service.get_address_balances(address).await?; - let balances_response: Vec = balances - .iter() - .map(|balance| AddressBalance { - token_address: balance.token.to_string(), - // TODO: temporary solution as we only store NAM balances - balance: DenominatedAmount::native(balance.amount.clone()) - .to_string_precise(), - }) - .collect(); + let balances_response: Vec = + balances.iter().cloned().map(AddressBalance::from).collect(); Ok(Json(balances_response)) } diff --git a/webserver/src/response/balance.rs b/webserver/src/response/balance.rs index 042343dec..fb53bb8ab 100644 --- a/webserver/src/response/balance.rs +++ b/webserver/src/response/balance.rs @@ -1,5 +1,5 @@ -use orm::balances::BalanceDb; use serde::{Deserialize, Serialize}; +use shared::balance::{Balance, DenominatedAmount}; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] @@ -8,11 +8,13 @@ pub struct AddressBalance { pub balance: String, } -impl From for AddressBalance { - fn from(value: BalanceDb) -> Self { +impl From for AddressBalance { + fn from(value: Balance) -> Self { Self { - token_address: value.token, - balance: value.raw_amount.to_string(), + token_address: value.token.to_string(), + // TODO: temporary solution as we only store NAM balances + balance: DenominatedAmount::native(value.amount.clone()) + .to_string_precise(), } } } diff --git a/webserver/src/service/balance.rs b/webserver/src/service/balance.rs index 4046615c2..2f793c0e2 100644 --- a/webserver/src/service/balance.rs +++ b/webserver/src/service/balance.rs @@ -1,4 +1,4 @@ -use shared::balance::{Amount, Balance, DenominatedAmount}; +use shared::balance::Balance; use crate::appstate::AppState; use crate::error::balance::BalanceError;