wip: refactor
This commit is contained in:
@@ -15,12 +15,31 @@ pub fn get_all_accounts_from_keyring() -> Vec<PublicKey> {
|
||||
accounts
|
||||
}
|
||||
|
||||
pub fn show_npub(public_key: PublicKey, len: usize) -> anyhow::Result<String, anyhow::Error> {
|
||||
let bech32 = public_key.to_bech32()?;
|
||||
let separator = " ... ";
|
||||
|
||||
let sep_len = separator.len();
|
||||
let chars_to_show = len - sep_len;
|
||||
let front_chars = (chars_to_show + 1) / 2; // ceil
|
||||
let back_chars = chars_to_show / 2; // floor
|
||||
|
||||
Ok(format!(
|
||||
"{}{}{}",
|
||||
&bech32[..front_chars],
|
||||
separator,
|
||||
&bech32[bech32.len() - back_chars..]
|
||||
))
|
||||
}
|
||||
|
||||
pub fn ago(time: u64) -> String {
|
||||
let now = Local::now();
|
||||
let input_time = Local.timestamp_opt(time as i64, 0).unwrap();
|
||||
let diff = (now - input_time).num_hours();
|
||||
|
||||
if diff < 24 {
|
||||
if diff == 0 {
|
||||
"now".to_owned()
|
||||
} else if diff < 24 {
|
||||
let duration = now.signed_duration_since(input_time);
|
||||
format!("{} ago", duration.num_hours())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user