Skip to content

Commit bcaa28b

Browse files
author
pythcoiner
committed
add back button into installer first step
1 parent 7801fc7 commit bcaa28b

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

gui/src/installer/message.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub enum Message {
3939
WalletRegistered(Result<(Fingerprint, Option<[u8; 32]>), Error>),
4040
MnemonicWord(usize, String),
4141
ImportMnemonic(bool),
42+
Back(PathBuf),
4243
}
4344

4445
#[derive(Debug, Clone)]

gui/src/installer/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Installer {
3333
steps: Vec<Box<dyn Step>>,
3434
hws: HardwareWallets,
3535
signer: Arc<Mutex<Signer>>,
36+
back_button: bool,
3637

3738
/// Context is data passed through each step.
3839
context: Context,
@@ -58,14 +59,21 @@ impl Installer {
5859
pub fn new(
5960
destination_path: PathBuf,
6061
network: bitcoin::Network,
62+
back_button: bool,
6163
) -> (Installer, Command<Message>) {
64+
let path = if back_button {
65+
Some(destination_path.clone())
66+
} else {
67+
None
68+
};
6269
(
6370
Installer {
6471
current: 0,
6572
hws: HardwareWallets::new(destination_path.clone(), network),
66-
steps: vec![Welcome::default().into()],
73+
steps: vec![Welcome::new(path).into()],
6774
context: Context::new(network, destination_path),
6875
signer: Arc::new(Mutex::new(Signer::generate(network).unwrap())),
76+
back_button,
6977
},
7078
Command::none(),
7179
)
@@ -134,10 +142,15 @@ impl Installer {
134142
}
135143

136144
pub fn update(&mut self, message: Message) -> Command<Message> {
145+
let path = if self.back_button {
146+
Some(self.context.data_dir.clone())
147+
} else {
148+
None
149+
};
137150
match message {
138151
Message::CreateWallet => {
139152
self.steps = vec![
140-
Welcome::default().into(),
153+
Welcome::new(path).into(),
141154
DefineDescriptor::new(self.signer.clone()).into(),
142155
BackupMnemonic::new(self.signer.clone()).into(),
143156
BackupDescriptor::default().into(),
@@ -151,7 +164,7 @@ impl Installer {
151164
}
152165
Message::ParticipateWallet => {
153166
self.steps = vec![
154-
Welcome::default().into(),
167+
Welcome::new(path).into(),
155168
ParticipateXpub::new(self.signer.clone()).into(),
156169
ImportDescriptor::new(false).into(),
157170
BackupMnemonic::new(self.signer.clone()).into(),
@@ -166,7 +179,7 @@ impl Installer {
166179
}
167180
Message::ImportWallet => {
168181
self.steps = vec![
169-
Welcome::default().into(),
182+
Welcome::new(path).into(),
170183
ImportDescriptor::new(true).into(),
171184
RecoverMnemonic::default().into(),
172185
RegisterDescriptor::new_import_wallet().into(),

gui/src/installer/step/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ pub trait Step {
5252
}
5353

5454
#[derive(Default)]
55-
pub struct Welcome {}
55+
pub struct Welcome {
56+
path: Option<PathBuf>,
57+
}
58+
59+
impl Welcome {
60+
pub fn new(path: Option<PathBuf>) -> Self {
61+
Welcome { path }
62+
}
63+
}
5664

5765
impl Step for Welcome {
5866
fn view(&self, _hws: &HardwareWallets, _progress: (usize, usize)) -> Element<Message> {
59-
view::welcome()
67+
view::welcome(&self.path)
6068
}
6169
}
6270

gui/src/installer/view.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const NETWORKS: [Network; 4] = [
8181
Network::Regtest,
8282
];
8383

84-
pub fn welcome<'a>() -> Element<'a, Message> {
84+
pub fn welcome<'a>(path: &Option<PathBuf>) -> Element<'a, Message> {
8585
Container::new(
8686
Column::new()
8787
.push(
@@ -90,6 +90,15 @@ pub fn welcome<'a>() -> Element<'a, Message> {
9090
.push(
9191
Container::new(
9292
Column::new()
93+
.push_maybe(path.as_ref().map(|p| {
94+
Row::new()
95+
.push(Space::with_width(Length::Fixed(30.0)))
96+
.push(Container::new(
97+
button::secondary(None, " Back ")
98+
.on_press(Message::Back(p.clone())),
99+
))
100+
.push(Space::with_width(Length::Fill))
101+
}))
93102
.push(
94103
Row::new()
95104
.align_items(Alignment::End)

gui/src/main.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Application for GUI {
137137
datadir_path.clone(),
138138
log_level.unwrap_or(LevelFilter::INFO),
139139
);
140-
let (install, command) = Installer::new(datadir_path, network);
140+
let (install, command) = Installer::new(datadir_path, network, false);
141141
(
142142
Self {
143143
state: State::Installer(Box::new(install)),
@@ -196,7 +196,7 @@ impl Application for GUI {
196196
self.log_level.unwrap_or(LevelFilter::INFO),
197197
);
198198
let (install, command) =
199-
Installer::new(datadir_path, bitcoin::Network::Bitcoin);
199+
Installer::new(datadir_path, bitcoin::Network::Bitcoin, true);
200200
self.state = State::Installer(Box::new(install));
201201
command.map(|msg| Message::Install(Box::new(msg)))
202202
}
@@ -213,8 +213,8 @@ impl Application for GUI {
213213
}
214214
_ => l.update(*msg).map(|msg| Message::Launch(Box::new(msg))),
215215
},
216-
(State::Installer(i), Message::Install(msg)) => {
217-
if let installer::Message::Exit(path, internal_bitcoind) = *msg {
216+
(State::Installer(i), Message::Install(msg)) => match *msg {
217+
installer::Message::Exit(path, internal_bitcoind) => {
218218
let cfg = app::Config::from_file(&path).unwrap();
219219
let daemon_cfg =
220220
DaemonConfig::from_file(cfg.daemon_config_path.clone()).unwrap();
@@ -239,10 +239,13 @@ impl Application for GUI {
239239
);
240240
self.state = State::Loader(Box::new(loader));
241241
command.map(|msg| Message::Load(Box::new(msg)))
242-
} else {
243-
i.update(*msg).map(|msg| Message::Install(Box::new(msg)))
244242
}
245-
}
243+
installer::Message::Back(path) => {
244+
self.state = State::Launcher(Box::new(Launcher::new(path)));
245+
Command::none()
246+
}
247+
_ => i.update(*msg).map(|msg| Message::Install(Box::new(msg))),
248+
},
246249
(State::Loader(loader), Message::Load(msg)) => match *msg {
247250
loader::Message::View(loader::ViewMessage::SwitchNetwork) => {
248251
self.state =

0 commit comments

Comments
 (0)