diff --git a/src/view/wallet/component.rs b/src/view/wallet/component.rs index c6d7ee6..ba1a2de 100644 --- a/src/view/wallet/component.rs +++ b/src/view/wallet/component.rs @@ -32,6 +32,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}; @@ -39,6 +40,7 @@ pub struct Component { model: ViewModel, widgets: Widgets, pay_widgets: pay::Widgets, + payto_widgets: payto::Widgets, exchange_channel: Channel, exchange_worker: ExchangeWorker, @@ -360,6 +362,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(), @@ -520,6 +523,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 + .as_wallet_mut() + .update_next_change_index(change_index) + { + self.save(); + } + } + pay::Msg::Response(ResponseType::Cancel) => { + self.payto_widgets.hide(); + } + pay::Msg::Response(_) => {} + _ => {} // Changes which update wallet tx + } + } +} + impl Widget for Component { // Specify the type of the root widget. type Root = ApplicationWindow; @@ -552,17 +593,22 @@ 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(); 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 9919816..9942a5b 100644 --- a/src/view/wallet/mod.rs +++ b/src/view/wallet/mod.rs @@ -11,6 +11,7 @@ mod component; mod pay; +mod payto; mod view_model; mod widget; @@ -39,6 +40,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..98424cd --- /dev/null +++ b/src/view/wallet/payto/mod.rs @@ -0,0 +1,21 @@ +// 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 gtk::ResponseType; + +mod widget; + +#[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..a22b344 --- /dev/null +++ b/src/view/wallet/payto/widget.rs @@ -0,0 +1,45 @@ +// 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, Label, ToggleButton}; +use relm::Relm; + +// Create the structure that holds the widgets used in the view. +#[derive(Clone, Gladis)] +pub struct Widgets { + dialog: Dialog, + header_bar: HeaderBar, + + 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) {} +}