From 616073588c17115257e558ac80cdff8a4fcb7dc3 Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Mon, 29 Jan 2024 17:24:25 +0100 Subject: [PATCH] display wallet birthday --- gui/src/app/mod.rs | 8 +++----- gui/src/app/state/receive.rs | 2 +- gui/src/app/state/settings/mod.rs | 7 ++++++- gui/src/app/state/settings/wallet.rs | 5 ++++- gui/src/app/view/settings.rs | 14 ++++++++++++++ gui/src/app/wallet.rs | 4 +++- gui/src/loader.rs | 7 +++++-- 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs index 0f3443c3b..8312abdad 100644 --- a/gui/src/app/mod.rs +++ b/gui/src/app/mod.rs @@ -218,11 +218,9 @@ impl App { } pub fn load_wallet(&mut self) -> Result, Error> { - let wallet = Wallet::new(self.wallet.main_descriptor.clone()).load_settings( - &self.config, - &self.data_dir, - self.cache.network, - )?; + let info = self.daemon.get_info()?; + let wallet = Wallet::new(self.wallet.main_descriptor.clone(), info.timestamp) + .load_settings(&self.config, &self.data_dir, self.cache.network)?; self.wallet = Arc::new(wallet); diff --git a/gui/src/app/state/receive.rs b/gui/src/app/state/receive.rs index 8a7f85a7b..fabf7cd40 100644 --- a/gui/src/app/state/receive.rs +++ b/gui/src/app/state/receive.rs @@ -310,7 +310,7 @@ mod tests { let sandbox: Sandbox = Sandbox::new(ReceivePanel::new( PathBuf::new(), - Arc::new(Wallet::new(LianaDescriptor::from_str(DESC).unwrap())), + Arc::new(Wallet::new(LianaDescriptor::from_str(DESC).unwrap(), 0)), )); let client = Arc::new(Lianad::new(daemon.run())); let sandbox = sandbox.load(client, &Cache::default()).await; diff --git a/gui/src/app/state/settings/mod.rs b/gui/src/app/state/settings/mod.rs index ad88a406b..d1e09130d 100644 --- a/gui/src/app/state/settings/mod.rs +++ b/gui/src/app/state/settings/mod.rs @@ -78,7 +78,12 @@ impl State for SettingsState { } Message::View(view::Message::Settings(view::SettingsMessage::EditWalletSettings)) => { self.setting = Some( - WalletSettingsState::new(self.data_dir.clone(), self.wallet.clone()).into(), + WalletSettingsState::new( + self.data_dir.clone(), + self.wallet.clone(), + self.wallet.timestamp, + ) + .into(), ); self.setting .as_mut() diff --git a/gui/src/app/state/settings/wallet.rs b/gui/src/app/state/settings/wallet.rs index 8686a9809..e8903d173 100644 --- a/gui/src/app/state/settings/wallet.rs +++ b/gui/src/app/state/settings/wallet.rs @@ -29,10 +29,11 @@ pub struct WalletSettingsState { modal: Option, processing: bool, updated: bool, + creation_date: u32, } impl WalletSettingsState { - pub fn new(data_dir: PathBuf, wallet: Arc) -> Self { + pub fn new(data_dir: PathBuf, wallet: Arc, creation_date: u32) -> Self { WalletSettingsState { data_dir, descriptor: wallet.main_descriptor.to_string(), @@ -42,6 +43,7 @@ impl WalletSettingsState { modal: None, processing: false, updated: false, + creation_date, } } @@ -81,6 +83,7 @@ impl State for WalletSettingsState { &self.keys_aliases, self.processing, self.updated, + self.creation_date, ); if let Some(m) = &self.modal { modal::Modal::new(content, m.view()) diff --git a/gui/src/app/view/settings.rs b/gui/src/app/view/settings.rs index 4618ad4b0..ec96d6e1c 100644 --- a/gui/src/app/view/settings.rs +++ b/gui/src/app/view/settings.rs @@ -589,6 +589,7 @@ pub fn wallet_settings<'a>( keys_aliases: &[(Fingerprint, form::Value)], processing: bool, updated: bool, + creation_date: u32, ) -> Element<'a, Message> { dashboard( &Menu::Settings, @@ -612,6 +613,7 @@ pub fn wallet_settings<'a>( .on_press(Message::Settings(SettingsMessage::AboutSection)), ), ) + .push_maybe(creation_date_message(creation_date)) .push(card::simple( Column::new() .push(text("Wallet descriptor:").bold()) @@ -738,3 +740,15 @@ pub fn register_wallet_modal<'a>( .width(Length::Fixed(500.0)) .into() } + +pub fn creation_date_message(creation_date: u32) -> Option> { + if let Some(datetime) = chrono::NaiveDateTime::from_timestamp_opt(creation_date as i64, 0) { + return Some( + Row::new() + .push(text("Wallet creation date:").bold()) + .spacing(10) + .push(text(datetime.format("%y/%m/%d").to_string())), + ); + } + None +} diff --git a/gui/src/app/wallet.rs b/gui/src/app/wallet.rs index e9cd483d4..d7ed48d92 100644 --- a/gui/src/app/wallet.rs +++ b/gui/src/app/wallet.rs @@ -35,16 +35,18 @@ pub struct Wallet { pub keys_aliases: HashMap, pub hardware_wallets: Vec, pub signer: Option, + pub timestamp: u32, } impl Wallet { - pub fn new(main_descriptor: LianaDescriptor) -> Self { + pub fn new(main_descriptor: LianaDescriptor, timestamp: u32) -> Self { Self { name: wallet_name(&main_descriptor), main_descriptor, keys_aliases: HashMap::new(), hardware_wallets: Vec::new(), signer: None, + timestamp, } } diff --git a/gui/src/loader.rs b/gui/src/loader.rs index 19f43033f..ff4b69764 100644 --- a/gui/src/loader.rs +++ b/gui/src/loader.rs @@ -364,8 +364,11 @@ pub async fn load_application( ), Error, > { - let wallet = - Wallet::new(info.descriptors.main).load_settings(&gui_config, &datadir_path, network)?; + let wallet = Wallet::new(info.descriptors.main, info.timestamp).load_settings( + &gui_config, + &datadir_path, + network, + )?; let coins = daemon.list_coins().map(|res| res.coins)?; let spend_txs = daemon.list_spend_transactions(None)?;