move primitive assignments to constants

This commit is contained in:
creating2morrow 2023-06-11 18:28:28 -04:00
parent 626c0d56f1
commit 03f7bdef05
6 changed files with 41 additions and 8 deletions

View file

@ -21,6 +21,20 @@ pub const NEVEKO_VENDOR_ENABLED: &str = "NEVEKO_VENDOR_ENABLED";
pub const NEVEKO_VENDOR_MODE_OFF: &str = "0";
pub const NEVEKO_VENDOR_MODE_ON: &str = "1";
pub enum Prune {
Full,
Pruned,
}
impl Prune {
pub fn value(&self) -> u32 {
match *self {
Prune::Full => 0,
Prune::Pruned => 1,
}
}
}
/// Create a new contact
pub async fn create(c: &Json<Contact>) -> Contact {
let f_cid: String = format!("c{}", utils::generate_rnd());

View file

@ -329,7 +329,7 @@ async fn is_contact_online(contact: &String, jwp: String) -> Result<bool, Box<dy
debug!("check is contact online by version response: {:?}", res);
match res {
Ok(r) => {
if r.result.version != 0 {
if r.result.version != monero::INVALID_VERSION {
Ok(true)
} else {
Ok(false)

View file

@ -21,6 +21,8 @@ use rand_core::RngCore;
use rocket::serde::json::Json;
use std::time::Duration;
const ESTIMATE_FEE_FAILURE: u128 = 0;
/// Struct for the vendor / contact status window
pub struct ContactStatus {
/// UNIX timestamp of expiration as string
@ -654,6 +656,7 @@ fn validate_installation_hash(sw: ExternalSoftware, filename: &String) -> bool {
///
/// especially on stagenet.
pub async fn estimate_fee() -> u128 {
// loop intializer
let mut height: u64 = 0;
let mut count: u64 = 1;
let mut v_fee: Vec<u128> = Vec::new();
@ -663,9 +666,9 @@ pub async fn estimate_fee() -> u128 {
break;
}
let r_height = monero::get_height().await;
if r_height.height == 0 {
if r_height.height == ESTIMATE_FEE_FAILURE as u64 {
error!("error fetching height");
return 0;
return ESTIMATE_FEE_FAILURE;
}
height = r_height.height - count;
let block = monero::get_block(height).await;
@ -702,6 +705,9 @@ pub async fn can_transfer(invoice: u128) -> bool {
let balance = monero::get_balance().await;
monero::close_wallet(&wallet_name, &wallet_password).await;
let fee = estimate_fee().await;
if fee == ESTIMATE_FEE_FAILURE {
false;
}
debug!("fee estimated to: {}", fee);
debug!("balance: {}", balance.result.unlocked_balance);
debug!("fee + invoice = {}", invoice + fee);

View file

@ -446,7 +446,13 @@ impl eframe::App for AddressBookApp {
if ui.button("Add").clicked() {
// Get the contacts information from the /share API
let contact = self.contact.clone();
send_contact_info_req(self.contact_info_tx.clone(), ctx.clone(), contact, 0);
let prune = contact::Prune::Full.value();
send_contact_info_req(
self.contact_info_tx.clone(),
ctx.clone(),
contact,
prune,
);
add_contact_timeout(self.contact_timeout_tx.clone(), ctx.clone());
self.is_adding = true;
}
@ -544,11 +550,12 @@ impl eframe::App for AddressBookApp {
// MESSAGES WON'T BE SENT UNTIL KEY IS SIGNED AND TRUSTED!
self.status.signed_key =
check_signed_key(self.status.i2p.clone());
let prune = contact::Prune::Pruned.value();
send_contact_info_req(
self.contact_info_tx.clone(),
ctx.clone(),
self.status.i2p.clone(),
1,
prune,
);
self.showing_status = true;
self.is_pinging = true;

View file

@ -264,6 +264,7 @@ impl eframe::App for MarketApp {
self.contact_info_tx.clone(),
ctx.clone(),
self.vendor_status.i2p.clone(),
contact::Prune::Pruned.value(),
);
vendor_status_timeout(
self.contact_timeout_tx.clone(),
@ -768,10 +769,15 @@ fn _refresh_on_delete_product_req(_tx: Sender<bool>, _ctx: egui::Context) {
});
}
fn send_contact_info_req(tx: Sender<models::Contact>, ctx: egui::Context, contact: String) {
fn send_contact_info_req(
tx: Sender<models::Contact>,
ctx: egui::Context,
contact: String,
prune: u32,
) {
log::debug!("async send_contact_info_req");
tokio::spawn(async move {
match contact::add_contact_request(contact, 1).await {
match contact::add_contact_request(contact, prune).await {
Ok(contact) => {
let _ = tx.send(contact);
ctx.request_repaint();

View file

@ -46,7 +46,7 @@ pub async fn get_i2p_status() -> Custom<Json<i2p::HttpProxyStatus>> {
#[get("/<pruned>")]
pub async fn share_contact_info(pruned: u32) -> Custom<Json<models::Contact>> {
let info: models::Contact = contact::share().await;
if pruned == 1 {
if pruned == contact::Prune::Pruned.value() {
let p_info: models::Contact = models::Contact {
gpg_key: Vec::new(),
..info