Skip to content

Commit

Permalink
Use create_spend to calculate amount left to select
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Dec 11, 2023
1 parent b5a3e78 commit 7c778ce
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 114 deletions.
2 changes: 1 addition & 1 deletion gui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion gui/src/app/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::From;
use std::io::ErrorKind;

use liana::{config::ConfigError, descriptors::LianaDescError};
use liana::{config::ConfigError, descriptors::LianaDescError, spend::SpendCreationError};

use crate::{
app::{settings::SettingsError, wallet::WalletError},
Expand All @@ -16,13 +16,15 @@ pub enum Error {
Unexpected(String),
HardwareWallet(async_hwi::Error),
Desc(LianaDescError),
Spend(SpendCreationError),
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Config(e) => write!(f, "{}", e),
Self::Wallet(e) => write!(f, "{}", e),
Self::Spend(e) => write!(f, "{}", e),
Self::Daemon(e) => match e {
DaemonError::Unexpected(e) => write!(f, "{}", e),
DaemonError::NoAnswer => write!(f, "Daemon did not answer"),
Expand Down Expand Up @@ -84,3 +86,9 @@ impl From<async_hwi::Error> for Error {
Error::HardwareWallet(error)
}
}

impl From<SpendCreationError> for Error {
fn from(error: SpendCreationError) -> Self {
Error::Spend(error)
}
}
8 changes: 8 additions & 0 deletions gui/src/app/state/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ mod tests {
spend_info: None,
is_immature: false,
address: dummy_address.clone(),
derivation_index: 0.into(),
is_change: false,
},
Coin {
outpoint: bitcoin::OutPoint { txid, vout: 3 },
Expand All @@ -224,6 +226,8 @@ mod tests {
spend_info: None,
is_immature: false,
address: dummy_address.clone(),
derivation_index: 1.into(),
is_change: false,
},
Coin {
outpoint: bitcoin::OutPoint { txid, vout: 0 },
Expand All @@ -232,6 +236,8 @@ mod tests {
spend_info: None,
is_immature: false,
address: dummy_address.clone(),
derivation_index: 2.into(),
is_change: false,
},
Coin {
outpoint: bitcoin::OutPoint { txid, vout: 1 },
Expand All @@ -240,6 +246,8 @@ mod tests {
spend_info: None,
is_immature: false,
address: dummy_address,
derivation_index: 3.into(),
is_change: false,
},
]);

Expand Down
4 changes: 2 additions & 2 deletions gui/src/app/state/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl CreateSpendPanel {
current: 0,
steps: vec![
Box::new(
step::DefineSpend::new(descriptor, coins, timelock)
step::DefineSpend::new(network, descriptor, coins, timelock)
.with_coins_sorted(blockheight),
),
Box::new(step::SaveSpend::new(wallet)),
Expand All @@ -54,7 +54,7 @@ impl CreateSpendPanel {
current: 0,
steps: vec![
Box::new(
step::DefineSpend::new(descriptor, coins, timelock)
step::DefineSpend::new(network, descriptor, coins, timelock)
.with_preselected_coins(preselected_coins)
.with_coins_sorted(blockheight)
.self_send(),
Expand Down
Loading

0 comments on commit 7c778ce

Please sign in to comment.