diff --git a/bindings/nostr-ffi/src/event/builder.rs b/bindings/nostr-ffi/src/event/builder.rs index 1c403af86..a3389f7c5 100644 --- a/bindings/nostr-ffi/src/event/builder.rs +++ b/bindings/nostr-ffi/src/event/builder.rs @@ -13,7 +13,7 @@ use super::{Event, EventId}; use crate::error::Result; use crate::helper::unwrap_or_clone_arc; use crate::key::Keys; -use crate::nips::nip15::{ProductData, StallData}; +use crate::nips::nip15::{ProductData, StallDataRecord}; use crate::nips::nip53::LiveEvent; use crate::nips::nip57::ZapRequestData; use crate::nips::nip90::DataVendingMachineStatus; @@ -464,10 +464,10 @@ impl EventBuilder { } #[uniffi::constructor] - pub fn stall_data(data: Arc) -> Arc { - Arc::new(Self { - inner: nostr::EventBuilder::stall_data(data.as_ref().deref().clone()), - }) + pub fn stall_data(data: StallDataRecord) -> Self { + Self { + inner: nostr::EventBuilder::stall_data(data.into()), + } } #[uniffi::constructor] diff --git a/bindings/nostr-ffi/src/nips/nip15.rs b/bindings/nostr-ffi/src/nips/nip15.rs index 5e6c588f9..c4fa309fc 100644 --- a/bindings/nostr-ffi/src/nips/nip15.rs +++ b/bindings/nostr-ffi/src/nips/nip15.rs @@ -12,6 +12,44 @@ use crate::error::Result; use crate::helper::unwrap_or_clone_arc; /// Payload for creating or updating stall +#[derive(Record)] +pub struct StallDataRecord { + /// UUID of the stall generated by merchant + pub id: String, + /// Stall name + pub name: String, + /// Stall description + pub description: Option, + /// Currency used + pub currency: String, + /// Available shipping methods + pub shipping: Vec, +} + +impl From for nip15::StallData { + fn from(value: StallDataRecord) -> Self { + Self { + id: value.id, + name: value.name, + description: value.description, + currency: value.currency, + shipping: value.shipping.into_iter().map(|s| s.into()).collect(), + } + } +} + +impl From for StallDataRecord { + fn from(value: nip15::StallData) -> Self { + Self { + id: value.id, + name: value.name, + description: value.description, + currency: value.currency, + shipping: value.shipping.into_iter().map(|s| s.into()).collect(), + } + } +} + #[derive(Object)] pub struct StallData { inner: nip15::StallData, @@ -55,6 +93,11 @@ impl StallData { } } + #[uniffi::constructor] + pub fn from_record(r: StallDataRecord) -> Self { + Self { inner: r.into() } + } + #[uniffi::constructor] pub fn from_json(json: String) -> Result { Ok(nip15::StallData::from_json(json)?.into()) @@ -85,6 +128,10 @@ impl StallData { .collect() } + pub fn as_record(&self) -> StallDataRecord { + self.inner.clone().into() + } + pub fn as_json(&self) -> String { self.inner.as_json() } @@ -135,6 +182,40 @@ impl From for nip15::ProductData { } } +#[derive(Record)] +pub struct ShippingMethodRecord { + /// Shipping method unique id by merchant + pub id: String, + /// Shipping method name + pub name: Option, + /// Shipping method cost (currency is the same as the stall) + pub cost: f64, + /// Covered regions + pub regions: Vec, +} + +impl From for ShippingMethodRecord { + fn from(value: nip15::ShippingMethod) -> Self { + Self { + id: value.id, + name: value.name, + cost: value.cost, + regions: value.regions, + } + } +} + +impl From for nip15::ShippingMethod { + fn from(value: ShippingMethodRecord) -> Self { + Self { + id: value.id, + name: value.name, + cost: value.cost, + regions: value.regions, + } + } +} + #[derive(Clone, Object)] pub struct ShippingMethod { inner: nip15::ShippingMethod,