Skip to content

Commit

Permalink
Modifs in typescript (#441)
Browse files Browse the repository at this point in the history
* Fix structs

* Add methods to web.rs and update rgb.ts

* Update web.rs

Co-authored-by: Armando CD <[email protected]>

* Update rgb.ts

Co-authored-by: Armando CD <[email protected]>

* Update rgb.ts

Co-authored-by: Armando CD <[email protected]>

---------

Co-authored-by: Jose Diego Robles Pardo <[email protected]>
Co-authored-by: Armando CD <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent 97c8423 commit 7e58a09
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
38 changes: 37 additions & 1 deletion 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 createAuctionBid = async (
nostrHexSk: string,
request: RgbAuctionBidRequest
): Promise<RgbAuctionBidResponse> =>
JSON.parse(await BMC.create_auction_bid(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 Expand Up @@ -935,9 +950,30 @@ export interface PublicRgbOfferResponse {
/// Bitcoin Price
bitcoinPrice: bigint;
/// Initial Offer PSBT
offerPsbt: string;
offerPsbt?: string;
}

export interface RgbAuctionFinishResponse {
/// Bundle ID
bundle_id: string,
/// New Change Outpoint
outpoint: string,
/// Sold Items
sold: Map<string, RgbSwapItem>,
/// Reamining Items
remaining: Map<string, RgbSwapItem>,
}

export interface RgbSwapItem {
/// Contract ID
contractId: string,
/// Iface
iface: string,
/// Final Consig
contractAmount: string,
}


export interface PublicRgbBidResponse {
/// Bid ID
bidId: string;
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_bid(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 7e58a09

Please sign in to comment.