use js_export_macro::js_export;
use miden_client::Felt as NativeFelt;
use miden_client::account::Account as NativeAccount;
use miden_client::account::component::FungibleFaucet as NativeFungibleFaucet;
use super::account::Account;
use super::felt::Felt;
use super::token_symbol::TokenSymbol;
use crate::js_error_with_context;
use crate::platform::JsErr;
#[js_export]
pub struct BasicFungibleFaucetComponent(NativeFungibleFaucet);
#[js_export]
impl BasicFungibleFaucetComponent {
#[js_export(js_name = "fromAccount")]
#[allow(clippy::needless_pass_by_value)]
pub fn from_account(account: Account) -> Result<Self, JsErr> {
let native_account: NativeAccount = account.into();
let faucet = NativeFungibleFaucet::try_from(&native_account).map_err(|e| {
js_error_with_context(e, "failed to get basic fungible faucet details from account")
})?;
Ok(Self(faucet))
}
pub fn symbol(&self) -> TokenSymbol {
self.0.symbol().into()
}
pub fn decimals(&self) -> u8 {
self.0.decimals()
}
#[js_export(js_name = "maxSupply")]
pub fn max_supply(&self) -> Felt {
NativeFelt::from(self.0.max_supply()).into()
}
}