mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-13 16:55:57 -04:00
feat(gui): Display progress of monero-wallet-rpc download (#170)
This commit is contained in:
parent
3540a029bd
commit
6f0d060263
5 changed files with 77 additions and 12 deletions
|
@ -1,12 +1,22 @@
|
||||||
import { Button } from "@material-ui/core";
|
import { Box, Button, LinearProgress, makeStyles } from "@material-ui/core";
|
||||||
import { Alert } from "@material-ui/lab";
|
import { Alert } from "@material-ui/lab";
|
||||||
import { TauriContextInitializationProgress } from "models/tauriModel";
|
import { TauriContextInitializationProgress } from "models/tauriModel";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useAppSelector } from "store/hooks";
|
import { useAppSelector } from "store/hooks";
|
||||||
import { exhaustiveGuard } from "utils/typescriptUtils";
|
import { exhaustiveGuard } from "utils/typescriptUtils";
|
||||||
import { LoadingSpinnerAlert } from "./LoadingSpinnerAlert";
|
import { LoadingSpinnerAlert } from "./LoadingSpinnerAlert";
|
||||||
|
import { bytesToMb } from "utils/conversionUtils";
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
innerAlert: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: theme.spacing(2),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
export default function DaemonStatusAlert() {
|
export default function DaemonStatusAlert() {
|
||||||
|
const classes = useStyles();
|
||||||
const contextStatus = useAppSelector((s) => s.rpc.status);
|
const contextStatus = useAppSelector((s) => s.rpc.status);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
@ -16,20 +26,32 @@ export default function DaemonStatusAlert() {
|
||||||
|
|
||||||
switch (contextStatus.type) {
|
switch (contextStatus.type) {
|
||||||
case "Initializing":
|
case "Initializing":
|
||||||
switch (contextStatus.content) {
|
switch (contextStatus.content.type) {
|
||||||
case TauriContextInitializationProgress.OpeningBitcoinWallet:
|
case "OpeningBitcoinWallet":
|
||||||
return (
|
return (
|
||||||
<LoadingSpinnerAlert severity="warning">
|
<LoadingSpinnerAlert severity="warning">
|
||||||
Connecting to the Bitcoin network
|
Connecting to the Bitcoin network
|
||||||
</LoadingSpinnerAlert>
|
</LoadingSpinnerAlert>
|
||||||
);
|
);
|
||||||
case TauriContextInitializationProgress.OpeningMoneroWallet:
|
case "DownloadingMoneroWalletRpc":
|
||||||
|
return (
|
||||||
|
<LoadingSpinnerAlert severity="warning">
|
||||||
|
<Box className={classes.innerAlert}>
|
||||||
|
<Box>
|
||||||
|
Downloading and verifying the Monero wallet RPC (
|
||||||
|
{bytesToMb(contextStatus.content.content.size).toFixed(2)} MB)
|
||||||
|
</Box>
|
||||||
|
<LinearProgress variant="determinate" value={contextStatus.content.content.progress} />
|
||||||
|
</Box>
|
||||||
|
</LoadingSpinnerAlert >
|
||||||
|
);
|
||||||
|
case "OpeningMoneroWallet":
|
||||||
return (
|
return (
|
||||||
<LoadingSpinnerAlert severity="warning">
|
<LoadingSpinnerAlert severity="warning">
|
||||||
Connecting to the Monero network
|
Connecting to the Monero network
|
||||||
</LoadingSpinnerAlert>
|
</LoadingSpinnerAlert>
|
||||||
);
|
);
|
||||||
case TauriContextInitializationProgress.OpeningDatabase:
|
case "OpeningDatabase":
|
||||||
return (
|
return (
|
||||||
<LoadingSpinnerAlert severity="warning">
|
<LoadingSpinnerAlert severity="warning">
|
||||||
Opening the local database
|
Opening the local database
|
||||||
|
|
|
@ -30,9 +30,8 @@ export function isBtcAddressValid(address: string, testnet: boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBitcoinTxExplorerUrl(txid: string, testnet: boolean) {
|
export function getBitcoinTxExplorerUrl(txid: string, testnet: boolean) {
|
||||||
return `https://mempool.space/${
|
return `https://mempool.space/${testnet ? "/testnet" : ""
|
||||||
testnet ? "/testnet" : ""
|
}/tx/${txid}`;
|
||||||
}/tx/${txid}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMoneroTxExplorerUrl(txid: string, stagenet: boolean) {
|
export function getMoneroTxExplorerUrl(txid: string, stagenet: boolean) {
|
||||||
|
@ -67,3 +66,7 @@ export function rendezvousSellerToProviderStatus(
|
||||||
testnet: isTestnet(),
|
testnet: isTestnet(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function bytesToMb(bytes: number): number {
|
||||||
|
return bytes / (1024 * 1024);
|
||||||
|
}
|
||||||
|
|
|
@ -336,8 +336,13 @@ impl ContextBuilder {
|
||||||
let (monero_wallet, monero_rpc_process) = {
|
let (monero_wallet, monero_rpc_process) = {
|
||||||
if let Some(monero) = self.monero {
|
if let Some(monero) = self.monero {
|
||||||
let monero_daemon_address = monero.apply_defaults(self.is_testnet);
|
let monero_daemon_address = monero.apply_defaults(self.is_testnet);
|
||||||
let (wlt, prc) =
|
let (wlt, prc) = init_monero_wallet(
|
||||||
init_monero_wallet(data_dir.clone(), monero_daemon_address, env_config).await?;
|
data_dir.clone(),
|
||||||
|
monero_daemon_address,
|
||||||
|
env_config,
|
||||||
|
self.tauri_handle.clone(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
(Some(Arc::new(wlt)), Some(Arc::new(SyncMutex::new(prc))))
|
(Some(Arc::new(wlt)), Some(Arc::new(SyncMutex::new(prc))))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
|
@ -473,12 +478,13 @@ async fn init_monero_wallet(
|
||||||
data_dir: PathBuf,
|
data_dir: PathBuf,
|
||||||
monero_daemon_address: String,
|
monero_daemon_address: String,
|
||||||
env_config: EnvConfig,
|
env_config: EnvConfig,
|
||||||
|
tauri_handle: Option<TauriHandle>,
|
||||||
) -> Result<(monero::Wallet, monero::WalletRpcProcess)> {
|
) -> Result<(monero::Wallet, monero::WalletRpcProcess)> {
|
||||||
let network = env_config.monero_network;
|
let network = env_config.monero_network;
|
||||||
|
|
||||||
const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet";
|
const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet";
|
||||||
|
|
||||||
let monero_wallet_rpc = monero::WalletRpc::new(data_dir.join("monero")).await?;
|
let monero_wallet_rpc = monero::WalletRpc::new(data_dir.join("monero"), tauri_handle).await?;
|
||||||
|
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
address = monero_daemon_address,
|
address = monero_daemon_address,
|
||||||
|
|
|
@ -110,8 +110,17 @@ impl TauriEmitter for Option<TauriHandle> {
|
||||||
|
|
||||||
#[typeshare]
|
#[typeshare]
|
||||||
#[derive(Display, Clone, Serialize)]
|
#[derive(Display, Clone, Serialize)]
|
||||||
|
#[serde(tag = "type", content = "content")]
|
||||||
pub enum TauriContextInitializationProgress {
|
pub enum TauriContextInitializationProgress {
|
||||||
OpeningBitcoinWallet,
|
OpeningBitcoinWallet,
|
||||||
|
DownloadingMoneroWalletRpc {
|
||||||
|
// Progress of the download in percent (0-100)
|
||||||
|
#[typeshare(serialized_as = "number")]
|
||||||
|
progress: u64,
|
||||||
|
// Size of the download file in bytes
|
||||||
|
#[typeshare(serialized_as = "number")]
|
||||||
|
size: u64,
|
||||||
|
},
|
||||||
OpeningMoneroWallet,
|
OpeningMoneroWallet,
|
||||||
OpeningDatabase,
|
OpeningDatabase,
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ use tokio::process::{Child, Command};
|
||||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||||
use tokio_util::io::StreamReader;
|
use tokio_util::io::StreamReader;
|
||||||
|
|
||||||
|
use crate::cli::api::tauri_bindings::{
|
||||||
|
TauriContextInitializationProgress, TauriContextStatusEvent, TauriEmitter, TauriHandle,
|
||||||
|
};
|
||||||
|
|
||||||
// See: https://www.moneroworld.com/#nodes, https://monero.fail
|
// See: https://www.moneroworld.com/#nodes, https://monero.fail
|
||||||
// We don't need any testnet nodes because we don't support testnet at all
|
// We don't need any testnet nodes because we don't support testnet at all
|
||||||
const MONERO_DAEMONS: Lazy<[MoneroDaemon; 16]> = Lazy::new(|| {
|
const MONERO_DAEMONS: Lazy<[MoneroDaemon; 16]> = Lazy::new(|| {
|
||||||
|
@ -201,7 +205,10 @@ pub struct WalletRpc {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalletRpc {
|
impl WalletRpc {
|
||||||
pub async fn new(working_dir: impl AsRef<Path>) -> Result<WalletRpc> {
|
pub async fn new(
|
||||||
|
working_dir: impl AsRef<Path>,
|
||||||
|
tauri_handle: Option<TauriHandle>,
|
||||||
|
) -> Result<WalletRpc> {
|
||||||
let working_dir = working_dir.as_ref();
|
let working_dir = working_dir.as_ref();
|
||||||
|
|
||||||
if !working_dir.exists() {
|
if !working_dir.exists() {
|
||||||
|
@ -255,6 +262,14 @@ impl WalletRpc {
|
||||||
"Downloading monero-wallet-rpc",
|
"Downloading monero-wallet-rpc",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Emit a tauri event to update the progress
|
||||||
|
tauri_handle.emit_context_init_progress_event(TauriContextStatusEvent::Initializing(
|
||||||
|
TauriContextInitializationProgress::DownloadingMoneroWalletRpc {
|
||||||
|
progress: 0,
|
||||||
|
size: content_length,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
|
|
||||||
let byte_stream = response
|
let byte_stream = response
|
||||||
|
@ -292,6 +307,16 @@ impl WalletRpc {
|
||||||
"Downloading monero-wallet-rpc",
|
"Downloading monero-wallet-rpc",
|
||||||
);
|
);
|
||||||
notified = percent;
|
notified = percent;
|
||||||
|
|
||||||
|
// Emit a tauri event to update the progress
|
||||||
|
tauri_handle.emit_context_init_progress_event(
|
||||||
|
TauriContextStatusEvent::Initializing(
|
||||||
|
TauriContextInitializationProgress::DownloadingMoneroWalletRpc {
|
||||||
|
progress: percent,
|
||||||
|
size: content_length,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
file.write_all(&bytes).await?;
|
file.write_all(&bytes).await?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue