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

[WIP] Restore seed word functionnality #5

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ strfmt = "0.1.6"
once_cell = "1.6.0"
lazy_static = "1"
serde = { version = "1.0", features=['derive'] }
regex = "1.6.0"

[target.'cfg(target_os = "linux")'.dependencies]
native-dialog = "0.5.5"
Expand Down
25 changes: 23 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ built = { version = "0.4", features = ["git2"]}

[dependencies]

############ Release ################


############ Master ################
### Node
grin_config = { git = "https://github.com/mimblewimble/grin", branch = "master" }
grin_core = { git = "https://github.com/mimblewimble/grin", branch = "master" }
Expand All @@ -28,7 +30,7 @@ grin_servers = { git = "https://github.com/mimblewimble/grin", branch = "master"
grin_keychain = { git = "https://github.com/mimblewimble/grin", branch = "master" }
grin_chain = { git = "https://github.com/mimblewimble/grin", branch = "master" }

### Wallet
#### Wallet
grin_wallet = { git = "https://github.com/mimblewimble/grin-wallet", branch = "master" }
grin_wallet_config = { git = "https://github.com/mimblewimble/grin-wallet", branch = "master" }
grin_wallet_util = { git = "https://github.com/mimblewimble/grin-wallet", branch = "master" }
Expand All @@ -38,6 +40,25 @@ grin_wallet_impls = { git = "https://github.com/mimblewimble/grin-wallet", branc
grin_wallet_libwallet = { git = "https://github.com/mimblewimble/grin-wallet", branch = "master" }


############ Release ################
### Node
#grin_config = { git = "https://github.com/mimblewimble/grin", tag = "v5.1.2" }
#grin_core = { git = "https://github.com/mimblewimble/grin", tag = "v5.1.2" }
#grin_util = { git = "https://github.com/mimblewimble/grin", tag = "v5.1.2" }
#grin_servers = { git = "https://github.com/mimblewimble/grin", tag = "v5.1.2" }
#grin_keychain = { git = "https://github.com/mimblewimble/grin", tag = "v5.1.2" }
#grin_chain = { git = "https://github.com/mimblewimble/grin", tag = "v5.1.2" }

##### Wallet
#grin_wallet = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0" }
#grin_wallet_config = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0" }
#grin_wallet_util = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0" }
#grin_wallet_controller = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0"}
#grin_wallet_api = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0" }
#grin_wallet_impls = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0"}
#grin_wallet_libwallet = { git = "https://github.com/mimblewimble/grin-wallet", tag = "v5.1.0" }



############ Local testing ################
### Node
Expand Down
25 changes: 22 additions & 3 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,37 @@ where
Ok(())
}

pub fn validate_mnemonic(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
mmemonic: String,
) -> Result<(), GrinWalletInterfaceError> {

WalletInterface::inst_owner_api(wallet_interface.clone())?;
let w = wallet_interface.read().unwrap();

match w.owner_api.as_ref() {
Some(o) => {
let mut w_lock = o.wallet_inst.lock();
let p = w_lock.lc_provider()?;
let is_valid = p.validate_mnemonic(mmemonic.into()).map_err(|_| GrinWalletInterfaceError::OwnerAPINotInstantiated);
return is_valid
}
None => return Err(GrinWalletInterfaceError::OwnerAPINotInstantiated),
};
}

pub async fn init(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
password: String,
top_level_directory:PathBuf,
display_name:String
display_name:String,
list_length: usize
) -> Result<(String, String, String), GrinWalletInterfaceError> {
WalletInterface::inst_owner_api(wallet_interface.clone())?;

let w = wallet_interface.read().unwrap();

let args = InitArgs {
list_length: 32,
list_length: list_length,
password: "".into(),
config: w.config.clone().unwrap().clone().members.unwrap().wallet,
recovery_phrase: None,
Expand Down
5 changes: 3 additions & 2 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@
"remote": "Latest version",
"remote-release-channel": "Release channel",
"reset-columns": "Reset Columns",
"restore-from-seed": "Restore this wallet from an existing seed phrase (TBD)",
"restore-from-seed": "Restore from seed",
"input-seed-btn": "Input seed word",
"retry": "Retry",
"scale": "Scale",
"search-for-addon": "Search for an addon...",
"select-account": "Select an Account",
"select-wallet-toml": "Select an Existing Wallet",
"select-wallet-toml": "Select Wallet File",
"settings": "Settings",
"setup-grin-autogenerate-wallet": "Create a New Wallet",
"setup-grin-wallet-description": "To get started, you can either:",
Expand Down
65 changes: 51 additions & 14 deletions src/gui/element/wallet/setup/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use {
Space, Text,
},
};

#[derive(Debug)]
pub struct StateContainer {
pub setup_wallet_defaults_is_selected: bool,
create_default_wallet_btn: button::State,
restore_from_seed_btn: button::State,
select_wallet_toml_btn: button::State,
execute_btn: button::State,
}
Expand All @@ -23,6 +24,7 @@ impl Default for StateContainer {
Self {
setup_wallet_defaults_is_selected: true,
create_default_wallet_btn: Default::default(),
restore_from_seed_btn: Default::default(),
select_wallet_toml_btn: Default::default(),
execute_btn: Default::default(),
}
Expand All @@ -31,7 +33,8 @@ impl Default for StateContainer {

#[derive(Debug, Clone)]
pub enum LocalViewInteraction {
WalletSetup,
WalletSetupCreate,
WalletSetupRestore,
WalletList,
}

Expand All @@ -41,7 +44,14 @@ pub fn handle_message(
) -> Result<Command<Message>> {
let state = &mut grin_gui.wallet_state.setup_state;
match message {
LocalViewInteraction::WalletSetup => state.mode = super::Mode::CreateWallet,
LocalViewInteraction::WalletSetupCreate => {
state.setup_wallet_state.restore_from_seed = false;
state.mode = super::Mode::CreateWallet
}
LocalViewInteraction::WalletSetupRestore => {
state.setup_wallet_state.restore_from_seed = true;
state.mode = super::Mode::RestoreWallet
}
LocalViewInteraction::WalletList => state.mode = super::Mode::ListWallets
}
Ok(Command::none())
Expand Down Expand Up @@ -72,16 +82,18 @@ pub fn data_container<'a>(
.horizontal_alignment(alignment::Horizontal::Left);
let description_container =
Container::new(description).style(style::NormalBackgroundContainer(color_palette));

let or_text = Text::new(localized_string("or-caps"))
.size(DEFAULT_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Center);

let or_text_container =
Container::new(or_text).style(style::NormalBackgroundContainer(color_palette));

/* Create new wallet */

let create_default_wallet_button_label_container = Container::new(
Text::new(localized_string("setup-grin-autogenerate-wallet")).size(DEFAULT_FONT_SIZE),
Text::new(localized_string("setup-grin-autogenerate-wallet")).size(18),
)
.center_x()
.align_x(alignment::Horizontal::Center);
Expand All @@ -92,10 +104,30 @@ pub fn data_container<'a>(
)
.style(style::DefaultBoxedButton(color_palette))
.on_press(Interaction::WalletSetupInitViewInteraction(
LocalViewInteraction::WalletSetup,
LocalViewInteraction::WalletSetupCreate,
))
.into();

/* Restore from seed */

let restore_from_seed_button_label_container = Container::new(
Text::new(localized_string("restore-from-seed")).size(DEFAULT_FONT_SIZE),
)
.center_x()
.align_x(alignment::Horizontal::Center);

let restore_from_seed_button: Element<Interaction> = Button::new(
&mut state.restore_from_seed_btn,
restore_from_seed_button_label_container,
)
.style(style::DefaultBoxedButton(color_palette))
.on_press(Interaction::WalletSetupInitViewInteraction(
LocalViewInteraction::WalletSetupRestore,
))
.into();

/* Select from file */

let select_wallet_button_label_container =
Container::new(Text::new(localized_string("select-wallet-toml")).size(DEFAULT_FONT_SIZE))
.center_x()
Expand Down Expand Up @@ -134,13 +166,11 @@ pub fn data_container<'a>(
Column::new().push(checkbox_container)
};*/

let unit_spacing = 15;
let unit_spacing = 20;

let select_column = Column::new()
.push(create_default_wallet_button.map(Message::Interaction))
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(or_text_container)
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
let select_row = Row::new()
.push(restore_from_seed_button.map(Message::Interaction))
.push(Space::new(Length::Units(unit_spacing), Length::Units(0)))
.push(select_wallet_button_container)
.align_items(Alignment::Center);

Expand All @@ -149,11 +179,18 @@ pub fn data_container<'a>(
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(description_container)
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(select_column)
.push(create_default_wallet_button.map(Message::Interaction))
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(or_text_container)
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(select_row)
.align_items(Alignment::Center);



Container::new(colum)
.center_y()
.center_x()
.width(Length::Fill)
}
.height(Length::Fill)
}
Loading