mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-12-22 11:39:22 +00:00
upload delivery info from gui - untested
This commit is contained in:
parent
6340119435
commit
b94802711c
4 changed files with 141 additions and 22 deletions
|
@ -9,7 +9,8 @@ use crate::{
|
|||
monero,
|
||||
order,
|
||||
product,
|
||||
utils, reqres,
|
||||
reqres,
|
||||
utils,
|
||||
};
|
||||
use log::{
|
||||
debug,
|
||||
|
@ -189,6 +190,33 @@ pub async fn find_all_customer_orders(cid: String) -> Vec<Order> {
|
|||
orders
|
||||
}
|
||||
|
||||
/// Lookup all orders for vendor
|
||||
pub fn find_all_vendor_orders() -> Vec<Order> {
|
||||
info!("lookup orders for vendor");
|
||||
let i_s = db::Interface::open();
|
||||
let i_list_key = crate::ORDER_LIST_DB_KEY;
|
||||
let i_r = db::Interface::read(&i_s.env, &i_s.handle, &String::from(i_list_key));
|
||||
if i_r == utils::empty_string() {
|
||||
error!("order index not found");
|
||||
}
|
||||
let i_v_oid = i_r.split(",");
|
||||
let i_v: Vec<String> = i_v_oid.map(|s| String::from(s)).collect();
|
||||
let mut orders: Vec<Order> = Vec::new();
|
||||
let vendor_b32: String = i2p::get_destination(None);
|
||||
for o in i_v {
|
||||
let order: Order = find(&o);
|
||||
if order.orid != utils::empty_string() && order.cid != vendor_b32 {
|
||||
// TODO(c2m): separate functionality for archived orders
|
||||
if order.status != order::StatusType::Cancelled.value()
|
||||
&& order.status != order::StatusType::Delivered.value()
|
||||
{
|
||||
orders.push(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
orders
|
||||
}
|
||||
|
||||
/// Modify order from admin server
|
||||
pub fn modify(o: Json<Order>) -> Order {
|
||||
info!("modify order: {}", &o.orid);
|
||||
|
@ -436,7 +464,9 @@ pub async fn finalize_order(orid: &String) -> reqres::FinalizeOrderResponse {
|
|||
address,
|
||||
..Default::default()
|
||||
};
|
||||
let valid = m_describe.result.desc[0].recepients.contains(&check_destination)
|
||||
let valid = m_describe.result.desc[0]
|
||||
.recepients
|
||||
.contains(&check_destination)
|
||||
&& m_describe.result.desc[0].unlock_time < monero::LockTimeLimit::Blocks.value();
|
||||
if !valid {
|
||||
monero::close_wallet(orid, &wallet_password).await;
|
||||
|
@ -450,6 +480,7 @@ pub async fn finalize_order(orid: &String) -> reqres::FinalizeOrderResponse {
|
|||
error!("order wallet not swept");
|
||||
return Default::default();
|
||||
}
|
||||
monero::close_wallet(orid, &wallet_password).await;
|
||||
m_order.status = order::StatusType::Delivered.value();
|
||||
order::modify(Json(m_order));
|
||||
reqres::FinalizeOrderResponse {
|
||||
|
@ -475,9 +506,7 @@ pub async fn transmit_finalize_request(
|
|||
let proxy = reqwest::Proxy::http(&host)?;
|
||||
let client = reqwest::Client::builder().proxy(proxy).build();
|
||||
match client?
|
||||
.post(format!(
|
||||
"http://{}/market/order/finalize/{}", contact, orid
|
||||
))
|
||||
.post(format!("http://{}/market/order/finalize/{}", contact, orid))
|
||||
.header("proof", jwp)
|
||||
.send()
|
||||
.await
|
||||
|
@ -500,7 +529,11 @@ pub async fn transmit_finalize_request(
|
|||
/// A post-decomposition trigger for the finalize request so that the logic
|
||||
///
|
||||
/// can be executed from the gui.
|
||||
pub async fn trigger_finalize_request(contact: &String, jwp: &String, orid: &String) -> reqres::FinalizeOrderResponse {
|
||||
pub async fn trigger_finalize_request(
|
||||
contact: &String,
|
||||
jwp: &String,
|
||||
orid: &String,
|
||||
) -> reqres::FinalizeOrderResponse {
|
||||
info!("executing trigger_finalize_request");
|
||||
let finalize = transmit_finalize_request(contact, jwp, orid).await;
|
||||
// cache finalize order request to db
|
||||
|
@ -516,7 +549,10 @@ pub async fn trigger_finalize_request(contact: &String, jwp: &String, orid: &Str
|
|||
}
|
||||
|
||||
/// Decomposition trigger for `finalize_order()`
|
||||
pub async fn d_trigger_finalize_request(contact: &String, orid: &String) -> reqres::FinalizeOrderResponse {
|
||||
pub async fn d_trigger_finalize_request(
|
||||
contact: &String,
|
||||
orid: &String,
|
||||
) -> reqres::FinalizeOrderResponse {
|
||||
// ugh, sorry seems we need to get jwp for vendor from fts cache
|
||||
// get jwp from db
|
||||
let s = db::Interface::async_open().await;
|
||||
|
|
|
@ -320,7 +320,7 @@ impl eframe::App for HomeApp {
|
|||
self.connections.is_i2p_advanced = !self.connections.is_i2p_advanced;
|
||||
log::debug!("is i2p advanced mode: {}", self.connections.is_i2p_advanced);
|
||||
}
|
||||
// TODO: mainnet
|
||||
// TODO(c2m): uncomment this to add mainnet flag to gui
|
||||
// let mut is_mainnet = self.connections.mainnet;
|
||||
// if ui.checkbox(&mut is_mainnet, "mainnet").changed() {
|
||||
// self.connections.mainnet = !self.connections.mainnet;
|
||||
|
|
|
@ -81,6 +81,7 @@ pub struct MarketApp {
|
|||
is_showing_vendor_status: bool,
|
||||
is_showing_vendors: bool,
|
||||
is_timeout: bool,
|
||||
is_uploading_dinfo: bool,
|
||||
is_vendor_enabled: bool,
|
||||
is_window_shopping: bool,
|
||||
msig: MultisigManagement,
|
||||
|
@ -117,12 +118,15 @@ pub struct MarketApp {
|
|||
cancel_request_rx: Receiver<models::Order>,
|
||||
// ship_request_tx: Sender<models::Order>,
|
||||
// ship_request_rx: Receiver<models::Order>,
|
||||
upload_dinfo_tx: Sender<bool>,
|
||||
upload_dinfo_rx: Receiver<bool>,
|
||||
s_contact: models::Contact,
|
||||
s_order: models::Order,
|
||||
vendor_status: utils::ContactStatus,
|
||||
vendors: Vec<models::Contact>,
|
||||
order_xmr_address_tx: Sender<reqres::XmrRpcAddressResponse>,
|
||||
order_xmr_address_rx: Receiver<reqres::XmrRpcAddressResponse>,
|
||||
upload_dinfo_str: String,
|
||||
}
|
||||
|
||||
impl Default for MarketApp {
|
||||
|
@ -145,6 +149,7 @@ impl Default for MarketApp {
|
|||
let (order_xmr_address_tx, order_xmr_address_rx) = std::sync::mpsc::channel();
|
||||
let (order_funded_tx, order_funded_rx) = std::sync::mpsc::channel();
|
||||
let (submit_txset_tx, submit_txset_rx) = std::sync::mpsc::channel();
|
||||
let (upload_dinfo_tx, upload_dinfo_rx) = std::sync::mpsc::channel();
|
||||
let contents = std::fs::read("./assets/qr.png").unwrap_or(Vec::new());
|
||||
MarketApp {
|
||||
contact_info_rx,
|
||||
|
@ -176,6 +181,7 @@ impl Default for MarketApp {
|
|||
is_showing_vendor_status: false,
|
||||
is_showing_vendors: false,
|
||||
is_timeout: false,
|
||||
is_uploading_dinfo: false,
|
||||
is_vendor_enabled,
|
||||
is_window_shopping: false,
|
||||
msig: Default::default(),
|
||||
|
@ -221,6 +227,9 @@ impl Default for MarketApp {
|
|||
submit_txset_tx,
|
||||
vendor_status: Default::default(),
|
||||
vendors: Vec::new(),
|
||||
upload_dinfo_str: utils::empty_string(),
|
||||
upload_dinfo_rx,
|
||||
upload_dinfo_tx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -339,6 +348,13 @@ impl eframe::App for MarketApp {
|
|||
self.is_loading = false;
|
||||
}
|
||||
|
||||
if let Ok(upload_dinfo) = self.upload_dinfo_rx.try_recv() {
|
||||
if !upload_dinfo {
|
||||
log::error!("failure to upload delivery info")
|
||||
}
|
||||
self.is_loading = false;
|
||||
}
|
||||
|
||||
// Vendor status window
|
||||
//-----------------------------------------------------------------------------------
|
||||
let mut is_showing_vendor_status = self.is_showing_vendor_status;
|
||||
|
@ -776,6 +792,7 @@ impl eframe::App for MarketApp {
|
|||
self.is_showing_decrypted_delivery_info = false;
|
||||
}
|
||||
});
|
||||
|
||||
// View orders - Customer Order Flow Management
|
||||
//-----------------------------------------------------------------------------------
|
||||
let mut is_customer_viewing_orders = self.is_customer_viewing_orders;
|
||||
|
@ -937,7 +954,6 @@ impl eframe::App for MarketApp {
|
|||
gpg::encrypt(self.vendor_status.i2p.clone(), &address_bytes);
|
||||
let new_order = reqres::OrderRequest {
|
||||
cid: String::from(&self.new_order.cid),
|
||||
// TODO: inject mediator for vendor dispute handling
|
||||
mediator: String::from(&mediator),
|
||||
pid: String::from(&self.new_order.pid),
|
||||
ship_address: encrypted_shipping_address.unwrap_or(Vec::new()),
|
||||
|
@ -967,6 +983,47 @@ impl eframe::App for MarketApp {
|
|||
}
|
||||
});
|
||||
|
||||
// Vendor Upload Delivery Info Form
|
||||
//-----------------------------------------------------------------------------------
|
||||
let mut is_uploading_dinfo = self.is_uploading_dinfo;
|
||||
egui::Window::new("upload dinfo form")
|
||||
.open(&mut is_uploading_dinfo)
|
||||
.title_bar(false)
|
||||
.vscroll(true)
|
||||
.show(&ctx, |ui| {
|
||||
ui.heading("Upload DINFO Form");
|
||||
if self.is_loading {
|
||||
ui.add(egui::Spinner::new());
|
||||
ui.label("triggering NASR, just a moment...");
|
||||
}
|
||||
ui.label(format!("order id: {}", self.new_order.orid));
|
||||
ui.horizontal(|ui| {
|
||||
let delivery_info = ui.label("delivery info: ");
|
||||
ui.text_edit_singleline(&mut self.upload_dinfo_str)
|
||||
.labelled_by(delivery_info.id);
|
||||
});
|
||||
if self.new_order.orid != utils::empty_string()
|
||||
&& self.upload_dinfo_str != utils::empty_string() {
|
||||
if ui.button("Trigger NASR").clicked() {
|
||||
// upload delivery info
|
||||
let dinfo_str = String::from(&self.upload_dinfo_str);
|
||||
upload_dinfo_req(
|
||||
dinfo_str.into_bytes().iter().cloned().collect(),
|
||||
self.new_order.orid.clone(),
|
||||
ctx.clone(),
|
||||
self.upload_dinfo_tx.clone(),
|
||||
);
|
||||
self.new_order = Default::default();
|
||||
}
|
||||
}
|
||||
ui.label("\n");
|
||||
if ui.button("Exit").clicked() {
|
||||
self.is_uploading_dinfo = false;
|
||||
self.upload_dinfo_str = Default::default();
|
||||
self.is_loading = false;
|
||||
}
|
||||
});
|
||||
|
||||
// View vendors
|
||||
//-----------------------------------------------------------------------------------
|
||||
let mut is_showing_vendors = self.is_showing_vendors;
|
||||
|
@ -1430,18 +1487,22 @@ impl eframe::App for MarketApp {
|
|||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::remainder())
|
||||
.column(Column::remainder())
|
||||
.min_scrolled_height(0.0);
|
||||
|
||||
table
|
||||
.header(20.0, |mut header| {
|
||||
header.col(|ui| {
|
||||
ui.strong("");
|
||||
ui.strong("CID");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("");
|
||||
ui.strong("Status");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("");
|
||||
ui.strong("Date");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Payout Address");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("");
|
||||
|
@ -1468,13 +1529,27 @@ impl eframe::App for MarketApp {
|
|||
});
|
||||
row.col(|ui| {
|
||||
ui.style_mut().wrap = Some(false);
|
||||
ui.horizontal(|ui| {
|
||||
if o.status != order::StatusType::Shipped.value() {
|
||||
if ui.button("Upload DINFO").clicked() {
|
||||
self.new_order.orid = String::from(&o.orid);
|
||||
self.is_uploading_dinfo = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.horizontal(|_ui| {
|
||||
// update button
|
||||
// TODO: update functionality on orders not yet shipped
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Exit").clicked() {
|
||||
self.is_showing_orders = false;
|
||||
self.is_loading = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// End Vendor specific
|
||||
|
@ -1584,7 +1659,8 @@ impl eframe::App for MarketApp {
|
|||
}
|
||||
ui.label("\n");
|
||||
if ui.button("Manage Orders").clicked() {
|
||||
// TODO(c2m): vendor order management logic
|
||||
self.is_showing_orders = true;
|
||||
self.orders = order::find_all_vendor_orders();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -2300,12 +2376,7 @@ fn validate_msig_step(
|
|||
m_info != utils::empty_string() && v_info != utils::empty_string()
|
||||
}
|
||||
|
||||
fn release_txset(
|
||||
contact: String,
|
||||
orid: String,
|
||||
ctx: egui::Context,
|
||||
tx: Sender<bool>,
|
||||
) {
|
||||
fn release_txset(contact: String, orid: String, ctx: egui::Context, tx: Sender<bool>) {
|
||||
tokio::spawn(async move {
|
||||
log::info!("async release txset");
|
||||
let lookup = order::find(&orid);
|
||||
|
@ -2322,3 +2393,12 @@ fn release_txset(
|
|||
todo!()
|
||||
});
|
||||
}
|
||||
|
||||
fn upload_dinfo_req(dinfo: Vec<u8>, orid: String, ctx: egui::Context, tx: Sender<bool>) {
|
||||
tokio::spawn(async move {
|
||||
log::info!("async upload_dinfo_req");
|
||||
let dinfo = order::upload_delivery_info(&orid, &dinfo).await;
|
||||
let _ = tx.send(dinfo.orid != utils::empty_string());
|
||||
ctx.request_repaint();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -246,7 +246,10 @@ pub async fn cancel_order(
|
|||
///
|
||||
/// Protected: true
|
||||
#[post("/order/finalize/<orid>")]
|
||||
pub async fn finalize_order(orid: String, _jwp: proof::PaymentProof) -> Custom<Json<reqres::FinalizeOrderResponse>> {
|
||||
pub async fn finalize_order(
|
||||
orid: String,
|
||||
_jwp: proof::PaymentProof,
|
||||
) -> Custom<Json<reqres::FinalizeOrderResponse>> {
|
||||
let finalize = order::finalize_order(&orid).await;
|
||||
if !finalize.vendor_update_success {
|
||||
return Custom(Status::BadRequest, Json(Default::default()));
|
||||
|
|
Loading…
Reference in a new issue