Pārlūkot izejas kodu

feat(NUT06): contact info update

thesimplekid 10 mēneši atpakaļ
vecāks
revīzija
76c096c780

+ 49 - 5
bindings/cdk-js/src/nuts/nut06.rs

@@ -1,6 +1,7 @@
 use std::ops::Deref;
 
 use cdk::nuts::nut06::{MintInfo, MintVersion};
+use cdk::nuts::ContactInfo;
 use wasm_bindgen::prelude::*;
 
 use super::nut01::JsPublicKey;
@@ -74,7 +75,7 @@ impl JsMintInfo {
         version: Option<JsMintVersion>,
         description: Option<String>,
         description_long: Option<String>,
-        contact: JsValue,
+        contact: Option<Vec<JsContactInfo>>,
         nuts: JsValue,
         motd: Option<String>,
     ) -> Result<JsMintInfo> {
@@ -85,7 +86,8 @@ impl JsMintInfo {
                 version: version.map(|v| v.deref().clone()),
                 description,
                 description_long,
-                contact: serde_wasm_bindgen::from_value(contact).map_err(into_err)?,
+                contact: contact
+                    .map(|contacts| contacts.iter().map(|c| c.deref().clone()).collect()),
                 nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?,
                 motd,
             },
@@ -122,10 +124,13 @@ impl JsMintInfo {
         self.inner.description_long.clone()
     }
 
-    /// Get contact
+    /// Get contact info
     #[wasm_bindgen(getter)]
-    pub fn contact(&self) -> Result<JsValue> {
-        serde_wasm_bindgen::to_value(&self.inner.contact).map_err(into_err)
+    pub fn contact(&self) -> Option<Vec<JsContactInfo>> {
+        self.inner
+            .contact
+            .clone()
+            .map(|c| c.into_iter().map(|c| c.into()).collect())
     }
 
     /// Get supported nuts
@@ -140,3 +145,42 @@ impl JsMintInfo {
         self.inner.motd.clone()
     }
 }
+
+#[wasm_bindgen(js_name = ContactInfo)]
+pub struct JsContactInfo {
+    inner: ContactInfo,
+}
+
+impl Deref for JsContactInfo {
+    type Target = ContactInfo;
+    fn deref(&self) -> &Self::Target {
+        &self.inner
+    }
+}
+
+impl From<ContactInfo> for JsContactInfo {
+    fn from(inner: ContactInfo) -> JsContactInfo {
+        JsContactInfo { inner }
+    }
+}
+
+#[wasm_bindgen(js_class = ContactInfo)]
+impl JsContactInfo {
+    #[wasm_bindgen(constructor)]
+    pub fn new(method: String, info: String) -> Result<JsContactInfo> {
+        Ok(JsContactInfo {
+            inner: ContactInfo { method, info },
+        })
+    }
+    /// Method
+    #[wasm_bindgen(getter)]
+    pub fn method(&self) -> String {
+        self.inner.method.clone()
+    }
+
+    /// Info
+    #[wasm_bindgen(getter)]
+    pub fn info(&self) -> String {
+        self.inner.info.clone()
+    }
+}

+ 1 - 1
crates/cdk/src/nuts/mod.rs

@@ -34,7 +34,7 @@ pub use nut05::{
     MeltBolt11Request, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteBolt11Response,
     QuoteState as MeltQuoteState, Settings as NUT05Settings,
 };
-pub use nut06::{MintInfo, MintVersion, Nuts};
+pub use nut06::{ContactInfo, MintInfo, MintVersion, Nuts};
 pub use nut07::{CheckStateRequest, CheckStateResponse, ProofState, State};
 pub use nut09::{RestoreRequest, RestoreResponse};
 pub use nut10::{Kind, Secret as Nut10Secret, SecretData};

+ 15 - 5
crates/cdk/src/nuts/nut06.rs

@@ -59,9 +59,9 @@ pub struct MintInfo {
     /// long description
     #[serde(skip_serializing_if = "Option::is_none")]
     pub description_long: Option<String>,
-    /// contact methods to reach the mint operator
+    /// Contact info
     #[serde(skip_serializing_if = "Option::is_none")]
-    pub contact: Option<Vec<Vec<String>>>,
+    pub contact: Option<Vec<ContactInfo>>,
     /// shows which NUTs the mint supports
     pub nuts: Nuts,
     /// message of the day that the wallet must display to the user
@@ -119,6 +119,15 @@ impl Default for SupportedSettings {
     }
 }
 
+/// Contact Info
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+pub struct ContactInfo {
+    /// Contact Method i.e. nostr
+    pub method: String,
+    /// Contact info i.e. npub...
+    pub info: String,
+}
+
 #[cfg(test)]
 mod tests {
 
@@ -148,9 +157,10 @@ mod tests {
   "description": "The short mint description",
   "description_long": "A description that can be a long piece of text.",
   "contact": [
-    ["email", "contact@me.com"],
-    ["twitter", "@me"],
-    ["nostr" ,"npub..."]
+    {
+        "method": "email",
+        "info": "contact@me.com"
+    }
   ],
   "motd": "Message to display to users.",
   "nuts": {