Skip to content

Commit

Permalink
display wallet birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
pythcoiner committed Feb 24, 2024
1 parent a34070d commit 5846fe3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
8 changes: 3 additions & 5 deletions gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,9 @@ impl App {
}

pub fn load_wallet(&mut self) -> Result<Arc<Wallet>, 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);

Expand Down
13 changes: 9 additions & 4 deletions gui/src/app/state/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ mod tests {
daemon::{
client::{Lianad, Request},
model::*,
Daemon,
},
utils::{mock::Daemon, sandbox::Sandbox},
utils::{mock::Daemon as MockDaemon, sandbox::Sandbox},
};

use liana::{descriptors::LianaDescriptor, miniscript::bitcoin::Address};
Expand All @@ -300,19 +301,23 @@ mod tests {
Address::from_str("tb1qkldgvljmjpxrjq2ev5qxe8dvhn0dph9q85pwtfkjeanmwdue2akqj4twxj")
.unwrap()
.assume_checked();
let daemon = Daemon::new(vec![(
let daemon = MockDaemon::new(vec![(
Some(json!({"method": "getnewaddress", "params": Option::<Request>::None})),
Ok(json!(GetAddressResult::new(
addr.clone(),
ChildNumber::from_normal_idx(0).unwrap()
))),
)]);

let client = Arc::new(Lianad::new(daemon.run()));
let timestamp = client.get_info().unwrap().timestamp;
let sandbox: Sandbox<ReceivePanel> = Sandbox::new(ReceivePanel::new(
PathBuf::new(),
Arc::new(Wallet::new(LianaDescriptor::from_str(DESC).unwrap())),
Arc::new(Wallet::new(
LianaDescriptor::from_str(DESC).unwrap(),
timestamp,
)),
));
let client = Arc::new(Lianad::new(daemon.run()));
let sandbox = sandbox.load(client, &Cache::default()).await;

let panel = sandbox.state();
Expand Down
7 changes: 6 additions & 1 deletion gui/src/app/state/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion gui/src/app/state/settings/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ pub struct WalletSettingsState {
modal: Option<RegisterWalletModal>,
processing: bool,
updated: bool,
creation_date: u32,
}

impl WalletSettingsState {
pub fn new(data_dir: PathBuf, wallet: Arc<Wallet>) -> Self {
pub fn new(data_dir: PathBuf, wallet: Arc<Wallet>, creation_date: u32) -> Self {
WalletSettingsState {
data_dir,
descriptor: wallet.main_descriptor.to_string(),
Expand All @@ -42,6 +43,7 @@ impl WalletSettingsState {
modal: None,
processing: false,
updated: false,
creation_date,
}
}

Expand Down Expand Up @@ -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())
Expand Down
14 changes: 14 additions & 0 deletions gui/src/app/view/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ pub fn wallet_settings<'a>(
keys_aliases: &[(Fingerprint, form::Value<String>)],
processing: bool,
updated: bool,
creation_date: u32,
) -> Element<'a, Message> {
dashboard(
&Menu::Settings,
Expand All @@ -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())
Expand Down Expand Up @@ -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<Row<'static, Message>> {
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
}
4 changes: 3 additions & 1 deletion gui/src/app/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ pub struct Wallet {
pub keys_aliases: HashMap<Fingerprint, String>,
pub hardware_wallets: Vec<HardwareWalletConfig>,
pub signer: Option<Signer>,
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,
}
}

Expand Down
7 changes: 5 additions & 2 deletions gui/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit 5846fe3

Please sign in to comment.