-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2024 Yuki Kishimoto | ||
// Distributed under the MIT software license | ||
|
||
use std::ops::Deref; | ||
|
||
use wasm_bindgen::prelude::*; | ||
use webln::{RequestInvoiceArgs, RequestInvoiceResponse}; | ||
|
||
#[wasm_bindgen(js_name = RequestInvoiceArgs)] | ||
pub struct JsRequestInvoiceArgs { | ||
inner: RequestInvoiceArgs, | ||
} | ||
|
||
impl Deref for JsRequestInvoiceArgs { | ||
type Target = RequestInvoiceArgs; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.inner | ||
} | ||
} | ||
|
||
impl From<RequestInvoiceArgs> for JsRequestInvoiceArgs { | ||
fn from(inner: RequestInvoiceArgs) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_class = RequestInvoiceArgs)] | ||
impl JsRequestInvoiceArgs { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new() -> Self { | ||
Self { | ||
inner: RequestInvoiceArgs::default(), | ||
} | ||
} | ||
|
||
pub fn amount(self, amount: u32) -> Self { | ||
self.inner.amount(amount as u64).into() | ||
} | ||
|
||
#[wasm_bindgen(js_name = defaultAmount)] | ||
pub fn default_amount(self, default_amount: u32) -> Self { | ||
self.inner.default_amount(default_amount as u64).into() | ||
} | ||
|
||
#[wasm_bindgen(js_name = minimumAmount)] | ||
pub fn minimum_amount(self, minimum_amount: u32) -> Self { | ||
self.inner.minimum_amount(minimum_amount as u64).into() | ||
} | ||
|
||
#[wasm_bindgen(js_name = maximumAmount)] | ||
pub fn maximum_amount(self, maximum_amount: u32) -> Self { | ||
self.inner.maximum_amount(maximum_amount as u64).into() | ||
} | ||
|
||
#[wasm_bindgen(js_name = defaultMemo)] | ||
pub fn default_memo(self, default_memo: String) -> Self { | ||
self.inner.default_memo(default_memo).into() | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name = RequestInvoiceResponse)] | ||
pub struct JsRequestInvoiceResponse { | ||
inner: RequestInvoiceResponse, | ||
} | ||
|
||
impl From<RequestInvoiceResponse> for JsRequestInvoiceResponse { | ||
fn from(inner: RequestInvoiceResponse) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_class = RequestInvoiceResponse)] | ||
impl JsRequestInvoiceResponse { | ||
#[wasm_bindgen(getter)] | ||
pub fn invoice(&self) -> String { | ||
self.inner.invoice.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters