Skip to content

Commit

Permalink
Add methods to web.rs and update rgb.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
josediegorobles committed Dec 18, 2023
1 parent e0e8770 commit 1271601
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/web/rgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ export const createOffer = async (
): Promise<RgbOfferResponse> =>
JSON.parse(await BMC.create_offer(nostrHexSk, request));

export const createAuction = async (
nostrHexSk: string,
request: RgbAuctionBidRequest
): Promise<RgbAuctionBidResponse> =>
JSON.parse(await BMC.create_auction(nostrHexSk, request));

export const createBid = async (
nostrHexSk: string,
request: RgbBidRequest
Expand All @@ -169,6 +175,15 @@ export const createSwap = async (
): Promise<RgbSwapResponse> =>
JSON.parse(await BMC.create_swap(nostrHexSk, request));

export const finishAuction = async (
nostrHexSk: string,
request: string
): Promise<RgbAuctionOfferResponse[]> =>
JSON.parse(await BMC.finish_auction(nostrHexSk, request));

export const listAuctions = async (): Promise<RgbOffersResponse> =>
JSON.parse(await BMC.list_auctions());

export const directSwap = async (
nostrHexSk: string,
request: RgbBidRequest
Expand Down
48 changes: 46 additions & 2 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use crate::rgb::structs::ContractAmount;
use crate::structs::{
AcceptRequest, FullIssueRequest, FullRgbTransferRequest, ImportRequest, InvoiceRequest,
IssueMediaRequest, IssueRequest, MediaRequest, PsbtRequest, PublishPsbtRequest, ReIssueRequest,
RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest, RgbSaveTransferRequest,
RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest, WatcherRequest,
RgbAuctionBidRequest, RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest,
RgbSaveTransferRequest, RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest,
WatcherRequest,
};

pub fn set_panic_hook() {
Expand Down Expand Up @@ -874,6 +875,21 @@ pub mod rgb {
})
}

#[wasm_bindgen]
pub fn create_auction(nostr_hex_sk: String, request: JsValue) -> Promise {
set_panic_hook();

future_to_promise(async move {
let bid_req: RgbAuctionBidRequest = serde_wasm_bindgen::from_value(request).unwrap();
match crate::rgb::create_auction_bid(&nostr_hex_sk, bid_req).await {
Ok(result) => Ok(JsValue::from_string(
serde_json::to_string(&result).unwrap(),
)),
Err(err) => Err(JsValue::from_string(err.to_string())),
}
})
}

#[wasm_bindgen]
pub fn create_bid(nostr_hex_sk: String, request: JsValue) -> Promise {
set_panic_hook();
Expand Down Expand Up @@ -904,6 +920,34 @@ pub mod rgb {
})
}

#[wasm_bindgen]
pub fn finish_auction(nostr_hex_sk: String, request: JsValue) -> Promise {
set_panic_hook();

future_to_promise(async move {
let bundle_id: String = serde_wasm_bindgen::from_value(request).unwrap();
match crate::rgb::finish_auction_offers(&nostr_hex_sk, bundle_id).await {
Ok(result) => Ok(JsValue::from_string(
serde_json::to_string(&result).unwrap(),
)),
Err(err) => Err(JsValue::from_string(err.to_string())),
}
})
}

#[wasm_bindgen]
pub fn list_auctions() -> Promise {
set_panic_hook();

future_to_promise(async move {
match crate::rgb::list_auctions().await {
Ok(result) => Ok(JsValue::from_string(
serde_json::to_string(&result).unwrap(),
)),
Err(err) => Err(JsValue::from_string(err.to_string())),
}
})
}
#[wasm_bindgen]
pub fn direct_swap(nostr_hex_sk: String, request: JsValue) -> Promise {
set_panic_hook();
Expand Down

0 comments on commit 1271601

Please sign in to comment.