diff --git a/webln-js/src/lib.rs b/webln-js/src/lib.rs index 0e8d46e..24d8703 100644 --- a/webln-js/src/lib.rs +++ b/webln-js/src/lib.rs @@ -74,7 +74,7 @@ impl JsWebLN { // TODO: add `make_invoice` - // Request that the user sends a payment for an invoice. + /// Request that the user sends a payment for an invoice. #[wasm_bindgen(js_name = sendPayment)] pub async fn send_payment(&self, invoice: String) -> Result { Ok(self @@ -84,4 +84,16 @@ impl JsWebLN { .map_err(into_err)? .into()) } + + /// Request that the user sends a payment for an invoice. + /// The payment will only be initiated and will not wait for a preimage to be returned. + /// This is useful when paying HOLD Invoices. There is no guarantee that the payment will be successfully sent to the receiver. + /// It's up to the receiver to check whether or not the invoice has been paid. + #[wasm_bindgen(js_name = sendPaymentAsync)] + pub async fn send_payment_async(&self, invoice: String) -> Result<()> { + self.inner + .send_payment_async(invoice) + .await + .map_err(into_err) + } } diff --git a/webln/src/lib.rs b/webln/src/lib.rs index 094fb0d..bfd8727 100644 --- a/webln/src/lib.rs +++ b/webln/src/lib.rs @@ -19,6 +19,7 @@ pub const GET_INFO: &str = "getInfo"; pub const KEYSEND: &str = "keysend"; // pub const MAKE_INVOICE: &str = "makeInvoice"; pub const SEND_PAYMENT: &str = "sendPayment"; +pub const SEND_PAYMENT_ASYNC: &str = "sendPaymentAsync"; /// WebLN error #[derive(Debug)] @@ -93,7 +94,7 @@ where KEYSEND => Self::Keysend, "makeInvoice" => Self::MakeInvoice, SEND_PAYMENT => Self::SendPayment, - "sendPaymentAsync" => Self::SendPaymentAsync, + SEND_PAYMENT_ASYNC => Self::SendPaymentAsync, "signMessage" => Self::SignMessage, "verifyMessage" => Self::VerifyMessage, "request" => Self::Request, @@ -115,7 +116,7 @@ impl fmt::Display for GetInfoMethod { Self::Keysend => write!(f, "{KEYSEND}"), Self::MakeInvoice => write!(f, "makeInvoice"), Self::SendPayment => write!(f, "{SEND_PAYMENT}"), - Self::SendPaymentAsync => write!(f, "sendPaymentAsync"), + Self::SendPaymentAsync => write!(f, "{SEND_PAYMENT_ASYNC}"), Self::SignMessage => write!(f, "signMessage"), Self::VerifyMessage => write!(f, "verifyMessage"), Self::Request => write!(f, "request"), @@ -269,7 +270,7 @@ impl WebLN { // TODO: add `make_invoice` - // Request that the user sends a payment for an invoice. + /// Request that the user sends a payment for an invoice. pub async fn send_payment(&self, invoice: String) -> Result { let func: Function = self.get_func(&self.webln_obj, SEND_PAYMENT)?; let promise: Promise = Promise::resolve(&func.call1(&self.webln_obj, &invoice.into())?); @@ -282,4 +283,15 @@ impl WebLN { .ok_or_else(|| Error::TypeMismatch(String::from("expected a string [preimage]")))?, }) } + + /// Request that the user sends a payment for an invoice. + /// The payment will only be initiated and will not wait for a preimage to be returned. + /// This is useful when paying HOLD Invoices. There is no guarantee that the payment will be successfully sent to the receiver. + /// It's up to the receiver to check whether or not the invoice has been paid. + pub async fn send_payment_async(&self, invoice: String) -> Result<(), Error> { + let func: Function = self.get_func(&self.webln_obj, SEND_PAYMENT_ASYNC)?; + let promise: Promise = Promise::resolve(&func.call1(&self.webln_obj, &invoice.into())?); + JsFuture::from(promise).await?; + Ok(()) + } }