fix: cache coins for remote backend when loading gui
This commit is contained in:
parent
e03d4e17be
commit
417a949037
@ -8,9 +8,13 @@ use liana_ui::{
|
||||
icon, theme,
|
||||
widget::*,
|
||||
};
|
||||
use lianad::commands::ListCoinsResult;
|
||||
|
||||
use crate::{
|
||||
app::settings::{AuthConfig, Settings, SettingsError, WalletSetting},
|
||||
app::{
|
||||
cache::coins_to_cache,
|
||||
settings::{AuthConfig, Settings, SettingsError, WalletSetting},
|
||||
},
|
||||
daemon::DaemonError,
|
||||
};
|
||||
|
||||
@ -68,7 +72,16 @@ pub enum Message {
|
||||
// redirect to the installer with the remote backend connection.
|
||||
Install(Option<BackendClient>),
|
||||
// redirect to the app runner with the remote backend connection.
|
||||
Run(Result<(BackendWalletClient, api::Wallet), Error>),
|
||||
Run(
|
||||
Result<
|
||||
(
|
||||
BackendWalletClient,
|
||||
api::Wallet,
|
||||
/* coins to cache */ ListCoinsResult,
|
||||
),
|
||||
Error,
|
||||
>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -83,7 +96,7 @@ pub enum ViewMessage {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum BackendState {
|
||||
NoWallet(BackendClient),
|
||||
WalletExists(BackendWalletClient, api::Wallet),
|
||||
WalletExists(BackendWalletClient, api::Wallet, ListCoinsResult),
|
||||
}
|
||||
|
||||
pub struct LianaLiteLogin {
|
||||
@ -182,10 +195,11 @@ impl LianaLiteLogin {
|
||||
Ok(BackendState::NoWallet(_)) => {
|
||||
self.auth_error = Some("No wallet found for the given email");
|
||||
}
|
||||
Ok(BackendState::WalletExists(client, wallet)) => {
|
||||
return Task::perform(async move { (client, wallet) }, |(c, w)| {
|
||||
Message::Run(Ok((c, w)))
|
||||
});
|
||||
Ok(BackendState::WalletExists(client, wallet, coins)) => {
|
||||
return Task::perform(
|
||||
async move { (client, wallet, coins) },
|
||||
|(c, w, coins)| Message::Run(Ok((c, w, coins))),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
self.connection_error = Some(e);
|
||||
@ -323,7 +337,7 @@ impl LianaLiteLogin {
|
||||
Ok(BackendState::NoWallet(client)) => {
|
||||
return Task::perform(async move { Some(client) }, Message::Install);
|
||||
}
|
||||
Ok(BackendState::WalletExists(client, wallet)) => {
|
||||
Ok(BackendState::WalletExists(client, wallet, coins)) => {
|
||||
let datadir = self.datadir.clone();
|
||||
let network = self.network;
|
||||
return Task::perform(
|
||||
@ -337,7 +351,7 @@ impl LianaLiteLogin {
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok((client, wallet))
|
||||
Ok((client, wallet, coins))
|
||||
},
|
||||
Message::Run,
|
||||
);
|
||||
@ -545,10 +559,12 @@ pub async fn connect(
|
||||
if wallet_id.is_empty() {
|
||||
let first = wallets.first().cloned().ok_or(DaemonError::NoAnswer)?;
|
||||
let (wallet_client, wallet) = client.connect_wallet(first);
|
||||
Ok(BackendState::WalletExists(wallet_client, wallet))
|
||||
let coins = coins_to_cache(Arc::new(wallet_client.clone())).await?;
|
||||
Ok(BackendState::WalletExists(wallet_client, wallet, coins))
|
||||
} else if let Some(wallet) = wallets.into_iter().find(|w| w.id == wallet_id) {
|
||||
let (wallet_client, wallet) = client.connect_wallet(wallet);
|
||||
Ok(BackendState::WalletExists(wallet_client, wallet))
|
||||
let coins = coins_to_cache(Arc::new(wallet_client.clone())).await?;
|
||||
Ok(BackendState::WalletExists(wallet_client, wallet, coins))
|
||||
} else {
|
||||
Ok(BackendState::NoWallet(client))
|
||||
}
|
||||
@ -571,7 +587,8 @@ pub async fn connect_with_refresh_token(
|
||||
.find(|w| w.id == wallet_id)
|
||||
{
|
||||
let (wallet_client, wallet) = client.connect_wallet(wallet);
|
||||
Ok(BackendState::WalletExists(wallet_client, wallet))
|
||||
let coins = coins_to_cache(Arc::new(wallet_client.clone())).await?;
|
||||
Ok(BackendState::WalletExists(wallet_client, wallet, coins))
|
||||
} else {
|
||||
Ok(BackendState::NoWallet(client))
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ extern crate serde_json;
|
||||
|
||||
use liana::miniscript::bitcoin;
|
||||
use liana_ui::{component::text, font, image, theme, widget::Element};
|
||||
use lianad::config::Config as DaemonConfig;
|
||||
use lianad::{commands::ListCoinsResult, config::Config as DaemonConfig};
|
||||
|
||||
use liana_gui::{
|
||||
app::{self, cache::Cache, config::default_datadir, wallet::Wallet, App},
|
||||
@ -272,7 +272,7 @@ impl GUI {
|
||||
self.state = State::Installer(Box::new(install));
|
||||
command.map(|msg| Message::Install(Box::new(msg)))
|
||||
}
|
||||
login::Message::Run(Ok((backend_client, wallet))) => {
|
||||
login::Message::Run(Ok((backend_client, wallet, coins))) => {
|
||||
let config = app::Config::from_file(
|
||||
&l.datadir
|
||||
.join(l.network.to_string())
|
||||
@ -288,6 +288,7 @@ impl GUI {
|
||||
let (app, command) = create_app_with_remote_backend(
|
||||
backend_client,
|
||||
wallet,
|
||||
coins,
|
||||
l.datadir.clone(),
|
||||
l.network,
|
||||
config,
|
||||
@ -463,6 +464,7 @@ impl GUI {
|
||||
pub fn create_app_with_remote_backend(
|
||||
remote_backend: BackendWalletClient,
|
||||
wallet: api::Wallet,
|
||||
coins: ListCoinsResult,
|
||||
datadir: PathBuf,
|
||||
network: bitcoin::Network,
|
||||
config: app::Config,
|
||||
@ -498,7 +500,7 @@ pub fn create_app_with_remote_backend(
|
||||
App::new(
|
||||
Cache {
|
||||
network,
|
||||
coins: Vec::new(),
|
||||
coins: coins.coins,
|
||||
rescan_progress: None,
|
||||
sync_progress: 1.0, // Remote backend is always synced
|
||||
datadir_path: datadir.clone(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user