// file: crates/ksp-app-wallet-desk/src/wallet_balance.rs // version: 1 //! Safe Wallet balance projection produced by the typed HTTP Transport path. use ts_rs::TS; // rust-rules: trait-import /// Safe balance snapshot for the currently authorized Wallet. #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, TS)] #[serde(rename_all = "camelCase")] #[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_balance/WalletBalanceDto.ts")] pub(crate) struct WalletBalanceDto { /// Optional Solana RPC API version reported by the selected node. pub(crate) api_version: std::option::Option, /// Exact decimal account balance in lamports, encoded as text to avoid JavaScript integer precision loss. pub(crate) lamports: String, /// RPC context slot associated with this balance. pub(crate) slot: u64, /// Exact decimal SOL presentation derived from lamports without floating point. pub(crate) sol: String, /// Composite-selected Transport profile used for the RPC. pub(crate) transport_profile: String, /// Logical Transport role used for the RPC. pub(crate) transport_role: String, /// Root-scoped Wallet identifier whose authorized Pubkey was queried. pub(crate) wallet_id: String, } /// Formats exact lamports as a decimal SOL string with nine fractional digits. #[must_use] pub(crate) fn format_lamports_as_sol(lamports: u64) -> String { let whole = lamports / 1_000_000_000; let fractional = lamports % 1_000_000_000; return format!("{whole}.{fractional:09}"); } #[cfg(test)] #[path = "../unit_tests/wallet_balance.rs"] mod tests;