Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP on accounting export #108

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern crate relm;
extern crate relm_derive;
extern crate bitcoin_hwi as hwi;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde_crate as serde;

extern crate glade as gladis;
Expand Down
12 changes: 11 additions & 1 deletion src/view/wallet/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +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::{error_dlg, launch, settings, NotificationBoxExt};
use crate::view::{error_dlg, file_open_dlg, launch, settings, NotificationBoxExt};
use crate::worker::{electrum, exchange, ElectrumWorker, ExchangeWorker};

pub struct Component {
Expand Down Expand Up @@ -355,6 +355,16 @@ impl Update for Component {
.as_ref()
.map(|stream| stream.emit(launch::Msg::ShowPage(launch::Page::Import)));
}
Msg::ExportHistory => {
if let Some(path) = file_open_dlg(
Some(self.widgets.as_root()),
"Export history",
"Comma-separated values",
"*.csv",
) {
match self.model.export_history(path) {}
}
}
Msg::Close => self.close(),
Msg::About => {
self.launcher_stream
Expand Down
1 change: 1 addition & 0 deletions src/view/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum Msg {
Open,
Close,
About,
ExportHistory,
Duplicate,
Import,
Launch(launch::Msg),
Expand Down
39 changes: 37 additions & 2 deletions src/view/wallet/view_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
// <https://www.gnu.org/licenses/agpl-3.0-standalone.html>.

use std::collections::BTreeSet;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use bpro::{file, DescriptorError, ElectrumServer, FileDocument, Signer, Wallet, WalletSettings};
use bitcoin::Txid;
use bpro::{
file, DescriptorError, ElectrumServer, FileDocument, HistoryEntry, Signer, Wallet,
WalletSettings,
};
use wallet::descriptors::DescriptorClass;
use wallet::hd::UnhardenedIndex;
use crate::model::FormatDate;

use super::pay::beneficiary_row::BeneficiaryModel;
use crate::worker::exchange::{Exchange, Fiat};
Expand Down Expand Up @@ -92,4 +97,34 @@ impl ViewModel {
None
})
}

pub fn export_history(&self, path: impl AsRef<Path>) {
#[derive(Serialize, Deserialize)]
#[serde(crate = serde_crate)]
struct Entry {
pub timestamp: String,
pub height: u32,
pub txid: Txid,
pub label: String,
pub amount: u64,
pub balance: u64,
pub fee: u64,
pub fee_rate: u64,
}

impl From<HistoryEntry> for Entry {
fn from(entry: HistoryEntry) -> Self { Entry {
timestamp: entry.onchain.format_date(),
height: entry.onchain.status.into_u32(),
txid: entry.onchain.txid,
label: entry.comment.map(|c| c.label).unwrap_or_default(),
amount: entry.,
balance: 0,
fee: 0,
fee_rate: 0,
} }
}

let history: Vec<_> = self.model.wallet().history().iter().collect();
}
}
14 changes: 14 additions & 0 deletions src/view/wallet/wallet.glade
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,20 @@
<object class="GtkMenu" id="menu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkMenuItem" id="export_history_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">E_xport history</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="redefine_mi">
<property name="visible">True</property>
Expand Down
16 changes: 8 additions & 8 deletions src/view/wallet/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct Widgets {
new_btn: Button,
open_btn: Button,
settings_btn: Button,
export_history_mi: MenuItem,
redefine_mi: MenuItem,
import_mi: MenuItem,
settings_mi: MenuItem,
Expand Down Expand Up @@ -164,6 +165,12 @@ impl Widgets {
Msg::Pay(pay::Msg::Show)
);
connect!(relm, self.refresh_btn, connect_clicked(_), Msg::Refresh);
connect!(
relm,
self.export_history_mi,
connect_activate(_),
Msg::ExportHistory
);
connect!(relm, self.redefine_mi, connect_activate(_), Msg::Duplicate);
connect!(relm, self.import_mi, connect_activate(_), Msg::Import);
connect!(relm, self.settings_mi, connect_activate(_), Msg::Settings);
Expand Down Expand Up @@ -513,14 +520,7 @@ impl Widgets {
balance += item.balance();
let btc = format!("{:+.08}", item.balance() as f64 / 100_000_000.0);
let btc_balance = format!("{:.08}", balance as f64 / 100_000_000.0);
let date = match item.onchain.status {
OnchainStatus::Blockchain(height) => item
.onchain
.date_time()
.map(|dt| dt.format("%F %H:%M").to_string())
.unwrap_or_else(|| format!("{height}")),
OnchainStatus::Mempool => s!("mempool"),
};
let date = item.onchain.format_date();
let txid = item.onchain.txid;
let baid = Baid58::with("txid", txid.into_inner());
let mut sort = item.onchain.status.into_u32();
Expand Down