Skip to content

Commit

Permalink
gui: don't treat wallets using bitcoind as syncing
Browse files Browse the repository at this point in the history
If the user has imported a descriptor and is using bitcoind as
a local node, then they will need to perform a rescan in order
to see past transactions.

Treating the wallet as syncing in this case could mislead the
user that a rescan is being performed. Therefore, it's better
to keep the past behaviour here to avoid further confusion.
  • Loading branch information
jp1ac4 committed Oct 18, 2024
1 parent 67c9262 commit bda97cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
15 changes: 13 additions & 2 deletions gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use iced::{clipboard, time, Command, Subscription};
use tokio::runtime::Handle;
use tracing::{error, info, warn};

use liana::config::BitcoinBackend;
pub use liana::{commands::CoinStatus, config::Config as DaemonConfig, miniscript::bitcoin};
use liana_ui::{
component::network_banner,
Expand All @@ -36,7 +37,7 @@ use state::{
use crate::{
app::{cache::Cache, error::Error, menu::Menu, wallet::Wallet},
daemon::{embedded::EmbeddedDaemon, Daemon, DaemonBackend},
node::bitcoind::Bitcoind,
node::{bitcoind::Bitcoind, NodeType},
};

use self::state::SettingsState;
Expand All @@ -60,10 +61,11 @@ impl Panels {
data_dir: PathBuf,
daemon_backend: DaemonBackend,
internal_bitcoind: Option<&Bitcoind>,
node_type: Option<NodeType>,
) -> Panels {
Self {
current: Menu::Home,
home: Home::new(wallet.clone(), &cache.coins, cache.blockheight),
home: Home::new(wallet.clone(), &cache.coins, cache.blockheight, node_type),
coins: CoinsPanel::new(&cache.coins, wallet.main_descriptor.first_timelock_value()),
transactions: TransactionsPanel::new(wallet.clone()),
psbts: PsbtsPanel::new(wallet.clone()),
Expand Down Expand Up @@ -136,12 +138,21 @@ impl App {
data_dir: PathBuf,
internal_bitcoind: Option<Bitcoind>,
) -> (App, Command<Message>) {
let node_type = match daemon
.config()
.and_then(|config| config.bitcoin_backend.as_ref())
{
Some(BitcoinBackend::Bitcoind(_)) => Some(NodeType::Bitcoind),
Some(BitcoinBackend::Electrum(_)) => Some(NodeType::Electrum),
None => None,
};
let mut panels = Panels::new(
&cache,
wallet.clone(),
data_dir,
daemon.backend(),
internal_bitcoind.as_ref(),
node_type,
);
let cmd = panels.home.reload(daemon.clone(), wallet.clone());
(
Expand Down
29 changes: 24 additions & 5 deletions gui/src/app/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ use super::{cache::Cache, error::Error, menu::Menu, message::Message, view, wall

pub const HISTORY_EVENT_PAGE_SIZE: u64 = 20;

use crate::daemon::{
model::{remaining_sequence, Coin, HistoryTransaction, Labelled},
Daemon,
use crate::{
daemon::{
model::{remaining_sequence, Coin, HistoryTransaction, Labelled},
Daemon,
},
node::NodeType,
};
pub use coins::CoinsPanel;
use label::LabelsEdited;
Expand Down Expand Up @@ -69,6 +72,7 @@ pub fn redirect(menu: Menu) -> Command<Message> {
pub struct Home {
wallet: Arc<Wallet>,
blockheight: i32,
node_type: Option<NodeType>,
balance: Amount,
unconfirmed_balance: Amount,
remaining_sequence: Option<u32>,
Expand All @@ -83,7 +87,12 @@ pub struct Home {
}

impl Home {
pub fn new(wallet: Arc<Wallet>, coins: &[Coin], blockheight: i32) -> Self {
pub fn new(
wallet: Arc<Wallet>,
coins: &[Coin],
blockheight: i32,
node_type: Option<NodeType>,
) -> Self {
let (balance, unconfirmed_balance) = coins.iter().fold(
(Amount::from_sat(0), Amount::from_sat(0)),
|(balance, unconfirmed_balance), coin| {
Expand All @@ -100,6 +109,7 @@ impl Home {
Self {
wallet,
blockheight,
node_type,
balance,
unconfirmed_balance,
remaining_sequence: None,
Expand All @@ -115,7 +125,16 @@ impl Home {
}

fn wallet_is_syncing(&self) -> bool {
self.blockheight <= 0
if self.node_type == Some(NodeType::Bitcoind) {
// If user imported descriptor and is using a local bitcoind,
// a rescan will need to be performed in order to see
// past transactions and so the syncing status could be
// misleading as it could suggest the rescan is being
// performed.
false
} else {
self.blockheight <= 0
}
}
}

Expand Down

0 comments on commit bda97cf

Please sign in to comment.