Skip to content

Commit

Permalink
complete wallet import operation
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Mar 6, 2024
1 parent 891c85c commit d4661d4
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 16 deletions.
1 change: 1 addition & 0 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"setup-grin-passwords-dont-match": "Passwords do not match",
"setup-grin-passwords-okay": "Password okay",
"setup-grin-wallet-success": "Wallet Created!",
"import-grin-wallet-success": "Wallet Imported!",
"setup-grin-wallet-done": "Done",
"setup-grin-wallet-recovery-phrase-title": "Recovery phrase",
"setup-grin-wallet-recovery-phrase": "Your wallet recovery phrase is shown below.\n\nStore these words in a non-digital format and be sure to keep them safe.",
Expand Down
1 change: 1 addition & 0 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"setup-grin-passwords-dont-match": "Passwords do not match",
"setup-grin-passwords-okay": "Password okay",
"setup-grin-wallet-success": "Wallet Created",
"import-grin-wallet-success": "Wallet Imported!",
"setup-grin-wallet-done": "Done",
"setup-grin-wallet-recovery-phrase-title": "Recovery phrase",
"setup-grin-wallet-recovery-phrase": "Your wallet recovery phrase is shown below.\nStore these words in a non-digital format and be sure to keep them safe.",
Expand Down
7 changes: 7 additions & 0 deletions src/gui/element/wallet/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod init;
pub mod wallet_import;
pub mod wallet_import_success;
pub mod wallet_list;
pub mod wallet_setup;
pub mod wallet_success;
Expand All @@ -22,6 +23,7 @@ pub struct StateContainer {
pub setup_wallet_state: wallet_setup::StateContainer,
pub import_wallet_state: wallet_import::StateContainer,
pub setup_wallet_success_state: wallet_success::StateContainer,
pub import_wallet_success_state: wallet_import_success::StateContainer,
pub setup_wallet_list_state: wallet_list::StateContainer,
}

Expand All @@ -31,6 +33,7 @@ pub enum Mode {
CreateWallet(String),
ListWallets,
WalletCreateSuccess,
WalletImportSuccess,
}

impl Default for StateContainer {
Expand All @@ -41,6 +44,7 @@ impl Default for StateContainer {
setup_wallet_state: Default::default(),
import_wallet_state: Default::default(),
setup_wallet_success_state: Default::default(),
import_wallet_success_state: Default::default(),
setup_wallet_list_state: Default::default(),
}
}
Expand All @@ -65,6 +69,9 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain
Mode::WalletCreateSuccess => {
wallet_success::data_container(&state.setup_wallet_success_state)
}
Mode::WalletImportSuccess => {
wallet_import_success::data_container(&state.import_wallet_success_state)
}
Mode::ListWallets => wallet_list::data_container(&state.setup_wallet_list_state, config),
};

Expand Down
44 changes: 28 additions & 16 deletions src/gui/element/wallet/setup/wallet_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum LocalViewInteraction {
PasswordInputEnterPressed,
DisplayName(String),
ImportWallet(String, PathBuf),
WalletImportedOk(GlobalWalletConfig),
WalletImportedOk(String, GlobalWalletConfig),
WalletImportError(Arc<RwLock<Option<anyhow::Error>>>),
}

Expand Down Expand Up @@ -139,14 +139,14 @@ pub fn handle_message<'a>(
)));
}
let global_config = wallet::get_wallet_config(fut_path.to_str().unwrap())?;
Ok(global_config)
Ok((fut_display_name, global_config))
};

return Ok(Command::perform(fut(), |r| {
match r.context("Failed to Import Wallet") {
Ok(ret) => {
Ok((display_name, config)) => {
Message::Interaction(Interaction::WalletSetupImportWalletViewInteraction(
LocalViewInteraction::WalletImportedOk(ret),
LocalViewInteraction::WalletImportedOk(display_name, config),
))
}
Err(e) => {
Expand All @@ -157,32 +157,44 @@ pub fn handle_message<'a>(
}
}));
}
LocalViewInteraction::WalletImportedOk(wallet_config) => {
debug!("Global config: {:?}", wallet_config);
/*let tld = Some(PathBuf::from(&tld));
let saved_wallet = Wallet::new(tld, display_name, chain_type);
LocalViewInteraction::WalletImportedOk(display_name, global_wallet_config) => {
//debug!("Global config: {:?}", wallet_config);
let wallet_config = global_wallet_config
.members
.as_ref()
.unwrap()
.wallet
.clone();
let chain_type = wallet_config.chain_type.unwrap_or_default();
let mut tld = PathBuf::from(wallet_config.data_file_dir);
tld.pop();
let tld = Some(tld);
let saved_wallet = Wallet::new(tld, display_name.clone(), chain_type);

let index = grin_gui.config.add_wallet(saved_wallet);
grin_gui.config.current_wallet_index = Some(index);
grin_gui.wallet_state.clear_config_missing();
grin_gui
.wallet_state
.setup_state
.setup_wallet_success_state
.recovery_phrase = mnemonic;

/*grin_gui
.wallet_state
.setup_state
.setup_wallet_success_state
.recovery_phrase = mnemonic;*/

// reset user input values
grin_gui.wallet_state.setup_state.setup_wallet_state = Default::default();
grin_gui.wallet_state.setup_state.import_wallet_state = Default::default();

let _ = grin_gui.config.save();

debug!("Wallet config imported successfully: {}", display_name);

grin_gui.wallet_state.setup_state.mode =
crate::gui::element::wallet::setup::Mode::WalletCreateSuccess;
crate::gui::element::wallet::setup::Mode::WalletImportSuccess;

if grin_gui.wallet_state.mode != element::wallet::Mode::Init {
// set init state
grin_gui.wallet_state.mode = element::wallet::Mode::Init;
}*/
}
}
LocalViewInteraction::WalletImportError(err) => {
grin_gui.error = err.write().unwrap().take();
Expand Down
90 changes: 90 additions & 0 deletions src/gui/element/wallet/setup/wallet_import_success.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use {
super::super::super::{DEFAULT_FONT_SIZE, DEFAULT_HEADER_FONT_SIZE, SMALLER_FONT_SIZE},
crate::gui::{GrinGui, Interaction, Message},
crate::localization::localized_string,
crate::Result,
grin_gui_core::theme::ColorPalette,
grin_gui_core::theme::{
Column, Container, Element, PickList, Row, Scrollable, Text, TextInput,
},
iced::widget::{button, pick_list, scrollable, text_input, Button, Checkbox, Space},
iced::{alignment, Alignment, Command, Length},
iced_aw::Card,
};

pub struct StateContainer {}

impl Default for StateContainer {
fn default() -> Self {
Self {}
}
}

#[derive(Debug, Clone)]
pub enum LocalViewInteraction {
Submit,
}

pub fn handle_message(
grin_gui: &mut GrinGui,
message: LocalViewInteraction,
) -> Result<Command<Message>> {
let state = &mut grin_gui.wallet_state.setup_state.import_wallet_state;
match message {
LocalViewInteraction::Submit => {
debug!("Wallet import success view submit");
grin_gui.wallet_state.mode = super::super::Mode::Operation;
grin_gui.wallet_state.setup_state.mode = crate::gui::element::wallet::setup::Mode::Init;
}
}
Ok(Command::none())
}

pub fn data_container<'a>(state: &'a StateContainer) -> Container<'a, Message> {
// Title row
let title = Text::new(localized_string("import-grin-wallet-success"))
.size(DEFAULT_HEADER_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Left);

let title_container =
Container::new(title).style(grin_gui_core::theme::ContainerStyle::NormalBackground);

let title_row = Row::new()
.push(title_container)
.align_items(Alignment::Center)
.spacing(20);

let submit_button_label_container = Container::new(
Text::new(localized_string("setup-grin-wallet-done")).size(DEFAULT_FONT_SIZE),
)
.center_x()
.align_x(alignment::Horizontal::Center);

let next_button = Button::new(submit_button_label_container)
.style(grin_gui_core::theme::ButtonStyle::Bordered)
.on_press(Interaction::WalletImportWalletSuccessViewInteraction(
LocalViewInteraction::Submit,
));

let next_button: Element<Interaction> = next_button.into();

let unit_spacing = 15.0;

let colum = Column::new()
.push(Space::new(
Length::Fixed(0.0),
Length::Fixed(unit_spacing + 5.0),
))
.push(title_row)
.push(Space::new(
Length::Fixed(0.0),
Length::Fixed(unit_spacing + 5.0),
))
.push(next_button.map(Message::Interaction))
.align_items(Alignment::Center);

Container::new(colum)
.center_y()
.center_x()
.width(Length::Fill)
}
3 changes: 3 additions & 0 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ pub enum Interaction {
WalletSetupWalletSuccessViewInteraction(
element::wallet::setup::wallet_success::LocalViewInteraction,
),
WalletImportWalletSuccessViewInteraction(
element::wallet::setup::wallet_import_success::LocalViewInteraction,
),
WalletOperationOpenViewInteraction(element::wallet::operation::open::LocalViewInteraction),
WalletOperationHomeViewInteraction(element::wallet::operation::home::LocalViewInteraction),
WalletOperationTxListInteraction(element::wallet::operation::tx_list::LocalViewInteraction),
Expand Down
4 changes: 4 additions & 0 deletions src/gui/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pub fn handle_message(grin_gui: &mut GrinGui, message: Message) -> Result<Comman
Message::Interaction(Interaction::WalletSetupWalletSuccessViewInteraction(l)) => {
return element::wallet::setup::wallet_success::handle_message(grin_gui, l);
}
// Import -> Wallet Success Settings
Message::Interaction(Interaction::WalletImportWalletSuccessViewInteraction(l)) => {
return element::wallet::setup::wallet_import_success::handle_message(grin_gui, l);
}
// Wallet -> Operation -> Open Settings
Message::Interaction(Interaction::WalletOperationOpenViewInteraction(l)) => {
return element::wallet::operation::open::handle_message(grin_gui, l);
Expand Down

0 comments on commit d4661d4

Please sign in to comment.