fix initial order request and start multisig ops

This commit is contained in:
creating2morrow 2023-06-24 05:07:38 -04:00
parent 2746e7345d
commit c247fced39
2 changed files with 24 additions and 7 deletions

View file

@ -298,12 +298,13 @@ pub async fn finalize_order(orid: &String) -> reqres::FinalizeOrderResponse {
} }
/// Send order request to vendor and start multisig flow /// Send order request to vendor and start multisig flow
pub async fn transmit_order_request(contact: String, request: reqres::OrderRequest) -> Result<Order, Box<dyn Error>> { pub async fn transmit_order_request(contact: String, jwp: String, request: reqres::OrderRequest) -> Result<Order, Box<dyn Error>> {
let host = utils::get_i2p_http_proxy(); let host = utils::get_i2p_http_proxy();
let proxy = reqwest::Proxy::http(&host)?; let proxy = reqwest::Proxy::http(&host)?;
let client = reqwest::Client::builder().proxy(proxy).build(); let client = reqwest::Client::builder().proxy(proxy).build();
match client? match client?
.post(format!("http://{}/market/order/create", contact)) .post(format!("http://{}/market/order/create", contact))
.header("proof", jwp)
.json(&request) .json(&request)
.send() .send()
.await .await
@ -312,7 +313,7 @@ pub async fn transmit_order_request(contact: String, request: reqres::OrderReque
let res = response.json::<Order>().await; let res = response.json::<Order>().await;
debug!("create order response: {:?}", res); debug!("create order response: {:?}", res);
match res { match res {
Ok(r) => Ok(r), Ok(_r) => Ok(Default::default()),
_ => Ok(Default::default()), _ => Ok(Default::default()),
} }
} }

View file

@ -228,12 +228,21 @@ impl eframe::App for MarketApp {
quantity: qty, quantity: qty,
..Default::default() ..Default::default()
}; };
log::debug!("new order: {:?}", &new_order);
self.is_loading = true; self.is_loading = true;
submit_order_req(self.submit_order_tx.clone(), ctx.clone(), new_order); submit_order_req(
self.submit_order_tx.clone(),
self.vendor_status.i2p.clone(),
ctx.clone(),
self.vendor_status.jwp.clone(),
new_order
);
self.new_order = Default::default(); self.new_order = Default::default();
self.new_order_price = 0; self.new_order_price = 0;
self.new_order_quantity = utils::empty_string(); self.new_order_quantity = utils::empty_string();
self.new_order_shipping_address = utils::empty_string(); self.new_order_shipping_address = utils::empty_string();
self.is_ordering = false;
self.is_showing_products = false;
} }
} }
ui.label("\n"); ui.label("\n");
@ -928,12 +937,19 @@ fn vendor_status_timeout(tx: Sender<bool>, ctx: egui::Context) {
}); });
} }
fn submit_order_req(tx: Sender<models::Order>, ctx: egui::Context, request: reqres::OrderRequest) { fn submit_order_req(tx: Sender<models::Order>, contact: String, ctx: egui::Context, jwp: String, request: reqres::OrderRequest) {
tokio::spawn(async move { tokio::spawn(async move {
log::info!("submit order"); log::info!("submit order");
let contact = String::from(&request.cid); let r_contact = String::from(&contact);
let order = order::transmit_order_request(contact, request).await; let order = order::transmit_order_request(r_contact, jwp, request).await;
let _ = tx.send(order.unwrap_or(Default::default())); let u_order = order.unwrap_or(Default::default());
// cache order request to db
utils::write_gui_db(
String::from("gui-orid"),
String::from(&contact),
String::from(&u_order.orid),
);
let _ = tx.send(u_order);
ctx.request_repaint(); ctx.request_repaint();
}); });
} }