fix recovery state coins filtering

Recoverable coins are coins that recovery
path is available *next* block
This commit is contained in:
edouard 2022-12-15 12:50:39 +01:00
parent 88c807d599
commit 192072ea25
2 changed files with 17 additions and 5 deletions

View File

@ -44,7 +44,8 @@ impl RecoveryPanel {
let mut recoverable_coins = (0, Amount::from_sat(0));
for coin in coins {
if coin.spend_info.is_none() {
if remaining_sequence(coin, blockheight, timelock) != 0 {
// recoverable coins are coins that can be recoverable next block.
if remaining_sequence(coin, blockheight, timelock) > 1 {
locked_coins.0 += 1;
locked_coins.1 += coin.amount;
} else {
@ -103,8 +104,9 @@ impl State for RecoveryPanel {
self.recoverable_coins = (0, Amount::from_sat(0));
for coin in coins {
if coin.spend_info.is_none() {
// recoverable coins are coins that can be recoverable next block.
if remaining_sequence(&coin, cache.blockheight as u32, self.timelock)
!= 0
> 1
{
self.locked_coins.0 += 1;
self.locked_coins.1 += coin.amount;

View File

@ -82,7 +82,12 @@ pub fn recovery<'a>(
.on_press(Message::Clipboard(psbt.unsigned_tx.txid().to_string()))
.style(button::Style::Border.into()))
)
.push(Row::new().push(text(format!("Fees: {}", recoverable_coins.1 - Amount::from_sat(psbt.unsigned_tx.output[0].value))).small()))
.push_maybe(if recoverable_coins.1.to_sat() > psbt.unsigned_tx.output[0].value {
Some(Row::new()
.push(text(format!("Fees: {}", recoverable_coins.1 - Amount::from_sat(psbt.unsigned_tx.output[0].value))).small()))
} else {
None
})
))
} else {
Column::new()
@ -115,7 +120,12 @@ pub fn recovery<'a>(
.on_press(Message::Clipboard(psbt.unsigned_tx.txid().to_string()))
.style(button::Style::Border.into()))
)
.push(Row::new().push(text(format!("Fees: {}", recoverable_coins.1 - Amount::from_sat(psbt.unsigned_tx.output[0].value))).small()))
.push_maybe(if recoverable_coins.1.to_sat() > psbt.unsigned_tx.output[0].value {
Some(Row::new()
.push(text(format!("Fees: {}", recoverable_coins.1 - Amount::from_sat(psbt.unsigned_tx.output[0].value))).small()))
} else {
None
})
)
)
.push(if !hws.is_empty() {
@ -186,7 +196,7 @@ pub fn recovery<'a>(
)
.width(Length::Units(250)),
)
.push(if feerate.valid && !feerate.value.is_empty() && address.valid && !address.value.is_empty() {
.push(if feerate.valid && !feerate.value.is_empty() && address.valid && !address.value.is_empty() && recoverable_coins.0 != 0 {
button::primary(None, "Next").on_press(Message::Next).width(Length::Units(200))
} else {
button::primary(None, "Next")