feat: implement MC as base currency replacing USD across marketplace and currency services

This commit is contained in:
mik-tf
2025-09-08 15:15:50 -04:00
parent 7f8ca188ee
commit abbf59207a
3 changed files with 58 additions and 58 deletions

View File

@@ -40,8 +40,8 @@ impl Default for MarketplaceConfig {
marketplace: MarketplaceInfo { marketplace: MarketplaceInfo {
name: "Mycelium Marketplace".to_string(), name: "Mycelium Marketplace".to_string(),
marketplace_type: "infrastructure".to_string(), marketplace_type: "infrastructure".to_string(),
base_currency: "USD".to_string(), base_currency: "MC".to_string(),
default_display_currency: "USD".to_string(), default_display_currency: "MC".to_string(),
supported_languages: vec!["en".to_string()], supported_languages: vec!["en".to_string()],
features: MarketplaceFeatures { features: MarketplaceFeatures {
reviews_enabled: false, reviews_enabled: false,

View File

@@ -18,11 +18,11 @@ impl CurrencyService {
let mut service = Self { let mut service = Self {
exchange_rates_cache: HashMap::default(), exchange_rates_cache: HashMap::default(),
last_update: Utc::now(), last_update: Utc::now(),
default_display_currency: "USD".to_string(), default_display_currency: "MC".to_string(),
}; };
// USD Credits is now the base currency - no conversion needed // MC is now the base currency - no conversion needed
service.exchange_rates_cache.insert("USD".to_string(), dec!(1.0)); service.exchange_rates_cache.insert("MC".to_string(), dec!(1.0));
service.update_exchange_rates(); service.update_exchange_rates();
service service
} }
@@ -36,7 +36,7 @@ impl CurrencyService {
let mut service = Self { let mut service = Self {
exchange_rates_cache: fallback_rates, exchange_rates_cache: fallback_rates,
last_update: Utc::now(), last_update: Utc::now(),
default_display_currency: "USD".to_string(), default_display_currency: "MC".to_string(),
}; };
if auto_update { if auto_update {
@@ -72,15 +72,27 @@ impl CurrencyService {
/// Get all supported currencies /// Get all supported currencies
pub fn get_supported_currencies(&self) -> Vec<Currency> { pub fn get_supported_currencies(&self) -> Vec<Currency> {
// Return standard supported currencies without mock data // Return standard supported currencies with MC as base currency
vec![ vec![
Currency {
code: "MC".to_string(),
name: "Mycelium Credit".to_string(),
symbol: "MC".to_string(),
currency_type: crate::models::currency::CurrencyType::Custom("credits".to_string()),
exchange_rate_to_base: dec!(1.0), // MC is the base currency
is_base_currency: true,
decimal_places: 2,
is_active: true,
provider_config: None,
last_updated: chrono::Utc::now(),
},
Currency { Currency {
code: "USD".to_string(), code: "USD".to_string(),
name: "US Dollar".to_string(), name: "US Dollar".to_string(),
symbol: "$".to_string(), symbol: "$".to_string(),
currency_type: crate::models::currency::CurrencyType::Fiat, currency_type: crate::models::currency::CurrencyType::Fiat,
exchange_rate_to_base: dec!(1.0), exchange_rate_to_base: dec!(1.0), // 1 USD = 1 MC (parity for UX preservation)
is_base_currency: true, is_base_currency: false,
decimal_places: 2, decimal_places: 2,
is_active: true, is_active: true,
provider_config: None, provider_config: None,
@@ -91,19 +103,7 @@ impl CurrencyService {
name: "Euro".to_string(), name: "Euro".to_string(),
symbol: "".to_string(), symbol: "".to_string(),
currency_type: crate::models::currency::CurrencyType::Fiat, currency_type: crate::models::currency::CurrencyType::Fiat,
exchange_rate_to_base: dec!(0.85), exchange_rate_to_base: dec!(0.85), // 1 EUR = 0.85 MC
is_base_currency: false,
decimal_places: 2,
is_active: true,
provider_config: None,
last_updated: chrono::Utc::now(),
},
Currency {
code: "MC".to_string(),
name: "Mycelium Credit".to_string(),
symbol: "MC".to_string(),
currency_type: crate::models::currency::CurrencyType::Custom("credits".to_string()),
exchange_rate_to_base: dec!(1.0), // 1 MC = 1 USD
is_base_currency: false, is_base_currency: false,
decimal_places: 2, decimal_places: 2,
is_active: true, is_active: true,
@@ -115,7 +115,7 @@ impl CurrencyService {
name: "Canadian Dollar".to_string(), name: "Canadian Dollar".to_string(),
symbol: "C$".to_string(), symbol: "C$".to_string(),
currency_type: crate::models::currency::CurrencyType::Fiat, currency_type: crate::models::currency::CurrencyType::Fiat,
exchange_rate_to_base: dec!(1.35), exchange_rate_to_base: dec!(1.35), // 1 CAD = 1.35 MC
is_base_currency: false, is_base_currency: false,
decimal_places: 2, decimal_places: 2,
is_active: true, is_active: true,
@@ -127,7 +127,7 @@ impl CurrencyService {
name: "Mycelium Token".to_string(), name: "Mycelium Token".to_string(),
symbol: "TFT".to_string(), symbol: "TFT".to_string(),
currency_type: crate::models::currency::CurrencyType::Token, currency_type: crate::models::currency::CurrencyType::Token,
exchange_rate_to_base: dec!(0.05), exchange_rate_to_base: dec!(0.05), // 1 TFT = 0.05 MC
is_base_currency: false, is_base_currency: false,
decimal_places: 3, decimal_places: 3,
is_active: true, is_active: true,
@@ -139,7 +139,7 @@ impl CurrencyService {
name: "UAE Dirham".to_string(), name: "UAE Dirham".to_string(),
symbol: "د.إ".to_string(), symbol: "د.إ".to_string(),
currency_type: crate::models::currency::CurrencyType::Fiat, currency_type: crate::models::currency::CurrencyType::Fiat,
exchange_rate_to_base: dec!(3.67), exchange_rate_to_base: dec!(3.67), // 1 AED = 3.67 MC
is_base_currency: false, is_base_currency: false,
decimal_places: 2, decimal_places: 2,
is_active: true, is_active: true,
@@ -159,10 +159,10 @@ impl CurrencyService {
/// Get base currency /// Get base currency
pub fn get_base_currency(&self) -> Currency { pub fn get_base_currency(&self) -> Currency {
Currency { Currency {
code: "USD".to_string(), code: "MC".to_string(),
name: "US Dollar".to_string(), name: "Mycelium Credit".to_string(),
symbol: "$".to_string(), symbol: "MC".to_string(),
currency_type: crate::models::currency::CurrencyType::Fiat, currency_type: crate::models::currency::CurrencyType::Custom("credits".to_string()),
exchange_rate_to_base: dec!(1.0), exchange_rate_to_base: dec!(1.0),
is_base_currency: true, is_base_currency: true,
decimal_places: 2, decimal_places: 2,
@@ -183,7 +183,7 @@ impl CurrencyService {
return Ok(amount); return Ok(amount);
} }
let base_currency_code = "USD"; // Use USD as base currency let base_currency_code = "MC"; // Use MC as base currency
// Convert to base currency first if needed // Convert to base currency first if needed
let base_amount = if from_currency == base_currency_code { let base_amount = if from_currency == base_currency_code {
@@ -204,7 +204,7 @@ impl CurrencyService {
/// Get exchange rate from base currency to target currency /// Get exchange rate from base currency to target currency
pub fn get_exchange_rate_to_base(&self, currency_code: &str) -> Result<Decimal, String> { pub fn get_exchange_rate_to_base(&self, currency_code: &str) -> Result<Decimal, String> {
let base_currency_code = "USD"; // Use USD as base currency let base_currency_code = "MC"; // Use MC as base currency
if currency_code == base_currency_code { if currency_code == base_currency_code {
return Ok(dec!(1.0)); return Ok(dec!(1.0));
@@ -300,7 +300,7 @@ impl CurrencyService {
if !self.default_display_currency.is_empty() { if !self.default_display_currency.is_empty() {
self.default_display_currency.clone() self.default_display_currency.clone()
} else { } else {
"USD".to_string() // Default to USD when no preference is set "MC".to_string() // Default to MC when no preference is set
} }
} }
@@ -335,7 +335,7 @@ impl CurrencyService {
/// Get all exchange rates relative to base currency /// Get all exchange rates relative to base currency
pub fn get_all_exchange_rates(&self) -> HashMap<String, Decimal> { pub fn get_all_exchange_rates(&self) -> HashMap<String, Decimal> {
let mut rates = HashMap::default(); let mut rates = HashMap::default();
let base_currency_code = "USD".to_string(); // Use USD as base currency let base_currency_code = "MC".to_string(); // Use MC as base currency
// Base currency always has rate 1.0 // Base currency always has rate 1.0
rates.insert(base_currency_code.clone(), dec!(1.0)); rates.insert(base_currency_code.clone(), dec!(1.0));
@@ -370,7 +370,7 @@ impl CurrencyService {
serde_json::Value::Number(serde_json::Number::from(self.get_supported_currencies().len()))); serde_json::Value::Number(serde_json::Number::from(self.get_supported_currencies().len())));
stats.insert("base_currency".to_string(), stats.insert("base_currency".to_string(),
serde_json::Value::String("USD".to_string())); serde_json::Value::String("MC".to_string()));
stats.insert("last_update".to_string(), stats.insert("last_update".to_string(),
serde_json::Value::String(self.last_update.to_rfc3339())); serde_json::Value::String(self.last_update.to_rfc3339()));

View File

@@ -155,7 +155,7 @@ impl Default for UserPersistentData {
node_groups: Vec::new(), node_groups: Vec::new(),
slice_rentals: Vec::new(), slice_rentals: Vec::new(),
slice_assignments: Vec::new(), slice_assignments: Vec::new(),
display_currency: Some("USD".to_string()), // Default to USD for new users display_currency: Some("MC".to_string()), // Default to MC for new users
quick_topup_amounts: Some(vec![dec!(10), dec!(25), dec!(50), dec!(100)]), // USD amounts quick_topup_amounts: Some(vec![dec!(10), dec!(25), dec!(50), dec!(100)]), // USD amounts
auto_topup_settings: None, // User can configure later auto_topup_settings: None, // User can configure later
products: Vec::new(), // Initialize empty products list products: Vec::new(), // Initialize empty products list