Skip to content

Commit

Permalink
js(nostr): add EventBuilder::job_feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rustedmoon committed Jan 31, 2024
1 parent 4b3d421 commit 47028b8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bindings/nostr-js/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::error::{into_err, Result};
use crate::key::{JsKeys, JsPublicKey};
use crate::nips::nip57::JsZapRequestData;
use crate::nips::nip65::JsRelayListItem;
use crate::nips::nip90::JsDataVendingMachineStatus;
use crate::types::{JsContact, JsMetadata};

#[wasm_bindgen(js_name = EventBuilder)]
Expand Down Expand Up @@ -301,4 +302,25 @@ impl JsEventBuilder {
.map_err(into_err)?,
})
}

#[wasm_bindgen(js_name = jobFeedback)]
pub fn job_feedback(
job_request: &JsEvent,
status: JsDataVendingMachineStatus,
extra_info: Option<String>,
amount_millisats: u64,
bolt11: Option<String>,
payload: Option<String>,
) -> Self {
Self {
builder: EventBuilder::job_feedback(
job_request.deref(),
status.into(),
extra_info,
amount_millisats,
bolt11,
payload,
),
}
}
}
1 change: 1 addition & 0 deletions bindings/nostr-js/src/nips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pub mod nip46;
pub mod nip47;
pub mod nip57;
pub mod nip65;
pub mod nip90;
38 changes: 38 additions & 0 deletions bindings/nostr-js/src/nips/nip90.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

use nostr::nips::nip90::DataVendingMachineStatus;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_name = DataVendingMachineStatus)]
pub enum JsDataVendingMachineStatus {
PaymentRequired,
Processing,
Error,
Success,
Partial,
}

impl From<DataVendingMachineStatus> for JsDataVendingMachineStatus {
fn from(value: DataVendingMachineStatus) -> Self {
match value {
DataVendingMachineStatus::PaymentRequired => Self::PaymentRequired,
DataVendingMachineStatus::Processing => Self::Processing,
DataVendingMachineStatus::Error => Self::Error,
DataVendingMachineStatus::Success => Self::Success,
DataVendingMachineStatus::Partial => Self::Partial,
}
}
}

impl From<JsDataVendingMachineStatus> for DataVendingMachineStatus {
fn from(value: JsDataVendingMachineStatus) -> Self {
match value {
JsDataVendingMachineStatus::PaymentRequired => Self::PaymentRequired,
JsDataVendingMachineStatus::Processing => Self::Processing,
JsDataVendingMachineStatus::Error => Self::Error,
JsDataVendingMachineStatus::Success => Self::Success,
JsDataVendingMachineStatus::Partial => Self::Partial,
}
}
}

0 comments on commit 47028b8

Please sign in to comment.