diff --git a/Cargo.lock b/Cargo.lock index e778b99..c3391a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "mycitadel-desktop" -version = "1.3.0" +version = "2.0.0" dependencies = [ "amplify 3.14.2", "bitcoin 0.29.2", diff --git a/Cargo.toml b/Cargo.toml index 2f49ac5..2dfac61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mycitadel-desktop" -version = "1.3.0" +version = "2.0.0" authors = ["Dr Maxim Orlovsky "] description = "Bitcoin, Lightning and RGB wallet; part of MyCitadel software suite." repository = "https://github.com/mycitadel/mycitadel-desktop" diff --git a/src/view/wallet/component.rs b/src/view/wallet/component.rs index e108e17..6ed552d 100644 --- a/src/view/wallet/component.rs +++ b/src/view/wallet/component.rs @@ -33,6 +33,7 @@ use wallet::lex_order::lex_order::LexOrder; use super::pay::beneficiary_row::Beneficiary; use super::pay::FeeRate; use super::{pay, ElectrumState, Msg, ViewModel, Widgets}; +use crate::view::wallet::payto; use crate::view::{error_dlg, launch, settings, NotificationBoxExt}; use crate::worker::{electrum, exchange, ElectrumWorker, ExchangeWorker}; @@ -40,6 +41,7 @@ pub struct Component { model: ViewModel, widgets: Widgets, pay_widgets: pay::Widgets, + payto_widgets: payto::Widgets, exchange_channel: Channel, exchange_worker: ExchangeWorker, @@ -376,6 +378,7 @@ impl Update for Component { .map(|stream| stream.emit(launch::Msg::About)); } Msg::Pay(msg) => self.update_pay(msg), + Msg::PayTo(msg) => self.update_payto(msg), Msg::Settings => self.settings.emit(settings::Msg::View( self.model.to_settings(), self.model.path().clone(), @@ -539,6 +542,44 @@ impl Component { } } +impl Component { + fn update_payto(&mut self, event: payto::Msg) { + match event { + payto::Msg::Show => { + self.payto_widgets.init_ui(&self.model); + self.payto_widgets.show(); + } + payto::Msg::Response(ResponseType::Ok) => { + let (psbt, change_index) = match self.sync_pay() { + Some(data) => data, + None => return, + }; + self.payto_widgets.hide(); + self.launcher_stream.as_ref().map(|stream| { + stream.emit(launch::Msg::CreatePsbt( + psbt, + self.model.as_settings().network(), + )) + }); + // Update latest change index in wallet settings by sending message to the wallet + // component + if self + .model + .wallet_mut() + .update_next_change_index(change_index) + { + self.save(); + } + } + payto::Msg::Response(ResponseType::Cancel) => { + self.payto_widgets.hide(); + } + payto::Msg::Response(_) => {} + _ => {} // Changes which update wallet tx + } + } +} + impl Widget for Component { // Specify the type of the root widget. type Root = ApplicationWindow; @@ -571,11 +612,15 @@ impl Widget for Component { let glade_src = include_str!("pay/pay.glade"); let pay_widgets = pay::Widgets::from_string(glade_src).expect("glade file broken"); - pay_widgets.connect(relm); pay_widgets.bind_beneficiary_model(relm, &model); pay_widgets.init_ui(&model); + let glade_src = include_str!("payto/payto.glade"); + let payto_widgets = payto::Widgets::from_string(glade_src).expect("glade file broken"); + payto_widgets.connect(relm); + payto_widgets.init_ui(&model); + electrum_worker.sync(); // TODO: remove the panic and allow user to fix resolver settings @@ -587,6 +632,7 @@ impl Widget for Component { model, widgets, pay_widgets, + payto_widgets, settings, exchange_channel, diff --git a/src/view/wallet/mod.rs b/src/view/wallet/mod.rs index 96c94f8..3193adb 100644 --- a/src/view/wallet/mod.rs +++ b/src/view/wallet/mod.rs @@ -12,6 +12,7 @@ mod asset_row; mod component; mod pay; +mod payto; mod view_model; mod widget; @@ -41,6 +42,7 @@ pub enum Msg { Settings, Update(Vec, BTreeSet, ElectrumServer), Pay(pay::Msg), + PayTo(payto::Msg), Fiat(Fiat), Refresh, InvoiceAmountToggle(bool), diff --git a/src/view/wallet/payto/mod.rs b/src/view/wallet/payto/mod.rs new file mode 100644 index 0000000..f6bda42 --- /dev/null +++ b/src/view/wallet/payto/mod.rs @@ -0,0 +1,22 @@ +// MyCitadel desktop wallet: bitcoin & RGB wallet based on GTK framework. +// +// Written in 2022 by +// Dr. Maxim Orlovsky +// +// Copyright (C) 2022 by Pandora Prime SA, Switzerland. +// +// This software is distributed without any warranty. You should have received +// a copy of the AGPL-3.0 License along with this software. If not, see +// . + +mod widget; + +use gtk::ResponseType; +pub use widget::Widgets; + +#[derive(Msg)] +pub enum Msg { + Show, + Advanced, + Response(ResponseType), +} diff --git a/src/view/wallet/payto/payto.glade b/src/view/wallet/payto/payto.glade index 83b7fa6..01b6527 100644 --- a/src/view/wallet/payto/payto.glade +++ b/src/view/wallet/payto/payto.glade @@ -2,7 +2,7 @@ - + False center dialog @@ -232,7 +232,7 @@ - + Batch True True diff --git a/src/view/wallet/payto/widget.rs b/src/view/wallet/payto/widget.rs new file mode 100644 index 0000000..30d4b04 --- /dev/null +++ b/src/view/wallet/payto/widget.rs @@ -0,0 +1,48 @@ +// MyCitadel desktop wallet: bitcoin & RGB wallet based on GTK framework. +// +// Written in 2022 by +// Dr. Maxim Orlovsky +// +// Copyright (C) 2022 by Pandora Prime SA, Switzerland. +// +// This software is distributed without any warranty. You should have received +// a copy of the AGPL-3.0 License along with this software. If not, see +// . + +use gladis::Gladis; +use gtk::prelude::*; +use gtk::{Button, Dialog, Entry, HeaderBar, InfoBar, Label, ToggleButton}; +use relm::Relm; + +use crate::view::wallet; + +// Create the structure that holds the widgets used in the view. +#[derive(Clone, Gladis)] +pub struct Widgets { + dialog: Dialog, + header_bar: HeaderBar, + + info_bar: InfoBar, + info_lbl: Label, + + cancel_btn: Button, + compose_btn: Button, + batch_btn: Button, + + invoice_fld: Entry, + amount_fld: Entry, + max_btn: ToggleButton, + asset_lbl: Label, +} + +impl Widgets { + pub fn init_ui(&self, model: &wallet::ViewModel) {} + + pub fn show(&self) { self.dialog.show() } + pub fn hide(&self) { self.dialog.hide() } + + pub fn to_root(&self) -> Dialog { self.dialog.clone() } + pub fn as_root(&self) -> &Dialog { &self.dialog } + + pub fn connect(&self, relm: &Relm) {} +}