gui: fix condition to create draft spend

The `balance_available` value was not being refreshed when new
coins were received and so it was sometimes not possible to
click Next.

It's enough, however, to check the amount left to select is 0,
and so both the `balance_available` and `total_amount` fields
can be removed.
This commit is contained in:
jp1ac4 2024-03-25 08:46:44 +00:00
parent b10198d54c
commit 68f8dbc43b
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B
2 changed files with 1 additions and 24 deletions

View File

@ -68,7 +68,6 @@ pub trait Step {
}
pub struct DefineSpend {
balance_available: Amount,
recipients: Vec<Recipient>,
/// If set, this is the index of a recipient that should
/// receive the max amount.
@ -99,16 +98,6 @@ impl DefineSpend {
coins: &[Coin],
timelock: u16,
) -> Self {
let balance_available = coins
.iter()
.filter_map(|coin| {
if coin.spend_info.is_none() {
Some(coin.amount)
} else {
None
}
})
.sum();
let coins: Vec<(Coin, bool)> = coins
.iter()
.filter_map(|c| {
@ -121,7 +110,6 @@ impl DefineSpend {
.collect();
Self {
balance_available,
network,
descriptor,
curve: secp256k1::Secp256k1::verification_only(),
@ -630,7 +618,6 @@ impl Step for DefineSpend {
fn view<'a>(&'a self, cache: &'a Cache) -> Element<'a, view::Message> {
view::spend::create_spend_tx(
cache,
&self.balance_available,
self.recipients
.iter()
.enumerate()
@ -640,12 +627,6 @@ impl Step for DefineSpend {
.map(view::Message::CreateSpend)
})
.collect(),
Amount::from_sat(
self.recipients
.iter()
.map(|r| r.amount().unwrap_or(0_u64))
.sum(),
),
self.is_valid,
self.is_duplicate,
self.timelock,

View File

@ -112,9 +112,7 @@ pub fn spend_view<'a>(
#[allow(clippy::too_many_arguments)]
pub fn create_spend_tx<'a>(
cache: &'a Cache,
balance_available: &'a Amount,
recipients: Vec<Element<'a, Message>>,
total_amount: Amount,
is_valid: bool,
duplicate: bool,
timelock: u16,
@ -300,9 +298,7 @@ pub fn create_spend_tx<'a>(
.push(
if is_valid
&& !duplicate
&& (is_self_send
|| (total_amount < *balance_available
&& Some(&Amount::from_sat(0)) == amount_left))
&& (is_self_send || Some(&Amount::from_sat(0)) == amount_left)
{
button::primary(None, "Next")
.on_press(Message::CreateSpend(CreateSpendMessage::Generate))