fedimovies/mitra-utils/src/currencies.rs
2023-04-24 17:35:32 +02:00

38 lines
743 B
Rust

#[derive(Debug, PartialEq)]
pub enum Currency {
Ethereum,
Monero,
}
impl Currency {
fn code(&self) -> String {
match self {
Self::Ethereum => "ETH",
Self::Monero => "XMR",
}
.to_string()
}
pub fn field_name(&self) -> String {
format!("${}", self.code())
}
pub fn normalize_address(&self, address: &str) -> String {
match self {
Self::Ethereum => address.to_lowercase(),
Self::Monero => address.to_string(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_currency_field_name() {
let ethereum = Currency::Ethereum;
assert_eq!(ethereum.field_name(), "$ETH");
}
}