Skip to content

Commit

Permalink
Merge pull request #102 from HarborWallet/todos
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman authored Nov 24, 2024
2 parents e1d355b + 177571f commit 30b1511
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
*/target
.env
.direnv
harbor.sqlite
38 changes: 26 additions & 12 deletions harbor-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use bip39::Mnemonic;
use bitcoin::address::NetworkUnchecked;
use bitcoin::{Address, Network, Txid};
use fedimint_core::config::{ClientConfig, FederationId};
use fedimint_core::core::ModuleKind;
use fedimint_core::invite_code::InviteCode;
use fedimint_core::Amount;
use fedimint_ln_client::{LightningClientModule, PayType};
use fedimint_ln_common::config::FeeToAmount;
use fedimint_ln_common::lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};
use fedimint_wallet_client::WalletClientModule;
use futures::future::join_all;
use futures::{channel::mpsc::Sender, SinkExt};
use log::{error, trace};
use std::collections::HashMap;
Expand Down Expand Up @@ -172,7 +174,6 @@ impl HarborCore {
}
let amount = Amount::from_msats(invoice.amount_milli_satoshis().expect("must have amount"));

// todo go through all clients and select the first one that has enough balance
let client = self.get_client(federation_id).await.fedimint_client;
let lightning_module = client
.get_first_module::<LightningClientModule>()
Expand Down Expand Up @@ -293,13 +294,11 @@ impl HarborCore {
address: Address<NetworkUnchecked>,
sats: Option<u64>,
) -> anyhow::Result<()> {
// todo go through all clients and select the first one that has enough balance
let client = self.get_client(federation_id).await.fedimint_client;
let onchain = client
.get_first_module::<WalletClientModule>()
.expect("must have wallet module");

// todo add manual fee selection
let (fees, amount) = match sats {
Some(sats) => {
let amount = bitcoin::Amount::from_sat(sats);
Expand Down Expand Up @@ -433,20 +432,35 @@ impl HarborCore {
let clients = self.clients.read().await;

// Tell the UI about any clients we have
clients
.values()
.map(|c| FederationItem {
join_all(clients.values().map(|c| async {
let balance = c.fedimint_client.get_balance().await;
let config = c.fedimint_client.config().await;

let guardians: Vec<String> = config
.global
.api_endpoints
.values()
.map(|url| url.name.clone())
.collect();

let module_kinds = config
.modules
.into_values()
.map(|module_config| module_config.kind().to_owned())
.collect::<Vec<ModuleKind>>();

FederationItem {
id: c.fedimint_client.federation_id(),
name: c
.fedimint_client
.get_meta("federation_name")
.unwrap_or("Unknown".to_string()),
// TODO: get the balance per fedimint
balance: 420,
guardians: None,
module_kinds: None,
})
.collect::<Vec<FederationItem>>()
balance: balance.sats_round_down(),
guardians: Some(guardians),
module_kinds: Some(module_kinds),
}
}))
.await
}

pub async fn get_seed_words(&self) -> String {
Expand Down
20 changes: 12 additions & 8 deletions harbor-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,14 @@ impl HarborWallet {
let amount = if self.is_max {
None
} else {
// TODO: error handling
Some(self.send_amount_input_str.parse::<u64>().unwrap())
match self.send_amount_input_str.parse::<u64>() {
Ok(amount) => Some(amount),
Err(e) => {
eprintln!("Error parsing amount: {e}");
self.send_failure_reason = Some(e.to_string());
return Task::none();
}
}
};
Task::perform(
Self::async_send_onchain(
Expand Down Expand Up @@ -572,7 +578,7 @@ impl HarborWallet {
UnlockStatus::Unlocking => Task::none(),
_ => {
self.unlock_failure_reason = None;
let id = Uuid::new_v4(); // todo use this id somewhere
let id = Uuid::new_v4();
Task::perform(
Self::async_unlock(self.ui_handle.clone(), id, password),
|_| Message::Noop,
Expand All @@ -583,7 +589,7 @@ impl HarborWallet {
UnlockStatus::Unlocking => Task::none(),
_ => {
self.unlock_failure_reason = None;
let id = Uuid::new_v4(); // todo use this id somewhere
let id = Uuid::new_v4();
Task::perform(
Self::async_init(self.ui_handle.clone(), id, password),
|_| Message::Noop,
Expand All @@ -593,7 +599,7 @@ impl HarborWallet {
Message::AddFederation(invite_code) => {
let invite = InviteCode::from_str(&invite_code);
if let Ok(invite) = invite {
let id = Uuid::new_v4(); // todo use this id somewhere
let id = Uuid::new_v4();
Task::perform(
Self::async_add_federation(self.ui_handle.clone(), id, invite),
|_| Message::Noop,
Expand Down Expand Up @@ -648,7 +654,7 @@ impl HarborWallet {
]),
Message::ShowSeedWords(show) => {
if show {
let id = Uuid::new_v4(); // todo use this id somewhere
let id = Uuid::new_v4();
Task::perform(
Self::async_get_seed_words(self.ui_handle.clone(), id),
|_| Message::Noop,
Expand Down Expand Up @@ -735,7 +741,6 @@ impl HarborWallet {
})
}
CoreUIMsg::FederationInfo(config) => {
// todo update the UI with the new config
let id = config.calculate_federation_id();
let name = config.meta::<String>("federation_name");
let guardians: Vec<String> = config
Expand All @@ -756,7 +761,6 @@ impl HarborWallet {
_ => "Unknown".to_string(),
};

// TODO: what to do about balance in this case? Maybe it should be Option<u64>?
let item = FederationItem {
id,
name,
Expand Down

0 comments on commit 30b1511

Please sign in to comment.