Merge #1031: gui: fix condition to create draft spend

68f8dbc43ba00de04b1ee33e0e8f2bd77242b127 gui: fix condition to create draft spend (jp1ac4)

Pull request description:

  This issue was encountered by @pythcoiner in https://github.com/wizardsardine/liana_manual_testing/blob/master/tests/v5/v5-pre-rc1/pyth.md#comments.

  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.

ACKs for top commit:
  edouardparis:
    ACK 68f8dbc43ba00de04b1ee33e0e8f2bd77242b127

Tree-SHA512: b50519beb094e2344273a44bcc21c077a568c31d9cd0d96a29117b42aef146919b18abf8cfea15c5b15962cdf553a547435d464feea4e87fdb33cfcab7394392
This commit is contained in:
edouardparis 2024-03-25 11:47:49 +01:00
commit 05e4e38e68
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
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))