Skip to content

Commit

Permalink
test: finish wasm use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Dec 21, 2023
1 parent 2e5a3d8 commit 0b5a312
Show file tree
Hide file tree
Showing 3 changed files with 1,072 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/carbonado.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ mod client {
use gloo_net::http::Request;
use gloo_utils::errors::JsError;

use crate::constants::CARBONADO_ENDPOINT;
use crate::constants::{BITMASK_ENDPOINT, CARBONADO_ENDPOINT};

fn js_to_error(js_value: JsValue) -> CarbonadoError {
CarbonadoError::JsError(js_to_js_error(js_value))
Expand Down Expand Up @@ -421,7 +421,7 @@ mod client {
) -> Result<(), CarbonadoError> {
let body = Arc::new(input.to_vec());
let network = NETWORK.read().await.to_string();
let endpoints = CARBONADO_ENDPOINT.read().await.to_string();
let endpoints = BITMASK_ENDPOINT.read().await.to_string();
let endpoints: Vec<&str> = endpoints.split(',').collect();
let requests = Array::new();

Expand Down Expand Up @@ -563,7 +563,7 @@ mod client {
name: &str,
) -> Result<(Vec<u8>, Option<Vec<u8>>), CarbonadoError> {
let network = NETWORK.read().await.to_string();
let endpoints = CARBONADO_ENDPOINT.read().await.to_string();
let endpoints = BITMASK_ENDPOINT.read().await.to_string();
let endpoints: Vec<&str> = endpoints.split(',').collect();

let requests = Array::new();
Expand Down
19 changes: 17 additions & 2 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::structs::{
AcceptRequest, FullIssueRequest, FullRgbTransferRequest, ImportRequest, InvoiceRequest,
IssueMediaRequest, IssueRequest, MediaRequest, PsbtRequest, PublishPsbtRequest, ReIssueRequest,
RgbAuctionBidRequest, RgbAuctionOfferRequest, RgbBidRequest, RgbOfferRequest,
RgbRemoveTransferRequest, RgbSaveTransferRequest, RgbSwapRequest, RgbTransferRequest,
SecretString, SignPsbtRequest, WatcherRequest,
RgbOfferUpdateRequest, RgbRemoveTransferRequest, RgbSaveTransferRequest, RgbSwapRequest,
RgbTransferRequest, SecretString, SignPsbtRequest, WatcherRequest,
};

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

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

future_to_promise(async move {
let swap_req: RgbOfferUpdateRequest = serde_wasm_bindgen::from_value(request).unwrap();
match crate::rgb::update_seller_offer(&nostr_hex_sk, swap_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_swap(nostr_hex_sk: String, request: JsValue) -> Promise {
set_panic_hook();
Expand Down
Loading

0 comments on commit 0b5a312

Please sign in to comment.