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,26 +53,18 @@ 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 (
<> <>
<Tooltip title="Click to view details">
<Paper <Paper
variant="outlined" variant="outlined"
onClick={() => setDialogOpen(true)} onClick={() => setDialogOpen(true)}
@ -102,8 +95,10 @@ export default function MakerDiscoveryStatus() {
}} }}
> >
{isActive {isActive
? quotesInflight > 0
? "Getting offers..." ? "Getting offers..."
: "Waiting a few seconds before refreshing offers"} : "Dialing peers..."
: "Waiting a few seconds..."}
</Typography> </Typography>
<Stack direction="row" alignItems="center" gap={2}> <Stack direction="row" alignItems="center" gap={2}>
@ -115,16 +110,7 @@ export default function MakerDiscoveryStatus() {
fontWeight: "medium", fontWeight: "medium",
}} }}
> >
{quotesReceived} online Connected to {peers.length} peers
</Typography>
<Typography
variant="caption"
sx={{
color: isActive ? "error.main" : "text.disabled",
fontWeight: "medium",
}}
>
{quotesFailed} offline
</Typography> </Typography>
</Stack> </Stack>
<InfoIcon <InfoIcon
@ -134,8 +120,8 @@ export default function MakerDiscoveryStatus() {
</Stack> </Stack>
</Stack> </Stack>
<LinearProgress <LinearProgress
variant="determinate" variant={isActive ? "indeterminate" : "determinate"}
value={Math.min(progressValue, 100)} value={0}
sx={{ sx={{
width: "100%", width: "100%",
height: 8, height: 8,
@ -145,6 +131,7 @@ export default function MakerDiscoveryStatus() {
/> />
</Stack> </Stack>
</Paper> </Paper>
</Tooltip>
<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.