Make home warning message relative to timelock

close #461
This commit is contained in:
edouard 2023-05-07 16:54:50 +02:00
parent f2843cc064
commit 25fffb2c52
2 changed files with 30 additions and 12 deletions

View File

@ -133,8 +133,9 @@ impl State for Home {
let timelock = self.wallet.main_descriptor.first_timelock_value();
let seq =
remaining_sequence(&coin, cache.blockheight as u32, timelock);
// number of block in a day
if seq <= 144 {
// Warn user for coins that are expiring in less than 10 percent of
// the timelock.
if seq <= timelock as u32 * 10 / 100 {
self.expiring_coins.push(coin.outpoint);
}
if let Some(last) = &mut self.remaining_sequence {

View File

@ -230,14 +230,31 @@ pub fn expire_message_units(sequence: u32) -> Vec<String> {
n_minutes -= n_months * 43830;
let n_days = n_minutes / 1440;
[(n_years, "year"), (n_months, "month"), (n_days, "day")]
.iter()
.filter_map(|(n, u)| {
if *n != 0 {
Some(format!("{} {}{}", n, u, if *n > 1 { "s" } else { "" }))
} else {
None
}
})
.collect()
#[allow(clippy::nonminimal_bool)]
if n_days != 0 || n_months != 0 || n_days != 0 {
[(n_years, "year"), (n_months, "month"), (n_days, "day")]
.iter()
.filter_map(|(n, u)| {
if *n != 0 {
Some(format!("{} {}{}", n, u, if *n > 1 { "s" } else { "" }))
} else {
None
}
})
.collect()
} else {
n_minutes -= n_days * 1440;
let n_hours = n_minutes / 60;
n_minutes -= n_hours * 60;
[(n_hours, "hour"), (n_minutes, "minute")]
.iter()
.filter_map(|(n, u)| {
if *n != 0 {
Some(format!("{} {}{}", n, u, if *n > 1 { "s" } else { "" }))
} else {
None
}
})
.collect()
}
}