Browse Source

feat(wallet): total balance

thesimplekid 11 months ago
parent
commit
f7b79e9e8e
1 changed files with 16 additions and 0 deletions
  1. 16 0
      crates/cdk/src/wallet.rs

+ 16 - 0
crates/cdk/src/wallet.rs

@@ -124,6 +124,22 @@ impl Wallet {
         self.mnemonic.clone()
     }
 
+    /// Total Balance of wallet
+    pub async fn total_balance(&self) -> Result<Amount, Error> {
+        let mints = self.localstore.get_mints().await?;
+        let mut balance = Amount::ZERO;
+
+        for (mint, _) in mints {
+            if let Some(proofs) = self.localstore.get_proofs(mint.clone()).await? {
+                let amount = proofs.iter().map(|p| p.amount).sum();
+
+                balance += amount;
+            }
+        }
+
+        Ok(balance)
+    }
+
     pub async fn mint_balances(&self) -> Result<HashMap<UncheckedUrl, Amount>, Error> {
         let mints = self.localstore.get_mints().await?;