Browse Source

feat(bindings): js bindings send

thesimplekid 10 months ago
parent
commit
4cc02b7770
2 changed files with 18 additions and 2 deletions
  1. 17 1
      bindings/cdk-js/src/wallet.rs
  2. 1 1
      crates/cdk-rexie/src/wallet.rs

+ 17 - 1
bindings/cdk-js/src/wallet.rs

@@ -5,7 +5,7 @@ use std::sync::Arc;
 use cdk::nuts::SigningKey;
 use cdk::url::UncheckedUrl;
 use cdk::wallet::Wallet;
-use cdk::HttpClient;
+use cdk::{Amount, HttpClient};
 use cdk_rexie::RexieWalletDatabase;
 use wasm_bindgen::prelude::*;
 
@@ -147,4 +147,20 @@ impl JsWallet {
 
         Ok(())
     }
+
+    #[wasm_bindgen(js_name = send)]
+    pub async fn send(
+        &mut self,
+        mint_url: String,
+        unit: JsCurrencyUnit,
+        memo: Option<String>,
+        amount: u64,
+    ) -> Result<String> {
+        let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?;
+
+        self.inner
+            .send(&mint_url, &unit.into(), memo, Amount::from(amount), None)
+            .await
+            .map_err(into_err)
+    }
 }

+ 1 - 1
crates/cdk-rexie/src/wallet.rs

@@ -485,7 +485,7 @@ impl WalletDatabase for RexieWalletDatabase {
             let proofs = serde_wasm_bindgen::to_value(&proofs).map_err(Error::from)?;
 
             proofs_store
-                .add(&proofs, Some(&mint_url))
+                .put(&proofs, Some(&mint_url))
                 .await
                 .map_err(Error::from)?;
         }