Skip to content

Commit

Permalink
Merge #940: gui(spend): display warnings for draft PSBTs
Browse files Browse the repository at this point in the history
85f5a68 gui(spend): display warnings for draft PSBTs (jp1ac4)

Pull request description:

  This is to complete #811.

  It displays any warnings generated by `createspend` on the draft PSBT view, which could currently be those from #905 and #873. Once the PSBT has been saved, these warnings will no longer be shown.

  Below are some screenshots.

  With a warning:
  ![image](https://github.com/wizardsardine/liana/assets/121959000/fb2167d9-4800-4849-8622-ff20ac55623e)

  ![image](https://github.com/wizardsardine/liana/assets/121959000/e1ab9ec2-00ae-457f-81e1-9b3a2863af31)

  Without a warning:
  ![image](https://github.com/wizardsardine/liana/assets/121959000/73b5b4bd-55b5-40ee-b587-4f57bfd57b4c)

  ![image](https://github.com/wizardsardine/liana/assets/121959000/e9b23d4e-bb13-4ae7-944e-258f9c9a0abd)

ACKs for top commit:
  edouardparis:
    ACK 85f5a68

Tree-SHA512: b9875801f7607f6f824ad9ab5182e93aa533ba2bbb8f9a4168c4a2a779a8f39cf77dc0b24eac7c99a0fce36c486c126144d23b0cb7ecec27ebc145ea2ffdb212
  • Loading branch information
edouardparis committed Feb 27, 2024
2 parents 4baf632 + 85f5a68 commit 7801fc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gui/src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum Message {
Coins(Result<Vec<Coin>, Error>),
Labels(Result<HashMap<String, String>, Error>),
SpendTxs(Result<Vec<SpendTx>, Error>),
Psbt(Result<Psbt, Error>),
Psbt(Result<(Psbt, Vec<String>), Error>),
RbfPsbt(Result<Txid, Error>),
Recovery(Result<SpendTx, Error>),
Signed(Fingerprint, Result<Psbt, Error>),
Expand Down
44 changes: 25 additions & 19 deletions gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct TransactionDraft {
network: Network,
inputs: Vec<Coin>,
recipients: Vec<Recipient>,
generated: Option<Psbt>,
generated: Option<(Psbt, Vec<String>)>,
batch_label: Option<String>,
labels: HashMap<String, String>,
}
Expand Down Expand Up @@ -80,7 +80,7 @@ pub struct DefineSpend {
batch_label: form::Value<String>,
amount_left_to_select: Option<Amount>,
feerate: form::Value<String>,
generated: Option<Psbt>,
generated: Option<(Psbt, Vec<String>)>,
warning: Option<Error>,
}

Expand Down Expand Up @@ -351,7 +351,9 @@ impl Step for DefineSpend {
.create_spend_tx(&inputs, &outputs, feerate_vb, None)
.map_err(|e| e.into())
.and_then(|res| match res {
CreateSpendResult::Success { psbt, .. } => Ok(psbt),
CreateSpendResult::Success { psbt, warnings } => {
Ok((psbt, warnings))
}
CreateSpendResult::InsufficientFunds { missing } => {
Err(SpendCreationError::CoinSelection(
liana::spend::InsufficientFunds { missing },
Expand Down Expand Up @@ -405,7 +407,7 @@ impl Step for DefineSpend {
.filter_map(|(coin, selected)| if *selected { Some(coin) } else { None })
.cloned()
.collect();
if let Some(psbt) = &self.generated {
if let Some((psbt, _)) = &self.generated {
draft.labels = self.coins_labels.clone();
for (i, output) in psbt.unsigned_tx.output.iter().enumerate() {
if let Some(label) = self
Expand Down Expand Up @@ -550,7 +552,7 @@ impl Recipient {

pub struct SaveSpend {
wallet: Arc<Wallet>,
spend: Option<psbt::PsbtState>,
spend: Option<(psbt::PsbtState, Vec<String>)>,
curve: secp256k1::Secp256k1<secp256k1::VerifyOnly>,
}

Expand All @@ -566,7 +568,7 @@ impl SaveSpend {

impl Step for SaveSpend {
fn load(&mut self, draft: &TransactionDraft) {
let psbt = draft.generated.clone().unwrap();
let (psbt, warnings) = draft.generated.clone().unwrap();
let mut tx = SpendTx::new(
None,
psbt,
Expand All @@ -590,12 +592,15 @@ impl Step for SaveSpend {
}
}

self.spend = Some(psbt::PsbtState::new(self.wallet.clone(), tx, false));
self.spend = Some((
psbt::PsbtState::new(self.wallet.clone(), tx, false),
warnings,
));
}

fn subscription(&self) -> Subscription<Message> {
if let Some(spend) = &self.spend {
spend.subscription()
if let Some((psbt_state, _)) = &self.spend {
psbt_state.subscription()
} else {
Subscription::none()
}
Expand All @@ -607,26 +612,27 @@ impl Step for SaveSpend {
cache: &Cache,
message: Message,
) -> Command<Message> {
if let Some(spend) = &mut self.spend {
spend.update(daemon, cache, message)
if let Some((psbt_state, _)) = &mut self.spend {
psbt_state.update(daemon, cache, message)
} else {
Command::none()
}
}

fn view<'a>(&'a self, cache: &'a Cache) -> Element<'a, view::Message> {
let spend = self.spend.as_ref().unwrap();
let (psbt_state, warnings) = self.spend.as_ref().unwrap();
let content = view::spend::spend_view(
cache,
&spend.tx,
spend.saved,
&spend.desc_policy,
&spend.wallet.keys_aliases,
spend.labels_edited.cache(),
&psbt_state.tx,
warnings,
psbt_state.saved,
&psbt_state.desc_policy,
&psbt_state.wallet.keys_aliases,
psbt_state.labels_edited.cache(),
cache.network,
spend.warning.as_ref(),
psbt_state.warning.as_ref(),
);
if let Some(action) = &spend.action {
if let Some(action) = &psbt_state.action {
action.as_ref().view(content)
} else {
content
Expand Down
16 changes: 16 additions & 0 deletions gui/src/app/view/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
pub fn spend_view<'a>(
cache: &'a Cache,
tx: &'a SpendTx,
spend_warnings: &'a Vec<String>,
saved: bool,
desc_info: &'a LianaPolicy,
key_aliases: &'a HashMap<Fingerprint, String>,
Expand All @@ -48,6 +49,21 @@ pub fn spend_view<'a>(
.spacing(20)
.push(Container::new(h3("Send")).width(Length::Fill))
.push(psbt::spend_header(tx, labels_editing))
.push_maybe(if spend_warnings.is_empty() || saved {
None
} else {
Some(spend_warnings.iter().fold(
Column::new().padding(15).spacing(5),
|col, warning| {
col.push(
Row::new()
.spacing(5)
.push(icon::warning_icon().style(color::ORANGE))
.push(text(warning).style(color::ORANGE)),
)
},
))
})
.push(psbt::spend_overview_view(tx, desc_info, key_aliases))
.push(
Column::new()
Expand Down

0 comments on commit 7801fc7

Please sign in to comment.