feat(gui): simplify MakerDiscoveryStatus

This commit is contained in:
Binarybaron 2025-12-01 20:22:47 +01:00
parent 43a36155e8
commit df95c2298c
2 changed files with 68 additions and 84 deletions

View file

@ -17,6 +17,7 @@ import {
Chip, Chip,
CircularProgress, CircularProgress,
Stack, Stack,
Tooltip,
} from "@mui/material"; } from "@mui/material";
import { Info as InfoIcon, Close as CloseIcon } from "@mui/icons-material"; import { Info as InfoIcon, Close as CloseIcon } from "@mui/icons-material";
import { useEffect, useState, useMemo } from "react"; import { useEffect, useState, useMemo } from "react";
@ -52,99 +53,85 @@ export default function MakerDiscoveryStatus() {
} }
}, [peers]); }, [peers]);
const totalPeers = peers.length;
const quotesReceived = peers.filter(
(p) => p.quote === QuoteStatus.Received,
).length;
const quotesFailed = peers.filter(
(p) =>
p.quote === QuoteStatus.Failed || p.quote === QuoteStatus.NotSupported,
).length;
const quotesInflight = peers.filter( const quotesInflight = peers.filter(
(p) => p.quote === QuoteStatus.Inflight, (p) => p.quote === QuoteStatus.Inflight,
).length; ).length;
const dialsInflight = peers.filter(
(p) => p.connection === ConnectionStatus.Dialing,
).length;
const isActive = quotesInflight > 0 || totalPeers === 0; const isActive = quotesInflight > 0 || dialsInflight > 0;
const totalCompleted = quotesReceived + quotesFailed;
const progressValue =
totalPeers > 0 ? (totalCompleted / totalPeers) * 100 : 0;
return ( return (
<> <>
<Paper <Tooltip title="Click to view details">
variant="outlined" <Paper
onClick={() => setDialogOpen(true)} variant="outlined"
sx={{ onClick={() => setDialogOpen(true)}
width: "100%", sx={{
mb: 2, width: "100%",
p: 2, mb: 2,
borderColor: isActive ? "success.main" : "divider", p: 2,
opacity: isActive ? 1 : 0.6, borderColor: isActive ? "success.main" : "divider",
cursor: "pointer", opacity: isActive ? 1 : 0.6,
transition: "background-color 0.2s", cursor: "pointer",
"&:hover": { transition: "background-color 0.2s",
bgcolor: "action.hover", "&:hover": {
}, bgcolor: "action.hover",
}} },
> }}
<Stack gap={1.5}> >
<Stack <Stack gap={1.5}>
direction="row" <Stack
alignItems="center" direction="row"
justifyContent="space-between" alignItems="center"
> justifyContent="space-between"
<Typography
variant="body2"
sx={{
fontWeight: "medium",
color: isActive ? "info.main" : "text.disabled",
}}
> >
{isActive <Typography
? "Getting offers..." variant="body2"
: "Waiting a few seconds before refreshing offers"} sx={{
</Typography> fontWeight: "medium",
color: isActive ? "info.main" : "text.disabled",
}}
>
{isActive
? quotesInflight > 0
? "Getting offers..."
: "Dialing peers..."
: "Waiting a few seconds..."}
</Typography>
<Stack direction="row" alignItems="center" gap={2}> <Stack direction="row" alignItems="center" gap={2}>
<Stack direction="row" gap={2}> <Stack direction="row" gap={2}>
<Typography <Typography
variant="caption" variant="caption"
sx={{ sx={{
color: isActive ? "success.main" : "text.disabled", color: isActive ? "success.main" : "text.disabled",
fontWeight: "medium", fontWeight: "medium",
}} }}
> >
{quotesReceived} online Connected to {peers.length} peers
</Typography> </Typography>
<Typography </Stack>
variant="caption" <InfoIcon
sx={{ fontSize="small"
color: isActive ? "error.main" : "text.disabled", sx={{ opacity: 0.7, color: "action.active" }}
fontWeight: "medium", />
}}
>
{quotesFailed} offline
</Typography>
</Stack> </Stack>
<InfoIcon
fontSize="small"
sx={{ opacity: 0.7, color: "action.active" }}
/>
</Stack> </Stack>
<LinearProgress
variant={isActive ? "indeterminate" : "determinate"}
value={0}
sx={{
width: "100%",
height: 8,
borderRadius: 4,
opacity: isActive ? 1 : 0.4,
}}
/>
</Stack> </Stack>
<LinearProgress </Paper>
variant="determinate" </Tooltip>
value={Math.min(progressValue, 100)}
sx={{
width: "100%",
height: 8,
borderRadius: 4,
opacity: isActive ? 1 : 0.4,
}}
/>
</Stack>
</Paper>
<PeerDetailsDialog <PeerDetailsDialog
open={dialogOpen} open={dialogOpen}
onClose={() => setDialogOpen(false)} onClose={() => setDialogOpen(false)}

View file

@ -5,7 +5,6 @@ use crate::monero;
use crate::network::cooperative_xmr_redeem_after_punish::{self, Request, Response}; use crate::network::cooperative_xmr_redeem_after_punish::{self, Request, Response};
use crate::network::encrypted_signature; use crate::network::encrypted_signature;
use crate::network::quote::BidQuote; use crate::network::quote::BidQuote;
use crate::network::quotes_cached::QuoteStatus;
use crate::network::swap_setup::bob::NewSwap; use crate::network::swap_setup::bob::NewSwap;
use crate::protocol::bob::swap::has_already_processed_transfer_proof; use crate::protocol::bob::swap::has_already_processed_transfer_proof;
use crate::protocol::bob::{BobState, State2}; use crate::protocol::bob::{BobState, State2};
@ -21,9 +20,7 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use swap_core::bitcoin::EncryptedSignature; use swap_core::bitcoin::EncryptedSignature;
use swap_p2p::observe;
use swap_p2p::protocols::redial; use swap_p2p::protocols::redial;
use tracing::Instrument;
use uuid::Uuid; use uuid::Uuid;
// Timeout for the execution setup protocol within the event loop. // Timeout for the execution setup protocol within the event loop.