Skip to content

Commit

Permalink
cargo clippy --fix --lib -p liana_gui
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Aug 29, 2023
1 parent 50a7252 commit caeb06a
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 47 deletions.
4 changes: 2 additions & 2 deletions gui/src/app/settings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Settings is the module to handle the GUI settings file.
//! The settings file is used by the GUI to store useful information.
use std::collections::HashMap;
use std::fs::OpenOptions;
use std::io::Write;
Expand All @@ -8,8 +10,6 @@ use serde::{Deserialize, Serialize};

use crate::{app::wallet::Wallet, hw::HardwareWalletConfig};

///! Settings is the module to handle the GUI settings file.
///! The settings file is used by the GUI to store useful information.
pub const DEFAULT_FILE_NAME: &str = "settings.json";

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
10 changes: 2 additions & 8 deletions gui/src/app/state/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ impl CoinsPanel {
fn update_coins(&mut self, coins: &[Coin]) {
self.coins.list = coins
.iter()
.filter_map(|coin| {
if coin.spend_info.is_none() {
Some(coin)
} else {
None
}
})
.filter(|coin| coin.spend_info.is_none())
.cloned()
.collect();

Expand Down Expand Up @@ -171,7 +165,7 @@ impl State for CoinsPanel {
let coins = daemon2
.list_coins()
.map(|res| res.coins)
.map_err(|e| Error::from(e))?;
.map_err(Error::from)?;
let mut targets = HashSet::<LabelItem>::new();
for coin in coins {
targets.insert(LabelItem::OutPoint(coin.outpoint));
Expand Down
4 changes: 2 additions & 2 deletions gui/src/app/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl State for Home {
cache,
event,
output_index,
&self.labels_edited.cache(),
self.labels_edited.cache(),
self.warning.as_ref(),
)
} else {
Expand Down Expand Up @@ -329,7 +329,7 @@ impl State for ReceivePanel {
&self.addresses.list,
self.qr_code.as_ref(),
&self.addresses.labels,
&self.labels_edited.cache(),
self.labels_edited.cache(),
),
)
}
Expand Down
8 changes: 4 additions & 4 deletions gui/src/app/state/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl PsbtState {
self.action = None;
}
view::SpendTxMessage::Delete => {
self.action = Some(Box::new(DeleteAction::default()));
self.action = Some(Box::<DeleteAction>::default());
}
view::SpendTxMessage::Sign => {
let action = SignAction::new(self.tx.signers(), self.wallet.clone());
Expand All @@ -104,10 +104,10 @@ impl PsbtState {
return cmd;
}
view::SpendTxMessage::Broadcast => {
self.action = Some(Box::new(BroadcastAction::default()));
self.action = Some(Box::<BroadcastAction>::default());
}
view::SpendTxMessage::Save => {
self.action = Some(Box::new(SaveAction::default()));
self.action = Some(Box::<SaveAction>::default());
}
_ => {
if let Some(action) = self.action.as_mut() {
Expand Down Expand Up @@ -151,7 +151,7 @@ impl PsbtState {
self.saved,
&self.desc_policy,
&self.wallet.keys_aliases,
&self.labels_edited.cache(),
self.labels_edited.cache(),
cache.network,
self.warning.as_ref(),
);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/state/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl State for CreateSpendPanel {
let coins = daemon
.list_coins()
.map(|res| res.coins)
.map_err(|e| Error::from(e))?;
.map_err(Error::from)?;
let mut targets = HashSet::<LabelItem>::new();
for coin in coins {
targets.insert(LabelItem::OutPoint(coin.outpoint));
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl Step for SaveSpend {
spend.saved,
&spend.desc_policy,
&spend.wallet.keys_aliases,
&spend.labels_edited.cache(),
spend.labels_edited.cache(),
cache.network,
spend.warning.as_ref(),
);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/state/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl State for TransactionsPanel {
view::transactions::tx_view(
cache,
tx,
&self.labels_edited.cache(),
self.labels_edited.cache(),
self.warning.as_ref(),
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/view/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub fn coin_sequence_label<'a, T: 'a>(seq: u32, timelock: u32) -> Container<'a,
)
.padding(10)
.style(theme::Container::Pill(theme::Pill::Warning))
} else if seq < timelock as u32 * 10 / 100 {
} else if seq < timelock * 10 / 100 {
Container::new(
Row::new()
.spacing(5)
Expand Down
17 changes: 9 additions & 8 deletions gui/src/app/view/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn home_view<'a>(
.into()
}

fn event_list_view<'a>(i: usize, event: &'a HistoryTransaction) -> Column<'a, Message> {
fn event_list_view(i: usize, event: &HistoryTransaction) -> Column<'_, Message> {
event.tx.output.iter().enumerate().fold(
Column::new().spacing(10),
|col, (output_index, output)| {
Expand All @@ -158,14 +158,15 @@ fn event_list_view<'a>(i: usize, event: &'a HistoryTransaction) -> Column<'a, Me
.to_string(),
) {
Some(p1_bold(label))
} else if let Some(label) = event.labels.get(
&bitcoin::Address::from_script(&output.script_pubkey, event.network)
.unwrap()
.to_string(),
) {
Some(p1_bold(format!("address label: {}", label)).style(color::GREY_3))
} else {
None
event
.labels
.get(
&bitcoin::Address::from_script(&output.script_pubkey, event.network)
.unwrap()
.to_string(),
)
.map(|label| p1_bold(format!("address label: {}", label)).style(color::GREY_3))
};
if event.is_external() {
if !event.change_indexes.contains(&output_index) {
Expand Down
6 changes: 3 additions & 3 deletions gui/src/app/view/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use liana_ui::{

use crate::app::view;

pub fn label_editable<'a>(
pub fn label_editable(
labelled: String,
label: Option<&'a String>,
label: Option<&String>,
size: u16,
) -> Element<'a, view::Message> {
) -> Element<'_, view::Message> {
if let Some(label) = label {
if !label.is_empty() {
return Container::new(
Expand Down
1 change: 1 addition & 0 deletions gui/src/app/view/pbst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::{
hw::HardwareWallet,
};

#[allow(clippy::too_many_arguments)]
pub fn psbt_view<'a>(
cache: &'a Cache,
tx: &'a SpendTx,
Expand Down
7 changes: 4 additions & 3 deletions gui/src/app/view/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::{
hw::HardwareWallet,
};

#[allow(clippy::too_many_arguments)]
pub fn psbt_view<'a>(
cache: &'a Cache,
tx: &'a SpendTx,
Expand Down Expand Up @@ -584,7 +585,7 @@ pub fn inputs_and_outputs_view<'a>(
.enumerate()
.filter(|(i, _)| {
if let Some(indexes) = change_indexes_copy.as_ref() {
!indexes.contains(&i)
!indexes.contains(i)
} else {
true
}
Expand Down Expand Up @@ -634,7 +635,7 @@ pub fn inputs_and_outputs_view<'a>(
.enumerate()
.filter(|(i, _)| {
if let Some(indexes) = change_indexes_copy.as_ref() {
!indexes.contains(&i)
!indexes.contains(i)
} else {
true
}
Expand Down Expand Up @@ -697,7 +698,7 @@ pub fn inputs_and_outputs_view<'a>(
tx.output
.iter()
.enumerate()
.filter(|(i, _)| change_indexes.as_ref().unwrap().contains(&i))
.filter(|(i, _)| change_indexes.as_ref().unwrap().contains(i))
.fold(
Column::new().padding(20),
|col: Column<'a, Message>, (i, output)| {
Expand Down
6 changes: 3 additions & 3 deletions gui/src/app/view/psbts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn import_psbt_success_view<'a>() -> Element<'a, Message> {
.into()
}

pub fn psbts_view<'a>(spend_txs: &'a [SpendTx]) -> Element<'a, Message> {
pub fn psbts_view(spend_txs: &[SpendTx]) -> Element<'_, Message> {
Column::new()
.push(
Row::new()
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn psbts_view<'a>(spend_txs: &'a [SpendTx]) -> Element<'a, Message> {
.into()
}

fn spend_tx_list_view<'a>(i: usize, tx: &'a SpendTx) -> Element<'a, Message> {
fn spend_tx_list_view(i: usize, tx: &SpendTx) -> Element<'_, Message> {
Container::new(
Button::new(
Row::new()
Expand Down Expand Up @@ -127,7 +127,7 @@ fn spend_tx_list_view<'a>(i: usize, tx: &'a SpendTx) -> Element<'a, Message> {
.push_maybe(
tx.labels
.get(&tx.psbt.unsigned_tx.txid().to_string())
.map(|label| p1_bold(label)),
.map(p1_bold),
)
.spacing(10)
.align_items(Alignment::Center)
Expand Down
1 change: 1 addition & 0 deletions gui/src/app/view/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
daemon::model::{remaining_sequence, Coin, SpendTx},
};

#[allow(clippy::too_many_arguments)]
pub fn spend_view<'a>(
cache: &'a Cache,
tx: &'a SpendTx,
Expand Down
8 changes: 2 additions & 6 deletions gui/src/app/view/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn transactions_view<'a>(
)
}

fn tx_list_view<'a>(i: usize, tx: &'a HistoryTransaction) -> Element<'a, Message> {
fn tx_list_view(i: usize, tx: &HistoryTransaction) -> Element<'_, Message> {
Container::new(
Button::new(
Row::new()
Expand All @@ -99,11 +99,7 @@ fn tx_list_view<'a>(i: usize, tx: &'a HistoryTransaction) -> Element<'a, Message
})
.push(
Column::new()
.push_maybe(
tx.labels
.get(&tx.tx.txid().to_string())
.map(|label| p1_bold(label)),
)
.push_maybe(tx.labels.get(&tx.tx.txid().to_string()).map(p1_bold))
.push_maybe(tx.time.map(|t| {
Container::new(
text(format!(
Expand Down
8 changes: 4 additions & 4 deletions gui/src/daemon/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl SpendTx {
.output
.iter()
.enumerate()
.filter(|(i, _)| !self.change_indexes.contains(&i))
.filter(|(i, _)| !self.change_indexes.contains(i))
.count()
> 1
}
Expand All @@ -153,7 +153,7 @@ impl Labelled for SpendTx {
items.push(LabelItem::Txid(txid));
for coin in &self.coins {
items.push(LabelItem::Address(coin.address.clone()));
items.push(LabelItem::OutPoint(coin.outpoint.clone()));
items.push(LabelItem::OutPoint(coin.outpoint));
}
for (vout, output) in self.psbt.unsigned_tx.output.iter().enumerate() {
items.push(LabelItem::OutPoint(OutPoint {
Expand Down Expand Up @@ -240,7 +240,7 @@ impl HistoryTransaction {
.output
.iter()
.enumerate()
.filter(|(i, _)| !self.change_indexes.contains(&i))
.filter(|(i, _)| !self.change_indexes.contains(i))
.count()
> 1
}
Expand All @@ -256,7 +256,7 @@ impl Labelled for HistoryTransaction {
items.push(LabelItem::Txid(txid));
for coin in &self.coins {
items.push(LabelItem::Address(coin.address.clone()));
items.push(LabelItem::OutPoint(coin.outpoint.clone()));
items.push(LabelItem::OutPoint(coin.outpoint));
}
for (vout, output) in self.tx.output.iter().enumerate() {
items.push(LabelItem::OutPoint(OutPoint {
Expand Down

0 comments on commit caeb06a

Please sign in to comment.