From 14e10a6721f4e769fe1830b1c7d188d656e6ab1a Mon Sep 17 00:00:00 2001 From: flo Date: Mon, 10 Oct 2022 10:44:33 -0600 Subject: [PATCH 1/4] The inst_owner_api function shall set the owner_api of the wallet interface if the chain types do not match. Fixes different owner api when user creates testnet wallet then opens a mainnet wallet. --- crates/core/src/wallet/mod.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/core/src/wallet/mod.rs b/crates/core/src/wallet/mod.rs index d2a5199..ffee80d 100644 --- a/crates/core/src/wallet/mod.rs +++ b/crates/core/src/wallet/mod.rs @@ -194,12 +194,19 @@ where { let w = wallet_interface.read().unwrap(); if let Some(_) = &w.owner_api { - global::set_local_chain_type(chain_type); - return Ok(()); + // chain type from previous inst must match + if w.chain_type.unwrap() == chain_type { + global::set_local_chain_type(chain_type); + return Ok(()); + } } } - let wallet_inst = WalletInterface::inst_wallet(wallet_interface.clone(), chain_type, top_level_directory)?; + let wallet_inst = WalletInterface::inst_wallet( + wallet_interface.clone(), + chain_type, + top_level_directory, + )?; let mut w = wallet_interface.write().unwrap(); w.owner_api = Some(Owner::new(wallet_inst.clone(), None)); global::set_local_chain_type(chain_type); @@ -214,7 +221,11 @@ where display_name: String, chain_type: global::ChainTypes, ) -> Result<(String, String, String, global::ChainTypes), GrinWalletInterfaceError> { - WalletInterface::inst_owner_api(wallet_interface.clone(), chain_type, top_level_directory.clone())?; + WalletInterface::inst_owner_api( + wallet_interface.clone(), + chain_type, + top_level_directory.clone(), + )?; let w = wallet_interface.read().unwrap(); @@ -264,7 +275,11 @@ where top_level_directory: PathBuf, chain_type: global::ChainTypes, ) -> Result<(), GrinWalletInterfaceError> { - WalletInterface::inst_owner_api(wallet_interface.clone(), chain_type, top_level_directory.clone())?; + WalletInterface::inst_owner_api( + wallet_interface.clone(), + chain_type, + top_level_directory.clone(), + )?; let mut w = wallet_interface.write().unwrap(); From bdb51e9c0cf7d902af38809ff9ba5d13ae2e0286 Mon Sep 17 00:00:00 2001 From: flo Date: Mon, 10 Oct 2022 10:48:08 -0600 Subject: [PATCH 2/4] Copy to clipboard after wallet success should be recover phrase. --- src/gui/element/wallet/setup/wallet_success.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/element/wallet/setup/wallet_success.rs b/src/gui/element/wallet/setup/wallet_success.rs index 474b822..33acfec 100644 --- a/src/gui/element/wallet/setup/wallet_success.rs +++ b/src/gui/element/wallet/setup/wallet_success.rs @@ -89,7 +89,7 @@ pub fn data_container<'a>( ) .style(style::NormalTextButton(color_palette)) .on_press(Message::Interaction(Interaction::WriteToClipboard( - "Write to clipboard".to_owned(), + state.recovery_phrase.clone(), ))), ), ) From f6369ad177da903a5e4b67f78da3b618197da1c9 Mon Sep 17 00:00:00 2001 From: flo Date: Mon, 10 Oct 2022 10:52:01 -0600 Subject: [PATCH 3/4] Added chain header to wallet selection...needs alignment. --- src/gui/element/wallet/setup/wallet_list.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gui/element/wallet/setup/wallet_list.rs b/src/gui/element/wallet/setup/wallet_list.rs index 900adb3..defc2c9 100644 --- a/src/gui/element/wallet/setup/wallet_list.rs +++ b/src/gui/element/wallet/setup/wallet_list.rs @@ -139,6 +139,12 @@ pub fn data_container<'a>( let name_header_container = Container::new(name_header) .style(style::NormalBackgroundContainer(color_palette)); + let chain_header = Text::new(localized_string("Chain")) + .size(DEFAULT_HEADER_FONT_SIZE); + + let chain_header_container = Container::new(chain_header) + .style(style::NormalBackgroundContainer(color_palette)); + let directory_header = Text::new(localized_string("Location")) .size(DEFAULT_HEADER_FONT_SIZE); @@ -147,6 +153,8 @@ pub fn data_container<'a>( let header_row = Row::new() .push(name_header_container) + .push(Space::new(Length::Units(85), Length::Units(0))) + .push(chain_header_container) .push(Space::new(Length::Units(135), Length::Units(0))) .push(directory_header_container); From 42cae4e440fa422a98d0fa82eb2a5256f2b65fb7 Mon Sep 17 00:00:00 2001 From: flo Date: Mon, 10 Oct 2022 11:20:48 -0600 Subject: [PATCH 4/4] Start of close wallet. --- crates/core/src/wallet/mod.rs | 14 +++++++++++ src/gui/element/wallet/operation/home.rs | 32 ++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/core/src/wallet/mod.rs b/crates/core/src/wallet/mod.rs index ffee80d..0039ba2 100644 --- a/crates/core/src/wallet/mod.rs +++ b/crates/core/src/wallet/mod.rs @@ -304,6 +304,20 @@ where } } + pub async fn close_wallet( + wallet_interface: Arc>>, + ) -> Result<(), GrinWalletInterfaceError> { + let mut w = wallet_interface.write().unwrap(); + if let Some(o) = &w.owner_api { + // ignoring secret key + o.close_wallet(None); + w.wallet_is_open = false; + return Ok(()); + } else { + return Err(GrinWalletInterfaceError::OwnerAPINotInstantiated); + } + } + pub fn get_wallet_updater_status( wallet_interface: Arc>>, ) -> Result, GrinWalletInterfaceError> { diff --git a/src/gui/element/wallet/operation/home.rs b/src/gui/element/wallet/operation/home.rs index b720970..e4773c2 100644 --- a/src/gui/element/wallet/operation/home.rs +++ b/src/gui/element/wallet/operation/home.rs @@ -28,11 +28,13 @@ use { }; pub struct StateContainer { + pub back_button_state: button::State, + pub expanded_type: ExpandType, + wallet_info: Option, wallet_txs: TxList, wallet_status: String, txs_scrollable_state: scrollable::State, - pub expanded_type: ExpandType, last_summary_update: chrono::DateTime, tx_header_state: HeaderState, } @@ -40,11 +42,12 @@ pub struct StateContainer { impl Default for StateContainer { fn default() -> Self { Self { + back_button_state: Default::default(), + expanded_type: ExpandType::None, wallet_info: Default::default(), wallet_txs: Default::default(), wallet_status: Default::default(), txs_scrollable_state: Default::default(), - expanded_type: ExpandType::None, last_summary_update: Default::default(), tx_header_state: Default::default(), } @@ -53,6 +56,7 @@ impl Default for StateContainer { #[derive(Debug, Clone)] pub enum LocalViewInteraction { + Back, Submit, /// was updated from node, info WalletInfoUpdateSuccess(bool, WalletInfo, Vec), @@ -126,6 +130,14 @@ pub fn handle_message<'a>( ) -> Result> { let state = &mut grin_gui.wallet_state.operation_state.home_state; match message { + LocalViewInteraction::Back => { + // TODO implement close wallet and handle close errors + let wallet_interface = grin_gui.wallet_interface.clone(); + WalletInterface::close_wallet(wallet_interface); + + grin_gui.wallet_state.operation_state.mode = + crate::gui::element::wallet::operation::Mode::Open; + } LocalViewInteraction::Submit => {} LocalViewInteraction::WalletInfoUpdateSuccess(node_success, wallet_info, txs) => { debug!( @@ -159,8 +171,24 @@ pub fn data_container<'a>( let title_container = Container::new(title).style(style::BrightBackgroundContainer(color_palette)); + let back_button_label_container = + Container::new(Text::new(localized_string("back")).size(DEFAULT_FONT_SIZE)) + .height(Length::Units(20)) + .align_y(alignment::Vertical::Bottom) + .align_x(alignment::Horizontal::Center); + + let back_button: Element = + Button::new(&mut state.back_button_state, back_button_label_container) + .style(style::NormalTextButton(color_palette)) + .on_press(Interaction::WalletOperationHomeViewInteraction( + LocalViewInteraction::Back, + )) + .into(); + let title_row = Row::new() .push(title_container) + .push(Space::new(Length::Units(100), Length::Units(0))) + .push(back_button.map(Message::Interaction)) .align_items(Alignment::Center) .padding(6) .spacing(20);