From 6bc9887020ecdc5388e43269a8e6d524376f577c Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Thu, 27 Jun 2024 07:47:24 +0200 Subject: [PATCH] gui: do not let user try recovery if one block left and timelock == 1 --- gui/src/app/state/mod.rs | 8 ++++++-- gui/src/app/state/recovery.rs | 2 +- gui/src/app/state/spend/step.rs | 4 ++-- gui/src/app/view/coins.rs | 3 ++- gui/src/app/view/recovery.rs | 14 +++++++++----- gui/src/app/view/spend/mod.rs | 2 +- gui/src/daemon/model.rs | 6 +++++- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/gui/src/app/state/mod.rs b/gui/src/app/state/mod.rs index 4b1b38e6a..95961f91f 100644 --- a/gui/src/app/state/mod.rs +++ b/gui/src/app/state/mod.rs @@ -158,8 +158,12 @@ impl State for Home { if coin.block_height.is_some() { self.balance += coin.amount; let timelock = self.wallet.main_descriptor.first_timelock_value(); - let seq = - remaining_sequence(&coin, cache.blockheight as u32, timelock); + let seq = remaining_sequence( + &coin, + cache.blockheight as u32, + timelock, + false, + ); // Warn user for coins that are expiring in less than 10 percent of // the timelock. if seq <= timelock as u32 * 10 / 100 { diff --git a/gui/src/app/state/recovery.rs b/gui/src/app/state/recovery.rs index 09298aaff..6a103c153 100644 --- a/gui/src/app/state/recovery.rs +++ b/gui/src/app/state/recovery.rs @@ -247,7 +247,7 @@ fn recovery_paths(wallet: &Wallet, coins: &[Coin], blockheight: i32) -> Vec( } else if coin.block_height.is_none() { badge::unconfirmed() } else { - let seq = remaining_sequence(coin, blockheight, timelock); + let seq = + remaining_sequence(coin, blockheight, timelock, false); coin_sequence_label(seq, timelock as u32) }) .spacing(10) diff --git a/gui/src/app/view/recovery.rs b/gui/src/app/view/recovery.rs index 6a5f39f21..7920775b9 100644 --- a/gui/src/app/view/recovery.rs +++ b/gui/src/app/view/recovery.rs @@ -96,10 +96,14 @@ pub fn recovery<'a>( Container::new( Column::new() .spacing(20) - .push(text(format!( - "{} recovery paths will be available at the next block, select one:", - recovery_paths.len() - ))) + .push(text(if recovery_paths.len() == 1 { + "1 recovery path is available, please select:".to_string() + } else { + format!( + "{} recovery paths are available, select one:", + recovery_paths.len() + ) + })) .push(Column::with_children(recovery_paths).spacing(20)), ) .style(theme::Container::Card(theme::Card::Simple)) @@ -190,7 +194,7 @@ pub fn recovery_path_view<'a>( .push(text(format!( "{} coin{} totalling", number_of_coins, - if number_of_coins > 0 { "s" } else { "" } + if number_of_coins > 1 { "s" } else { "" } ))) .push(amount(&total_amount)), ) diff --git a/gui/src/app/view/spend/mod.rs b/gui/src/app/view/spend/mod.rs index e760ed68f..d501159b3 100644 --- a/gui/src/app/view/spend/mod.rs +++ b/gui/src/app/view/spend/mod.rs @@ -459,7 +459,7 @@ fn coin_list_view<'a>( } else if coin.block_height.is_none() { badge::unconfirmed() } else { - let seq = remaining_sequence(coin, blockheight, timelock); + let seq = remaining_sequence(coin, blockheight, timelock, false); coins::coin_sequence_label(seq, timelock as u32) }) .spacing(10) diff --git a/gui/src/daemon/model.rs b/gui/src/daemon/model.rs index bc1d315bf..b830cfbab 100644 --- a/gui/src/daemon/model.rs +++ b/gui/src/daemon/model.rs @@ -17,7 +17,11 @@ pub use liana::{ pub type Coin = ListCoinsEntry; -pub fn remaining_sequence(coin: &Coin, blockheight: u32, timelock: u16) -> u32 { +pub fn remaining_sequence(coin: &Coin, blockheight: u32, mut timelock: u16, recovery: bool) -> u32 { + // `createrecovery` command does not consider unconfirmed coins + if timelock == 1 && recovery { + timelock += 1; + } if let Some(coin_blockheight) = coin.block_height { if blockheight > coin_blockheight as u32 + timelock as u32 { 0