mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-24 14:15:55 -04:00
dprint fmt
This commit is contained in:
parent
7102962898
commit
c1c45571f0
20 changed files with 151 additions and 74 deletions
27
Cargo.toml
27
Cargo.toml
|
@ -1,16 +1,24 @@
|
|||
[workspace]
|
||||
resolver = "2"
|
||||
members = [ "electrum-pool", "monero-rpc", "monero-rpc-pool", "monero-sys", "monero-seed", "src-tauri", "swap", "swap-env", "swap-fs", "swap-feed", "swap-serde", "throttle"]
|
||||
members = [
|
||||
"electrum-pool",
|
||||
"monero-rpc",
|
||||
"monero-rpc-pool",
|
||||
"monero-seed",
|
||||
"monero-sys",
|
||||
"src-tauri",
|
||||
"swap",
|
||||
"swap-env",
|
||||
"swap-feed",
|
||||
"swap-fs",
|
||||
"swap-serde",
|
||||
"throttle",
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
anyhow = "1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync"] }
|
||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
||||
tracing = { version = "0.1", features = ["attributes"] }
|
||||
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "ansi", "env-filter", "time", "tracing-log", "json"] }
|
||||
bitcoin = { version = "0.32", features = ["rand", "serde"] }
|
||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
||||
hex = "0.4"
|
||||
libp2p = { version = "0.53.2" }
|
||||
monero = { version = "0.12", features = ["serde_support"] }
|
||||
|
@ -18,7 +26,12 @@ rand = "0.8"
|
|||
reqwest = { version = "0.12", default-features = false, features = ["json"] }
|
||||
rust_decimal = { version = "1", features = ["serde-float"] }
|
||||
rust_decimal_macros = "1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
thiserror = "1"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync"] }
|
||||
tracing = { version = "0.1", features = ["attributes"] }
|
||||
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "ansi", "env-filter", "time", "tracing-log", "json"] }
|
||||
typeshare = "1.0"
|
||||
url = { version = "2", features = ["serde"] }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
|
|
|
@ -66,9 +66,7 @@
|
|||
|
||||
<p>
|
||||
This repository provides Flatpak packages for
|
||||
<a href="https://github.com/eigenwallet/core"
|
||||
>eigenwallet GUI.</a
|
||||
>
|
||||
<a href="https://github.com/eigenwallet/core">eigenwallet GUI.</a>
|
||||
</p>
|
||||
|
||||
<div class="install-section">
|
||||
|
|
|
@ -1639,7 +1639,9 @@ impl FfiWallet {
|
|||
/// Store the wallet state.
|
||||
fn store(&mut self, path: &str) {
|
||||
let_cxx_string!(path = path);
|
||||
self.inner.pinned().store(&path)
|
||||
self.inner
|
||||
.pinned()
|
||||
.store(&path)
|
||||
.context("Failed to store wallet: FFI call failed with exception")
|
||||
.expect("Shouldn't panic");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import React from "react";
|
||||
import { Badge } from "@mui/material";
|
||||
import { useIsSwapRunning, useResumeableSwapsCountExcludingPunished } from "store/hooks";
|
||||
import {
|
||||
useIsSwapRunning,
|
||||
useResumeableSwapsCountExcludingPunished,
|
||||
} from "store/hooks";
|
||||
|
||||
export default function UnfinishedSwapsBadge({
|
||||
children,
|
||||
|
@ -10,7 +13,9 @@ export default function UnfinishedSwapsBadge({
|
|||
const isSwapRunning = useIsSwapRunning();
|
||||
const resumableSwapsCount = useResumeableSwapsCountExcludingPunished();
|
||||
|
||||
const displayedResumableSwapsCount = isSwapRunning ? resumableSwapsCount - 1 : resumableSwapsCount;
|
||||
const displayedResumableSwapsCount = isSwapRunning
|
||||
? resumableSwapsCount - 1
|
||||
: resumableSwapsCount;
|
||||
|
||||
if (displayedResumableSwapsCount > 0) {
|
||||
return (
|
||||
|
|
|
@ -22,7 +22,8 @@ export default function SendTransactionModal({
|
|||
const pendingApprovals = usePendingSendMoneroApproval();
|
||||
const hasPendingApproval = pendingApprovals.length > 0;
|
||||
|
||||
const [successResponse, setSuccessResponse] = useState<SendMoneroResponse | null>(null);
|
||||
const [successResponse, setSuccessResponse] =
|
||||
useState<SendMoneroResponse | null>(null);
|
||||
|
||||
const showSuccess = successResponse !== null;
|
||||
|
||||
|
@ -42,13 +43,20 @@ export default function SendTransactionModal({
|
|||
}}
|
||||
>
|
||||
{!showSuccess && !hasPendingApproval && (
|
||||
<SendTransactionContent balance={balance} onClose={onClose} onSuccess={setSuccessResponse} />
|
||||
<SendTransactionContent
|
||||
balance={balance}
|
||||
onClose={onClose}
|
||||
onSuccess={setSuccessResponse}
|
||||
/>
|
||||
)}
|
||||
{!showSuccess && hasPendingApproval && (
|
||||
<SendApprovalContent onClose={onClose} />
|
||||
)}
|
||||
{showSuccess && (
|
||||
<SendSuccessContent onClose={onClose} successDetails={successResponse} />
|
||||
<SendSuccessContent
|
||||
onClose={onClose}
|
||||
successDetails={successResponse}
|
||||
/>
|
||||
)}
|
||||
</Dialog>
|
||||
);
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { Box, Button, Typography } from "@mui/material";
|
||||
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
|
||||
import { FiatPiconeroAmount, PiconeroAmount } from "renderer/components/other/Units";
|
||||
import {
|
||||
FiatPiconeroAmount,
|
||||
PiconeroAmount,
|
||||
} from "renderer/components/other/Units";
|
||||
import MonospaceTextBox from "renderer/components/other/MonospaceTextBox";
|
||||
import ArrowOutwardIcon from "@mui/icons-material/ArrowOutward";
|
||||
import { SendMoneroResponse } from "models/tauriModel";
|
||||
|
@ -15,10 +18,12 @@ export default function SendSuccessContent({
|
|||
onClose: () => void;
|
||||
successDetails: SendMoneroResponse | null;
|
||||
}) {
|
||||
|
||||
const address = successDetails?.address;
|
||||
const amount = successDetails?.amount_sent;
|
||||
const explorerUrl = getMoneroTxExplorerUrl(successDetails?.tx_hash, isTestnet());
|
||||
const explorerUrl = getMoneroTxExplorerUrl(
|
||||
successDetails?.tx_hash,
|
||||
isTestnet(),
|
||||
);
|
||||
|
||||
return (
|
||||
<Box
|
||||
|
@ -36,30 +41,68 @@ export default function SendSuccessContent({
|
|||
<CheckCircleIcon sx={{ fontSize: 64, mt: 3 }} />
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Typography variant="h4">Transaction Published</Typography>
|
||||
<Box sx={{ display: "flex", flexDirection: "row", alignItems: "center", gap: 1 }}>
|
||||
<Typography variant="body1" color="text.secondary">Sent</Typography>
|
||||
<Typography variant="body1" color="text.primary">
|
||||
<PiconeroAmount amount={amount} fixedPrecision={4}/>
|
||||
</Typography>
|
||||
<Typography variant="body1" color="text.secondary">(<FiatPiconeroAmount amount={amount} />)</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Typography variant="body1" color="text.secondary">
|
||||
Sent
|
||||
</Typography>
|
||||
<Typography variant="body1" color="text.primary">
|
||||
<PiconeroAmount amount={amount} fixedPrecision={4} />
|
||||
</Typography>
|
||||
<Typography variant="body1" color="text.secondary">
|
||||
(<FiatPiconeroAmount amount={amount} />)
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ display: "flex", flexDirection: "row", alignItems: "center", gap: 1 }}>
|
||||
<Typography variant="body1" color="text.secondary">to</Typography>
|
||||
<Typography variant="body1" color="text.primary">
|
||||
<MonospaceTextBox>{address.slice(0, 8)} ... {address.slice(-8)}</MonospaceTextBox>
|
||||
</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Typography variant="body1" color="text.secondary">
|
||||
to
|
||||
</Typography>
|
||||
<Typography variant="body1" color="text.primary">
|
||||
<MonospaceTextBox>
|
||||
{address.slice(0, 8)} ... {address.slice(-8)}
|
||||
</MonospaceTextBox>
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 1 }}>
|
||||
<Button onClick={onClose} variant="contained" color="primary">Done</Button>
|
||||
<Button color="primary" size="small" endIcon={<ArrowOutwardIcon />} onClick={() => open(explorerUrl)}>View on Explorer</Button>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Button onClick={onClose} variant="contained" color="primary">
|
||||
Done
|
||||
</Button>
|
||||
<Button
|
||||
color="primary"
|
||||
size="small"
|
||||
endIcon={<ArrowOutwardIcon />}
|
||||
onClick={() => open(explorerUrl)}
|
||||
>
|
||||
View on Explorer
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
|
|
@ -514,16 +514,15 @@ export async function sendMoneroTransaction(
|
|||
const response = await sendMonero(args);
|
||||
|
||||
// Refresh balance and history after sending - but don't let this block the response
|
||||
Promise.all([
|
||||
getMoneroBalance(),
|
||||
getMoneroHistory(),
|
||||
]).then(([newBalance, newHistory]) => {
|
||||
store.dispatch(setBalance(newBalance));
|
||||
store.dispatch(setHistory(newHistory));
|
||||
}).catch(refreshErr => {
|
||||
console.error("Failed to refresh wallet data after send:", refreshErr);
|
||||
// Could emit a toast notification here
|
||||
});
|
||||
Promise.all([getMoneroBalance(), getMoneroHistory()])
|
||||
.then(([newBalance, newHistory]) => {
|
||||
store.dispatch(setBalance(newBalance));
|
||||
store.dispatch(setHistory(newHistory));
|
||||
})
|
||||
.catch((refreshErr) => {
|
||||
console.error("Failed to refresh wallet data after send:", refreshErr);
|
||||
// Could emit a toast notification here
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (err) {
|
||||
|
|
|
@ -379,7 +379,7 @@ pub fn query_user_for_initial_config(testnet: bool) -> Result<Config> {
|
|||
println!();
|
||||
|
||||
Ok(Config {
|
||||
data: Data { dir: data_dir},
|
||||
data: Data { dir: data_dir },
|
||||
network: Network {
|
||||
listen: listen_addresses,
|
||||
rendezvous_point: rendezvous_points, // keeping the singular key name for backcompat
|
||||
|
|
|
@ -26,4 +26,4 @@ tokio = { workspace = true }
|
|||
tokio-tungstenite = { version = "0.15", features = ["rustls-tls"] }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
url = { workspace = true }
|
||||
url = { workspace = true }
|
||||
|
|
|
@ -3,11 +3,11 @@ pub mod rate;
|
|||
pub mod traits;
|
||||
|
||||
// Re-exports for convenience
|
||||
pub use kraken::{connect, PriceUpdates, Error as KrakenError};
|
||||
pub use rate::{Rate, FixedRate, KrakenRate};
|
||||
pub use kraken::{connect, Error as KrakenError, PriceUpdates};
|
||||
pub use rate::{FixedRate, KrakenRate, Rate};
|
||||
pub use traits::LatestRate;
|
||||
|
||||
// Core functions
|
||||
pub fn connect_kraken(url: url::Url) -> anyhow::Result<kraken::PriceUpdates> {
|
||||
kraken::connect(url)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,8 +177,9 @@ mod tests {
|
|||
.sell_quote(bitcoin::Amount::ONE_BTC)
|
||||
.unwrap();
|
||||
|
||||
let xmr_factor =
|
||||
xmr_no_spread.into().as_piconero_decimal() / xmr_with_spread.into().as_piconero_decimal() - ONE;
|
||||
let xmr_factor = xmr_no_spread.into().as_piconero_decimal()
|
||||
/ xmr_with_spread.into().as_piconero_decimal()
|
||||
- ONE;
|
||||
|
||||
assert!(xmr_with_spread < xmr_no_spread);
|
||||
assert_eq!(xmr_factor.round_dp(8), TWO_PERCENT); // round to 8 decimal
|
||||
|
@ -186,4 +187,4 @@ mod tests {
|
|||
// it is really close
|
||||
// to two percent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub trait LatestRate {
|
|||
pub trait PriceFeed: Sized {
|
||||
type Error: std::error::Error + Send + Sync + 'static;
|
||||
type Update;
|
||||
|
||||
|
||||
async fn connect(url: url::Url) -> Result<Self, Self::Error>;
|
||||
async fn next_update(&mut self) -> Result<Self::Update, Self::Error>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,9 +72,9 @@ swap-env = { path = "../swap-env" }
|
|||
swap-feed = { path = "../swap-feed" }
|
||||
swap-fs = { path = "../swap-fs" }
|
||||
swap-serde = { path = "../swap-serde" }
|
||||
throttle = { path = "../throttle" }
|
||||
tauri = { version = "2.0", features = ["config-json5"], optional = true, default-features = false }
|
||||
thiserror = { workspace = true }
|
||||
throttle = { path = "../throttle" }
|
||||
time = "0.3"
|
||||
tokio = { workspace = true, features = ["process", "fs", "net", "parking_lot", "rt"] }
|
||||
tokio-tungstenite = { version = "0.15", features = ["rustls-tls"] }
|
||||
|
|
|
@ -7,13 +7,13 @@ pub use event_loop::{EventLoop, EventLoopHandle};
|
|||
pub use network::behaviour::{Behaviour, OutEvent};
|
||||
pub use network::rendezvous::RendezvousNode;
|
||||
pub use network::transport;
|
||||
pub use swap_feed::{FixedRate, KrakenRate, LatestRate, Rate};
|
||||
pub use recovery::cancel::cancel;
|
||||
pub use recovery::punish::punish;
|
||||
pub use recovery::redeem::{redeem, Finality};
|
||||
pub use recovery::refund::refund;
|
||||
pub use recovery::safely_abort::safely_abort;
|
||||
pub use recovery::{cancel, refund};
|
||||
pub use swap_feed::{FixedRate, KrakenRate, LatestRate, Rate};
|
||||
|
||||
#[cfg(test)]
|
||||
pub use network::rendezvous;
|
||||
|
|
|
@ -8,8 +8,6 @@ use crate::protocol::alice::swap::has_already_processed_enc_sig;
|
|||
use crate::protocol::alice::{AliceState, ReservesMonero, State3, Swap};
|
||||
use crate::protocol::{Database, State};
|
||||
use crate::{bitcoin, monero};
|
||||
use swap_feed::{LatestRate};
|
||||
use swap_env::env;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use futures::future;
|
||||
use futures::future::{BoxFuture, FutureExt};
|
||||
|
@ -20,10 +18,12 @@ use libp2p::{PeerId, Swarm};
|
|||
use moka::future::Cache;
|
||||
use monero::Amount;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::{TryInto};
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use swap_env::env;
|
||||
use swap_feed::LatestRate;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tokio::time::timeout;
|
||||
use uuid::Uuid;
|
||||
|
@ -615,7 +615,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventLoopHandle {
|
||||
swap_id: Uuid,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use swap_feed::LatestRate;
|
||||
use swap_env::env;
|
||||
use crate::network::quote::BidQuote;
|
||||
use crate::network::rendezvous::XmrBtcNamespace;
|
||||
use crate::network::swap_setup::alice;
|
||||
|
@ -19,6 +17,8 @@ use libp2p::swarm::NetworkBehaviour;
|
|||
use libp2p::{Multiaddr, PeerId};
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
use swap_env::env;
|
||||
use swap_feed::LatestRate;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub mod transport {
|
||||
|
|
|
@ -36,10 +36,10 @@ use swap::protocol::alice::{run, AliceState};
|
|||
use swap::protocol::{Database, State};
|
||||
use swap::seed::Seed;
|
||||
use swap::{bitcoin, monero};
|
||||
use swap_feed;
|
||||
use swap_env::config::{
|
||||
initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized,
|
||||
};
|
||||
use swap_feed;
|
||||
use tracing_subscriber::filter::LevelFilter;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -195,7 +195,8 @@ pub async fn main() -> Result<()> {
|
|||
tracing::info!(%bitcoin_balance, "Bitcoin wallet balance");
|
||||
|
||||
// Connect to Kraken
|
||||
let kraken_price_updates = swap_feed::connect_kraken(config.maker.price_ticker_ws_url.clone())?;
|
||||
let kraken_price_updates =
|
||||
swap_feed::connect_kraken(config.maker.price_ticker_ws_url.clone())?;
|
||||
|
||||
let kraken_rate = KrakenRate::new(config.maker.ask_spread, kraken_price_updates);
|
||||
let namespace = XmrBtcNamespace::from_is_testnet(testnet);
|
||||
|
|
|
@ -507,7 +507,7 @@ impl ContextBuilder {
|
|||
data_dir: data_dir.clone(),
|
||||
log_dir: log_dir.clone(),
|
||||
},
|
||||
swap_lock,
|
||||
swap_lock,
|
||||
tasks,
|
||||
tauri_handle: self.tauri_handle,
|
||||
tor_client: tor,
|
||||
|
@ -554,7 +554,7 @@ impl Context {
|
|||
pub fn cleanup(&self) -> Result<()> {
|
||||
// TODO: close all monero wallets
|
||||
// call store(..) on all wallets
|
||||
|
||||
|
||||
// TODO: This doesn't work because "there is no reactor running, must be called from the context of a Tokio 1.x runtime"
|
||||
// let monero_manager = self.monero_manager.clone();
|
||||
// tokio::spawn(async move {
|
||||
|
@ -802,7 +802,12 @@ async fn request_and_open_monero_wallet(
|
|||
}
|
||||
|
||||
SeedChoice::Legacy => {
|
||||
let wallet = request_and_open_monero_wallet_legacy(legacy_data_dir, env_config, daemon).await?;
|
||||
let wallet = request_and_open_monero_wallet_legacy(
|
||||
legacy_data_dir,
|
||||
env_config,
|
||||
daemon,
|
||||
)
|
||||
.await?;
|
||||
let seed = Seed::from_file_or_generate(legacy_data_dir)
|
||||
.await
|
||||
.context("Failed to extract seed from wallet")?;
|
||||
|
@ -812,7 +817,10 @@ async fn request_and_open_monero_wallet(
|
|||
};
|
||||
|
||||
// Extract seed from the wallet
|
||||
tracing::info!("Extracting seed from wallet directory: {}", legacy_data_dir.display());
|
||||
tracing::info!(
|
||||
"Extracting seed from wallet directory: {}",
|
||||
legacy_data_dir.display()
|
||||
);
|
||||
let seed = Seed::from_monero_wallet(&wallet)
|
||||
.await
|
||||
.context("Failed to extract seed from wallet")?;
|
||||
|
@ -824,7 +832,8 @@ async fn request_and_open_monero_wallet(
|
|||
// If we don't have a tauri handle, we use the seed.pem file
|
||||
// This is used for the CLI to monitor the blockchain
|
||||
None => {
|
||||
let wallet = request_and_open_monero_wallet_legacy(legacy_data_dir, env_config, daemon).await?;
|
||||
let wallet =
|
||||
request_and_open_monero_wallet_legacy(legacy_data_dir, env_config, daemon).await?;
|
||||
let seed = Seed::from_file_or_generate(legacy_data_dir)
|
||||
.await
|
||||
.context("Failed to extract seed from wallet")?;
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
use std::{path::PathBuf, sync::Arc, time::Duration};
|
||||
|
||||
use throttle::{throttle, Throttle};
|
||||
use anyhow::{Context, Result};
|
||||
use monero::{Address, Network};
|
||||
use monero_sys::WalletEventListener;
|
||||
pub use monero_sys::{Daemon, WalletHandle as Wallet, WalletHandleListener};
|
||||
use throttle::{throttle, Throttle};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::cli::api::{
|
||||
|
|
|
@ -6,7 +6,6 @@ edition = "2024"
|
|||
[dependencies]
|
||||
tracing = { workspace = true }
|
||||
|
||||
|
||||
[lib]
|
||||
path = "src/throttle.rs"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue