Skip to content

Commit

Permalink
Allow from federation for sweeps
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGiorgio committed May 7, 2024
1 parent 1400c87 commit 3ced965
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,16 +1590,16 @@ impl<S: MutinyStorage> MutinyWallet<S> {
pub async fn sweep_federation_balance(
&self,
amount: Option<u64>,
from_federation_id: Option<FederationId>,
) -> Result<FedimintSweepResult, MutinyError> {
// TODO support more than one federation
let federation_ids = self.list_federation_ids().await?;
if federation_ids.is_empty() {
return Err(MutinyError::NotFound);
}
let federation_id = &federation_ids[0];
let federation_id = from_federation_id.unwrap_or(federation_ids[0]);
let federation_lock = self.federations.read().await;
let fedimint_client = federation_lock
.get(federation_id)
.get(&federation_id)
.ok_or(MutinyError::NotFound)?;

let labels = vec![SWAP_LABEL.to_string()];
Expand Down
14 changes: 13 additions & 1 deletion mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,20 @@ impl MutinyWallet {
pub async fn sweep_federation_balance(
&self,
amount: Option<u64>,
from_federation_id: Option<String>,
) -> Result<FedimintSweepResult, MutinyJsError> {
Ok(self.inner.sweep_federation_balance(amount).await?.into())
let from_federation_id = match from_federation_id {
Some(f) => {
Some(FederationId::from_str(&f).map_err(|_| MutinyJsError::InvalidArgumentsError)?)
}
None => None,
};

Ok(self
.inner
.sweep_federation_balance(amount, from_federation_id)
.await?
.into())
}

/// Estimate the fee before trying to sweep from federation
Expand Down

0 comments on commit 3ced965

Please sign in to comment.