From 6f2b6e34e3c11ae3be5381998e8aee7f5a8075d9 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Fri, 10 Jan 2025 14:35:08 +0100 Subject: [PATCH] feat: add units to balances --- src/constants.rs | 2 ++ src/faucet/controller.rs | 9 +++++++++ src/faucet/views.rs | 9 +++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index f59fda7..9f32cad 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -11,3 +11,5 @@ pub static MAINNET_DRIP_AMOUNT: LazyLock = /// The amount of calibnet tFIL to be dripped to the user. pub static CALIBNET_DRIP_AMOUNT: LazyLock = LazyLock::new(|| TokenAmount::from_whole(1)); +pub static FIL_MAINNET_UNIT: &str = "FIL"; +pub static FIL_CALIBNET_UNIT: &str = "tFIL"; diff --git a/src/faucet/controller.rs b/src/faucet/controller.rs index 58b9b03..ef26629 100644 --- a/src/faucet/controller.rs +++ b/src/faucet/controller.rs @@ -61,6 +61,7 @@ impl FaucetController { }, Some(TokenAmount::from_atto(0)), ); + let faucet = FaucetModel { network, send_disabled: create_rw_signal(false), @@ -117,6 +118,14 @@ impl FaucetController { self.faucet.target_address.get() } + pub fn get_fil_unit(&self) -> String { + match self.faucet.network { + Network::Mainnet => crate::constants::FIL_MAINNET_UNIT, + _ => crate::constants::FIL_CALIBNET_UNIT, + } + .to_string() + } + pub fn set_target_address(&self, address: String) { self.faucet.target_address.set(address); } diff --git a/src/faucet/views.rs b/src/faucet/views.rs index 6d24cd9..e3407b2 100644 --- a/src/faucet/views.rs +++ b/src/faucet/views.rs @@ -10,6 +10,7 @@ use crate::faucet::controller::FaucetController; #[component] pub fn Faucet(target_network: Network) -> impl IntoView { let faucet = create_rw_signal(FaucetController::new(target_network)); + let fil_unit = faucet.get().get_fil_unit(); #[cfg(feature = "hydrate")] let _ = use_interval_fn( @@ -117,11 +118,11 @@ pub fn Faucet(target_network: Network) -> impl IntoView {

Faucet Balance:

-

{move || faucet.get().get_faucet_balance().to_string()}

+

{move || faucet.get().get_faucet_balance().to_string()} " " { &fil_unit }

Target Balance:

-

{move || faucet.get().get_target_balance().to_string()}

+

{move || faucet.get().get_target_balance().to_string()} " " { &fil_unit }


@@ -174,7 +175,7 @@ pub fn Faucet_Calibnet() -> impl IntoView {
- "This faucet distributes 1 tFIL per request. It is rate-limited to 1 request per " {crate::constants::RATE_LIMIT_SECONDS} " seconds. Farming is discouraged and will result in more stringent rate limiting in the future and/or permanent bans." + "This faucet distributes 1 " { crate::constants::FIL_CALIBNET_UNIT } " per request. It is rate-limited to 1 request per " {crate::constants::RATE_LIMIT_SECONDS} " seconds. Farming is discouraged and will result in more stringent rate limiting in the future and/or permanent bans."
} } @@ -186,7 +187,7 @@ pub fn Faucet_Mainnet() -> impl IntoView {

Mainnet Faucet

- "This faucet distributes 0.01 FIL per request. It is rate-limited to 1 request per " {crate::constants::RATE_LIMIT_SECONDS} " seconds. Farming is discouraged and will result in more stringent rate limiting in the future and/or permanent bans or service termination. Faucet funds are limited and may run out. They are replenished periodically." + "This faucet distributes 0.01 " { crate::constants::FIL_MAINNET_UNIT } " per request. It is rate-limited to 1 request per " {crate::constants::RATE_LIMIT_SECONDS} " seconds. Farming is discouraged and will result in more stringent rate limiting in the future and/or permanent bans or service termination. Faucet funds are limited and may run out. They are replenished periodically."
}