Skip to content

Commit

Permalink
wip on making new payment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 11, 2023
1 parent 046fb86 commit eb0e08d
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
48 changes: 47 additions & 1 deletion src/view/wallet/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ 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};

pub struct Component {
model: ViewModel,
widgets: Widgets,
pay_widgets: pay::Widgets,
payto_widgets: payto::Widgets,

exchange_channel: Channel<exchange::Msg>,
exchange_worker: ExchangeWorker,
Expand Down Expand Up @@ -365,6 +367,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(),
Expand Down Expand Up @@ -528,6 +531,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;
Expand Down Expand Up @@ -560,17 +601,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,
Expand Down
2 changes: 2 additions & 0 deletions src/view/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

mod component;
mod pay;
mod payto;
mod view_model;
mod widget;

Expand Down Expand Up @@ -39,6 +40,7 @@ pub enum Msg {
Settings,
Update(Vec<Signer>, BTreeSet<DescriptorClass>, ElectrumServer),
Pay(pay::Msg),
PayTo(payto::Msg),
Fiat(Fiat),
Refresh,
InvoiceAmountToggle(bool),
Expand Down
21 changes: 21 additions & 0 deletions src/view/wallet/payto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// MyCitadel desktop wallet: bitcoin & RGB wallet based on GTK framework.
//
// Written in 2022 by
// Dr. Maxim Orlovsky <[email protected]>
//
// 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
// <https://www.gnu.org/licenses/agpl-3.0-standalone.html>.

use gtk::ResponseType;

mod widget;

#[derive(Msg)]
pub enum Msg {
Show,
Advanced,
Response(ResponseType),
}
4 changes: 2 additions & 2 deletions src/view/wallet/payto/payto.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="payto_dlg">
<object class="GtkDialog" id="dialog">
<property name="can-focus">False</property>
<property name="window-position">center</property>
<property name="type-hint">dialog</property>
Expand Down Expand Up @@ -232,7 +232,7 @@
</packing>
</child>
<child>
<object class="GtkButton" id="advanced_btn">
<object class="GtkButton" id="batch_btn">
<property name="label" translatable="yes">Batch</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
Expand Down
45 changes: 45 additions & 0 deletions src/view/wallet/payto/widget.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// MyCitadel desktop wallet: bitcoin & RGB wallet based on GTK framework.
//
// Written in 2022 by
// Dr. Maxim Orlovsky <[email protected]>
//
// 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
// <https://www.gnu.org/licenses/agpl-3.0-standalone.html>.

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<wallet::Component>) {}
}

0 comments on commit eb0e08d

Please sign in to comment.