Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bug fixes #13

Merged
merged 4 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 34 additions & 5 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -289,6 +304,20 @@ where
}
}

pub async fn close_wallet(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
) -> 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<RwLock<WalletInterface<L, C>>>,
) -> Result<Vec<StatusMessage>, GrinWalletInterfaceError> {
Expand Down
32 changes: 30 additions & 2 deletions src/gui/element/wallet/operation/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,26 @@ use {
};

pub struct StateContainer {
pub back_button_state: button::State,
pub expanded_type: ExpandType,

wallet_info: Option<WalletInfo>,
wallet_txs: TxList,
wallet_status: String,
txs_scrollable_state: scrollable::State,
pub expanded_type: ExpandType,
last_summary_update: chrono::DateTime<chrono::Local>,
tx_header_state: HeaderState,
}

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(),
}
Expand All @@ -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<TxLogEntry>),
Expand Down Expand Up @@ -126,6 +130,14 @@ pub fn handle_message<'a>(
) -> Result<Command<Message>> {
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!(
Expand Down Expand Up @@ -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<Interaction> =
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);
Expand Down
8 changes: 8 additions & 0 deletions src/gui/element/wallet/setup/wallet_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/element/wallet/setup/wallet_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
))),
),
)
Expand Down