Skip to content

Commit

Permalink
ledger upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pythcoiner committed Aug 20, 2024
1 parent 9525838 commit e88dbac
Show file tree
Hide file tree
Showing 22 changed files with 2,527 additions and 1,312 deletions.
2,341 changes: 1,278 additions & 1,063 deletions gui/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bitcoin_hashes = "0.12"
reqwest = { version = "0.11", default-features=false, features = ["json", "rustls-tls"] }
rust-ini = "0.19.0"

ledger_manager = { git = "https://github.com/pythcoiner/ledger_installer.git", branch = "liana", ref = "afcc0e5db74488191b5d9b3f28eaad8717772c58"}

[patch.crates-io]
iced_style = { git = "https://github.com/edouardparis/iced", branch = "patch-0.12.3"}
Expand Down
1 change: 1 addition & 0 deletions gui/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"auth_api_url":"https://sjlrfowlmlxhvcdiqjnz.supabase.co","auth_api_public_key":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNqbHJmb3dsbWx4aHZjZGlxam56Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTAxOTkwMDIsImV4cCI6MjAwNTc3NTAwMn0.IyvRA51UG6dqe94IDAlsPPtm9hc03o7N4t5JTUuu40I","backend_api_url":"https://liana-sandbox.cleverapps.io"}
1 change: 1 addition & 0 deletions gui/src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ pub enum Message {
LabelsUpdated(Result<HashMap<String, Option<String>>, Error>),
BroadcastModal(Result<HashSet<Txid>, Error>),
RbfModal(Box<HistoryTransaction>, bool, Result<HashSet<Txid>, Error>),
LockModal(bool),
}
38 changes: 35 additions & 3 deletions gui/src/app/state/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use liana_ui::{
widget::Element,
};

use crate::hw::{hw_subscriptions, HardwareWalletMessage};
use crate::{
app::{
cache::Cache,
Expand Down Expand Up @@ -410,6 +411,7 @@ pub struct SignAction {
signed: HashSet<Fingerprint>,
is_saved: bool,
display_modal: bool,
upgrading: bool,
}

impl SignAction {
Expand All @@ -428,13 +430,15 @@ impl SignAction {
signed,
is_saved,
display_modal: true,
upgrading: false,
}
}
}

impl Action for SignAction {
fn subscription(&self) -> Subscription<Message> {
self.hws.refresh().map(Message::HardwareWallets)
hw_subscriptions(&self.hws, Some(self.wallet.main_descriptor.is_taproot()))
.map(Message::HardwareWallets)
}

fn update(
Expand Down Expand Up @@ -512,7 +516,20 @@ impl Action for SignAction {
},
Err(e) => self.error = Some(e),
},

Message::HardwareWallets(HardwareWalletMessage::LockModal(upgrading)) => {
self.upgrading = upgrading
}
Message::View(view::Message::UpgradeLedger(id, network)) => {
match self
.hws
.update(HardwareWalletMessage::UpgradeLedger(id, network))
{
Ok(cmd) => return cmd.map(Message::HardwareWallets),
Err(e) => {
self.error = Some(e.into());
}
}
}
Message::HardwareWallets(msg) => match self.hws.update(msg) {
Ok(cmd) => {
return cmd.map(Message::HardwareWallets);
Expand All @@ -526,6 +543,15 @@ impl Action for SignAction {
Command::none()
}
fn view<'a>(&'a self, content: Element<'a, view::Message>) -> Element<'a, view::Message> {
let network = if self
.wallet
.main_descriptor
.all_xpubs_net_is(Network::Bitcoin)
{
Network::Bitcoin
} else {
Network::Testnet
};
let content = toast::Manager::new(
content,
view::psbt::sign_action_toasts(self.error.as_ref(), &self.hws.list, &self.signing),
Expand All @@ -544,9 +570,15 @@ impl Action for SignAction {
.and_then(|signer| self.wallet.keys_aliases.get(&signer.fingerprint)),
&self.signed,
&self.signing,
self.upgrading,
network,
),
)
.on_blur(Some(view::Message::Spend(view::SpendTxMessage::Cancel)))
.on_blur(if !self.upgrading {
Some(view::Message::Spend(view::SpendTxMessage::Cancel))
} else {
None
})
.into()
} else {
content
Expand Down
43 changes: 36 additions & 7 deletions gui/src/app/state/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use liana::miniscript::bitcoin::{
};
use liana_ui::{component::modal, widget::*};

use crate::hw::{hw_subscriptions, HardwareWalletMessage};
use crate::{
app::{
cache::Cache,
Expand All @@ -19,14 +20,13 @@ use crate::{
view,
wallet::Wallet,
},
daemon::{
model::{LabelItem, Labelled},
Daemon,
},
hw::{HardwareWallet, HardwareWallets},
};

use crate::daemon::{
model::{LabelItem, Labelled},
Daemon,
};

pub enum Modal {
VerifyAddress(VerifyAddressModal),
ShowQrCode(ShowQrCodeModal),
Expand Down Expand Up @@ -89,7 +89,11 @@ impl State for ReceivePanel {

match &self.modal {
Modal::VerifyAddress(m) => modal::Modal::new(content, m.view())
.on_blur(Some(view::Message::Close))
.on_blur(if !m.upgrading {
Some(view::Message::Close)
} else {
None
})
.into(),
Modal::ShowQrCode(m) => modal::Modal::new(content, m.view())
.on_blur(Some(view::Message::Close))
Expand Down Expand Up @@ -152,6 +156,7 @@ impl State for ReceivePanel {
.derivation_indexes
.get(i)
.expect("Must be present"),
self.wallet.main_descriptor.is_taproot(),
));
Command::none()
}
Expand Down Expand Up @@ -222,6 +227,8 @@ pub struct VerifyAddressModal {
hws: HardwareWallets,
address: Address,
derivation_index: ChildNumber,
taproot: bool,
pub upgrading: bool,
}

impl VerifyAddressModal {
Expand All @@ -231,30 +238,36 @@ impl VerifyAddressModal {
network: Network,
address: Address,
derivation_index: ChildNumber,
taproot: bool,
) -> Self {
Self {
warning: None,
chosen_hws: HashSet::new(),
hws: HardwareWallets::new(data_dir, network).with_wallet(wallet),
address,
derivation_index,
taproot,
upgrading: false,
}
}
}

impl VerifyAddressModal {
fn view(&self) -> Element<view::Message> {
let network = self.address.network();
view::receive::verify_address_modal(
self.warning.as_ref(),
&self.hws.list,
&self.chosen_hws,
&self.address,
&self.derivation_index,
self.upgrading,
*network,
)
}

fn subscription(&self) -> Subscription<Message> {
self.hws.refresh().map(Message::HardwareWallets)
hw_subscriptions(&self.hws, Some(self.taproot)).map(Message::HardwareWallets)
}

fn update(
Expand All @@ -264,6 +277,22 @@ impl VerifyAddressModal {
message: Message,
) -> Command<Message> {
match message {
Message::HardwareWallets(HardwareWalletMessage::LockModal(upgrading)) => {
self.upgrading = upgrading;
Command::none()
}
Message::View(view::Message::UpgradeLedger(id, network)) => {
match self
.hws
.update(HardwareWalletMessage::UpgradeLedger(id, network))
{
Ok(cmd) => cmd.map(Message::HardwareWallets),
Err(e) => {
self.warning = Some(e.into());
Command::none()
}
}
}
Message::HardwareWallets(msg) => match self.hws.update(msg) {
Ok(cmd) => cmd.map(Message::HardwareWallets),
Err(e) => {
Expand Down
44 changes: 41 additions & 3 deletions gui/src/app/state/settings/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use crate::{
cache::Cache, error::Error, message::Message, settings, state::State, view, wallet::Wallet,
},
daemon::{Daemon, DaemonBackend},
hw::{HardwareWallet, HardwareWalletConfig, HardwareWallets},
hw::{
hw_subscriptions, HardwareWallet, HardwareWalletConfig, HardwareWalletMessage,
HardwareWallets,
},
};

pub struct WalletSettingsState {
Expand Down Expand Up @@ -84,7 +87,11 @@ impl State for WalletSettingsState {
);
if let Some(m) = &self.modal {
modal::Modal::new(content, m.view())
.on_blur(Some(view::Message::Close))
.on_blur(if !m.upgrading {
Some(view::Message::Close)
} else {
None
})
.into()
} else {
content
Expand Down Expand Up @@ -201,6 +208,7 @@ pub struct RegisterWalletModal {
hws: HardwareWallets,
registered: HashSet<Fingerprint>,
processing: bool,
pub upgrading: bool,
}

impl RegisterWalletModal {
Expand All @@ -217,23 +225,37 @@ impl RegisterWalletModal {
wallet,
processing: false,
registered,
upgrading: false,
}
}
}

impl RegisterWalletModal {
fn view(&self) -> Element<view::Message> {
let upgrading = self.hws.list.iter().any(|hw| hw.is_upgrade_in_progress());
let network = if self
.wallet
.main_descriptor
.all_xpubs_net_is(Network::Bitcoin)
{
Network::Bitcoin
} else {
Network::Testnet
};
view::settings::register_wallet_modal(
self.warning.as_ref(),
&self.hws.list,
self.processing,
self.chosen_hw,
&self.registered,
upgrading,
network,
)
}

fn subscription(&self) -> Subscription<Message> {
self.hws.refresh().map(Message::HardwareWallets)
hw_subscriptions(&self.hws, Some(self.wallet.main_descriptor.is_taproot()))
.map(Message::HardwareWallets)
}

fn update(
Expand All @@ -248,6 +270,22 @@ impl RegisterWalletModal {
self.warning = None;
Command::none()
}
Message::HardwareWallets(HardwareWalletMessage::LockModal(upgrading)) => {
self.upgrading = upgrading;
Command::none()
}
Message::View(view::Message::UpgradeLedger(id, network)) => {
match self
.hws
.update(HardwareWalletMessage::UpgradeLedger(id, network))
{
Ok(cmd) => cmd.map(Message::HardwareWallets),
Err(e) => {
self.warning = Some(e.into());
Command::none()
}
}
}
Message::HardwareWallets(msg) => match self.hws.update(msg) {
Ok(cmd) => cmd.map(Message::HardwareWallets),
Err(e) => {
Expand Down
Loading

0 comments on commit e88dbac

Please sign in to comment.