feat: add mint_icon_url to mint details. (#282)

This commit is contained in:
Caleb Beery
2024-08-10 14:57:02 -07:00
committed by GitHub
parent a94c0630fd
commit da1acc4e6d
7 changed files with 41 additions and 4 deletions

View File

@@ -77,6 +77,7 @@ impl JsMintInfo {
description_long: Option<String>,
contact: Option<Vec<JsContactInfo>>,
nuts: JsValue,
mint_icon_url: Option<String>,
motd: Option<String>,
) -> Result<JsMintInfo> {
Ok(JsMintInfo {
@@ -89,6 +90,7 @@ impl JsMintInfo {
contact: contact
.map(|contacts| contacts.iter().map(|c| c.deref().clone()).collect()),
nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?,
mint_icon_url,
motd,
},
})
@@ -139,6 +141,12 @@ impl JsMintInfo {
serde_wasm_bindgen::to_value(&self.inner.nuts).map_err(into_err)
}
/// Get mint icon url
#[wasm_bindgen(getter)]
pub fn mint_icon_url(&self) -> Option<String> {
self.inner.mint_icon_url.clone()
}
/// Get motd
#[wasm_bindgen(getter)]
pub fn motd(&self) -> Option<String> {

View File

@@ -14,6 +14,7 @@ mnemonic = ""
# description = "These are not real sats for testing only"
# description_long = "A longer mint for testing"
# motd = "Hello world"
# mint_icon_url = "https://this-is-a-mint-icon-url.com/icon.png"
# contact_email = "hello@cashu.me"
# Nostr pubkey of mint (Hex)
# contact_nostr_public_key = ""

View File

@@ -92,6 +92,8 @@ pub struct MintInfo {
pub description: String,
/// long description
pub description_long: Option<String>,
/// url to the mint icon
pub mint_icon_url: Option<String>,
/// message of the day that the wallet must display to the user
pub motd: Option<String>,
/// Nostr publickey

View File

@@ -286,6 +286,10 @@ async fn main() -> anyhow::Result<()> {
mint_info = mint_info.pubkey(pubkey);
}
if let Some(mint_icon_url) = &settings.mint_info.mint_icon_url {
mint_info = mint_info.mint_icon_url(mint_icon_url);
}
if let Some(motd) = settings.mint_info.motd {
mint_info = mint_info.motd(motd);
}

View File

@@ -0,0 +1 @@
ALTER TABLE mint ADD mint_icon_url TEXT;

View File

@@ -65,7 +65,7 @@ impl WalletDatabase for WalletSqliteDatabase {
mint_url: UncheckedUrl,
mint_info: Option<MintInfo>,
) -> Result<(), Self::Err> {
let (name, pubkey, version, description, description_long, contact, nuts, motd) =
let (name, pubkey, version, description, description_long, contact, nuts, mint_icon_url, motd) =
match mint_info {
Some(mint_info) => {
let MintInfo {
@@ -76,6 +76,7 @@ impl WalletDatabase for WalletSqliteDatabase {
description_long,
contact,
nuts,
mint_icon_url,
motd,
} = mint_info;
@@ -87,17 +88,18 @@ impl WalletDatabase for WalletSqliteDatabase {
description_long,
contact.map(|c| serde_json::to_string(&c).ok()),
serde_json::to_string(&nuts).ok(),
mint_icon_url,
motd,
)
}
None => (None, None, None, None, None, None, None, None),
None => (None, None, None, None, None, None, None, None, None),
};
sqlx::query(
r#"
INSERT OR REPLACE INTO mint
(mint_url, name, pubkey, version, description, description_long, contact, nuts, motd)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
(mint_url, name, pubkey, version, description, description_long, contact, nuts, mint_icon_url, motd)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
"#,
)
.bind(mint_url.to_string())
@@ -108,6 +110,7 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
.bind(description_long)
.bind(contact)
.bind(nuts)
.bind(mint_icon_url)
.bind(motd)
.execute(&self.pool)
.await
@@ -727,6 +730,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
let description_long: Option<String> = row.try_get("description_long").map_err(Error::from)?;
let row_contact: Option<String> = row.try_get("contact").map_err(Error::from)?;
let row_nuts: Option<String> = row.try_get("nuts").map_err(Error::from)?;
let mint_icon_url: Option<String> = row.try_get("mint_icon_url").map_err(Error::from)?;
let motd: Option<String> = row.try_get("motd").map_err(Error::from)?;
Ok(MintInfo {
@@ -739,6 +743,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
nuts: row_nuts
.and_then(|n| serde_json::from_str(&n).ok())
.unwrap_or_default(),
mint_icon_url,
motd,
})
}

View File

@@ -73,6 +73,9 @@ pub struct MintInfo {
pub contact: Option<Vec<ContactInfo>>,
/// shows which NUTs the mint supports
pub nuts: Nuts,
/// Mint's icon URL
#[serde(skip_serializing_if = "Option::is_none")]
pub mint_icon_url: Option<String>,
/// message of the day that the wallet must display to the user
#[serde(skip_serializing_if = "Option::is_none")]
pub motd: Option<String>,
@@ -146,6 +149,17 @@ impl MintInfo {
Self { nuts, ..self }
}
/// Set mint icon url
pub fn mint_icon_url<S>(self, mint_icon_url: S) -> Self
where
S: Into<String>,
{
Self {
mint_icon_url: Some(mint_icon_url.into()),
..self
}
}
/// Set motd
pub fn motd<S>(self, motd: S) -> Self
where
@@ -389,6 +403,7 @@ mod tests {
}
],
"motd": "Message to display to users.",
"mint_icon_url": "https://this-is-a-mint-icon-url.com/icon.png",
"nuts": {
"4": {
"methods": [
@@ -431,6 +446,7 @@ mod tests {
["email", "contact@me.com"]
],
"motd": "Message to display to users.",
"mint_icon_url": "https://this-is-a-mint-icon-url.com/icon.png",
"nuts": {
"4": {
"methods": [