Skip to content

Commit

Permalink
ui: new payto window
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 21, 2023
1 parent 831fd48 commit 4edc406
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mycitadel-desktop"
version = "1.3.0"
version = "2.0.0"
authors = ["Dr Maxim Orlovsky <[email protected]>"]
description = "Bitcoin, Lightning and RGB wallet; part of MyCitadel software suite."
repository = "https://github.com/mycitadel/mycitadel-desktop"
Expand Down
48 changes: 47 additions & 1 deletion src/view/wallet/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,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 @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -587,6 +632,7 @@ impl Widget for 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 @@ -12,6 +12,7 @@
mod asset_row;
mod component;
mod pay;
mod payto;
mod view_model;
mod widget;

Expand Down Expand Up @@ -41,6 +42,7 @@ pub enum Msg {
Settings,
Update(Vec<Signer>, BTreeSet<DescriptorClass>, ElectrumServer),
Pay(pay::Msg),
PayTo(payto::Msg),
Fiat(Fiat),
Refresh,
InvoiceAmountToggle(bool),
Expand Down
22 changes: 22 additions & 0 deletions src/view/wallet/payto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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>.

mod widget;

use gtk::ResponseType;
pub use widget::Widgets;

#[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
48 changes: 48 additions & 0 deletions src/view/wallet/payto/widget.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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, 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<wallet::Component>) {}
}

0 comments on commit 4edc406

Please sign in to comment.