Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend_task/dashpay/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pub async fn load_contacts(
.map(|s| s.to_string());

let bio = props
.get("bio")
.get("publicMessage")
.and_then(|v| v.as_text())
.map(|s| s.to_string());

Expand Down
39 changes: 37 additions & 2 deletions src/ui/dashpay/contact_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,39 @@ use crate::ui::theme::DashColors;
use crate::ui::{MessageType, Screen, ScreenLike, ScreenType};
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::platform::Identifier;
use chrono::{LocalResult, TimeZone, Utc};
use chrono_humanize::HumanTime;
use egui::{Frame, Margin, RichText, ScrollArea, Ui};
use std::collections::{BTreeMap, HashSet};
use std::sync::{Arc, RwLock};

/// Format a timestamp (seconds or milliseconds since epoch) as a human-readable
/// relative time string (e.g. "3 hours ago"). Returns `None` if the timestamp
/// is zero or cannot be parsed.
fn format_relative_time(timestamp: u64) -> Option<String> {
if timestamp == 0 {
return None;
}
// Distinguish seconds vs milliseconds: timestamps after year ~2001 in millis
// exceed 1_000_000_000_000, while second-based timestamps won't until year 33658.
let dt_result = if timestamp > 1_000_000_000_000 {
Utc.timestamp_millis_opt(timestamp as i64)
} else {
Utc.timestamp_opt(timestamp as i64, 0)
};
match dt_result {
LocalResult::Single(dt) => {
let human = HumanTime::from(dt).to_string();
if human.contains("seconds") {
Some("just now".to_string())
} else {
Some(human)
}
}
_ => None,
}
}

#[derive(Debug, Clone)]
pub struct ContactRequest {
pub request_id: Identifier,
Expand Down Expand Up @@ -593,8 +622,11 @@ impl ContactRequests {
}

// Timestamp
let time_text = format_relative_time(request.timestamp)
.map(|t| format!("Received: {}", t))
.unwrap_or_else(|| "Received: unknown".to_string());
ui.label(
RichText::new("Received: 1 day ago").small().color(DashColors::text_secondary(dark_mode)),
RichText::new(time_text).small().color(DashColors::text_secondary(dark_mode)),
);
});

Expand Down Expand Up @@ -772,7 +804,10 @@ impl ContactRequests {

// Status
ui.label(RichText::new("Status: Pending").small().color(DashColors::text_secondary(dark_mode)));
ui.label(RichText::new("Sent: 2 days ago").small().color(DashColors::text_secondary(dark_mode)));
let sent_time_text = format_relative_time(request.timestamp)
.map(|t| format!("Sent: {}", t))
.unwrap_or_else(|| "Sent: unknown".to_string());
ui.label(RichText::new(sent_time_text).small().color(DashColors::text_secondary(dark_mode)));
});

ui.with_layout(
Expand Down
42 changes: 37 additions & 5 deletions src/ui/dashpay/send_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,36 @@ use dash_sdk::dpp::balances::credits::Credits;
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::dpp::platform_value::string_encoding::Encoding;
use dash_sdk::platform::Identifier;
use chrono::{LocalResult, TimeZone, Utc};
use chrono_humanize::HumanTime;
use egui::{Frame, Margin, RichText, ScrollArea, TextEdit, Ui};
use std::sync::{Arc, RwLock};

/// Format a timestamp (seconds or milliseconds since epoch) as a human-readable
/// relative time string (e.g. "3 hours ago"). Returns `None` if the timestamp
/// is zero or cannot be parsed.
fn format_relative_time(timestamp: u64) -> Option<String> {
if timestamp == 0 {
return None;
}
let dt_result = if timestamp > 1_000_000_000_000 {
Utc.timestamp_millis_opt(timestamp as i64)
} else {
Utc.timestamp_opt(timestamp as i64, 0)
};
match dt_result {
LocalResult::Single(dt) => {
let human = HumanTime::from(dt).to_string();
if human.contains("seconds") {
Some("just now".to_string())
} else {
Some(human)
}
}
_ => None,
}
}

const PAYMENT_GUIDELINES_INFO_TEXT: &str = "Payment Guidelines:\n\n\
Payments to contacts use encrypted payment channels.\n\n\
Only you and the recipient can see payment details.\n\n\
Expand Down Expand Up @@ -767,11 +794,16 @@ impl PaymentHistory {
);

// Timestamp
ui.label(
RichText::new("• 2 days ago")
.small()
.color(DashColors::text_secondary(dark_mode)),
);
let payment_time_text = format_relative_time(payment.timestamp)
.map(|t| format!("• {}", t))
.unwrap_or_default();
if !payment_time_text.is_empty() {
ui.label(
RichText::new(payment_time_text)
.small()
.color(DashColors::text_secondary(dark_mode)),
);
}
});
});
});
Expand Down
Loading