gui: don't treat wallets using bitcoind as syncing

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.
This commit is contained in:
Michael Mallan 2024-10-18 17:16:25 +01:00
parent f34bb1b79a
commit 9208cd11b2
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB
2 changed files with 42 additions and 16 deletions

View File

@ -63,7 +63,12 @@ impl Panels {
) -> Panels {
Self {
current: Menu::Home,
home: Home::new(wallet.clone(), &cache.coins, cache.blockheight),
home: Home::new(
wallet.clone(),
&cache.coins,
cache.blockheight,
daemon_backend.clone(),
),
coins: CoinsPanel::new(&cache.coins, wallet.main_descriptor.first_timelock_value()),
transactions: TransactionsPanel::new(wallet.clone()),
psbts: PsbtsPanel::new(wallet.clone()),

View File

@ -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, DaemonBackend,
},
node::NodeType,
};
pub use coins::CoinsPanel;
use label::LabelsEdited;
@ -66,9 +69,24 @@ pub fn redirect(menu: Menu) -> Command<Message> {
})
}
fn wallet_is_syncing(daemon_backend: DaemonBackend, blockheight: i32) -> bool {
match daemon_backend {
// 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.
// For external daemon or if we otherwise don't know the node type,
// treat it the same as bitcoind to be sure we don't mislead the user.
DaemonBackend::EmbeddedLianad(Some(NodeType::Bitcoind))
| DaemonBackend::EmbeddedLianad(None)
| DaemonBackend::ExternalLianad => false,
_ => blockheight <= 0,
}
}
pub struct Home {
wallet: Arc<Wallet>,
blockheight: i32,
wallet_is_syncing: bool,
balance: Amount,
unconfirmed_balance: Amount,
remaining_sequence: Option<u32>,
@ -83,7 +101,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,
daemon_backend: DaemonBackend,
) -> Self {
let (balance, unconfirmed_balance) = coins.iter().fold(
(Amount::from_sat(0), Amount::from_sat(0)),
|(balance, unconfirmed_balance), coin| {
@ -97,9 +120,11 @@ impl Home {
},
);
let wallet_is_syncing = wallet_is_syncing(daemon_backend, blockheight);
Self {
wallet,
blockheight,
wallet_is_syncing,
balance,
unconfirmed_balance,
remaining_sequence: None,
@ -113,10 +138,6 @@ impl Home {
processing: false,
}
}
fn wallet_is_syncing(&self) -> bool {
self.blockheight <= 0
}
}
impl State for Home {
@ -148,7 +169,7 @@ impl State for Home {
&self.events,
self.is_last_page,
self.processing,
self.wallet_is_syncing(),
self.wallet_is_syncing,
),
)
}
@ -226,10 +247,10 @@ impl State for Home {
}
},
Message::UpdatePanelCache(is_current, Ok(cache)) => {
let wallet_was_syncing = self.wallet_is_syncing();
self.blockheight = cache.blockheight;
let wallet_was_syncing = self.wallet_is_syncing;
self.wallet_is_syncing = wallet_is_syncing(daemon.backend(), cache.blockheight);
// If this is the current panel, reload it if wallet is no longer syncing.
if is_current && wallet_was_syncing && !self.wallet_is_syncing() {
if is_current && wallet_was_syncing && !self.wallet_is_syncing {
return self.reload(daemon, self.wallet.clone());
}
}
@ -310,7 +331,7 @@ impl State for Home {
wallet: Arc<Wallet>,
) -> Command<Message> {
// Wait for wallet to finish syncing before reloading data.
if self.wallet_is_syncing() {
if self.wallet_is_syncing {
return Command::none();
}
self.selected_event = None;