Skip to content

Commit

Permalink
Do NOT try to get USD equivalent of STARK and USD
Browse files Browse the repository at this point in the history
  • Loading branch information
ofux committed Oct 30, 2023
1 parent 89196a0 commit 6a2d18f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/src/presentation/event_listeners/quote_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use chrono::Utc;
use derive_more::Constructor;
use domain::{currencies, services::quotes, BudgetEvent, Event, SubscriberCallbackError};
use infrastructure::dbclient::Repository;
use infrastructure::{database::enums::Currency, dbclient::Repository};
use tracing::instrument;

use super::EventListener;
Expand All @@ -24,9 +24,9 @@ impl EventListener<Event> for Projector {
if let Event::Budget(event) = event {
match event {
BudgetEvent::Created { currency, .. } if currency != currencies::USD => {
let code = currency.try_into()?;
let code: Currency = currency.try_into()?;

if !self.quotes_repository.exists(code)? {
if code.has_usd_equivalent() && !self.quotes_repository.exists(code)? {
let price = self
.quote_service
.fetch_conversion_rate(currency)
Expand Down
12 changes: 12 additions & 0 deletions common/infrastructure/src/database/enums/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ pub enum Currency {
Stark,
}

impl Currency {
pub fn has_usd_equivalent(&self) -> bool {
match self {
Currency::Usd => false,
Currency::Eth => true,
Currency::Op => true,
Currency::Apt => true,
Currency::Stark => false,
}
}
}

impl TryFrom<&'static domain::Currency> for Currency {
type Error = ParseCurrencyError;

Expand Down

0 comments on commit 6a2d18f

Please sign in to comment.