Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/api/SwapsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { type ActiveSwap, type SwapDetail } from './models';
export const useActiveSwaps = () =>
useApiQuery<ActiveSwap[]>('swaps', '/swaps/active', SSE_FALLBACK_INTERVAL);

export const useAllSwaps = (params?: {
search?: string;
limit?: number;
offset?: number;
}) =>
export const useAllSwaps = (
params?: {
search?: string;
limit?: number;
offset?: number;
},
enabled?: boolean,
) =>
useApiQuery<ActiveSwap[]>(
'allSwaps',
'/swaps',
SSE_FALLBACK_INTERVAL,
params,
enabled,
);

export const useSwapDetail = (swapId: string) =>
Expand Down
10 changes: 7 additions & 3 deletions src/components/dashboard/OrderbookDepth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ const OrderbookDepth: React.FC = () => {
arrow
placement="top"
>
<span style={{ cursor: 'help', borderBottom: '1px dotted' }}>
<span
style={{ cursor: 'pointer', borderBottom: '1px dotted' }}
>
Rate (TAO)
</span>
</Tooltip>
Expand All @@ -310,7 +312,9 @@ const OrderbookDepth: React.FC = () => {
arrow
placement="top"
>
<span style={{ cursor: 'help', borderBottom: '1px dotted' }}>
<span
style={{ cursor: 'pointer', borderBottom: '1px dotted' }}
>
Capacity (TAO)
</span>
</Tooltip>
Expand All @@ -326,7 +330,7 @@ const OrderbookDepth: React.FC = () => {
display: 'inline-flex',
alignItems: 'center',
gap: 0.75,
cursor: 'help',
cursor: 'pointer',
}}
>
{selected?.direction === 'reverse' ? (
Expand Down
41 changes: 30 additions & 11 deletions src/components/dashboard/ReservationsTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
InputAdornment,
Stack,
TextField,
Tooltip,
Typography,
useTheme,
} from '@mui/material';
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import SearchIcon from '@mui/icons-material/Search';
import {
useChainState,
Expand Down Expand Up @@ -76,17 +78,34 @@ const ReservationsTracker: React.FC = () => {
alignItems={{ xs: 'stretch', sm: 'center' }}
justifyContent="space-between"
>
<Typography
sx={{
fontFamily: FONTS.mono,
fontSize: '0.7rem',
letterSpacing: '0.12em',
textTransform: 'uppercase',
color: 'text.secondary',
}}
>
Reservations
</Typography>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.75 }}>
<Typography
sx={{
fontFamily: FONTS.mono,
fontSize: '0.7rem',
letterSpacing: '0.12em',
textTransform: 'uppercase',
color: 'text.secondary',
}}
>
Reservations
</Typography>
<Tooltip
title={
<Box sx={{ maxWidth: 260 }}>
A short hold a user places on a miner's quoted rate before
sending funds. The reservation locks the rate and prevents other
users from claiming the same miner mid-swap.
</Box>
}
arrow
placement="right"
>
<IconButton size="small" sx={{ p: 0, color: 'text.secondary' }}>
<InfoOutlinedIcon sx={{ fontSize: 14 }} />
</IconButton>
</Tooltip>
</Box>
<Box
component="form"
onSubmit={submitSearch}
Expand Down
21 changes: 14 additions & 7 deletions src/components/dashboard/SwapTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useTheme,
} from '@mui/material';
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import { useAllSwaps } from '../../api';
import { useAllSwaps, useSwapDetail } from '../../api';
import { FONTS } from '../../theme';
import CopyableAddress from '../CopyableAddress';
import { SwapTrackerSkeleton } from './Skeletons';
Expand Down Expand Up @@ -63,17 +63,24 @@ const SwapTracker: React.FC = () => {
const [limit, setLimit] = useState(PAGE_SIZE);
const debouncedSearch = useDebounce(search, 300);

const { data: swaps, isLoading } = useAllSwaps({
search: debouncedSearch || undefined,
limit,
});
const idMatch = debouncedSearch.trim().match(/^#?(\d+)$/);
const exactSwapId = idMatch?.[1] ?? '';

const { data: detail, isLoading: detailLoading } = useSwapDetail(exactSwapId);
const { data: fuzzy, isLoading: fuzzyLoading } = useAllSwaps(
{ search: debouncedSearch || undefined, limit },
!exactSwapId,
);

const swaps = exactSwapId ? (detail?.swap ? [detail.swap] : []) : fuzzy;
const isLoading = exactSwapId ? detailLoading : fuzzyLoading;

// Reset limit when search changes
React.useEffect(() => {
setLimit(PAGE_SIZE);
}, [debouncedSearch]);

const hasMore = swaps?.length === limit;
const hasMore = !exactSwapId && swaps?.length === limit;
const scrollRef = useRef<HTMLDivElement>(null);

const handleScroll = useCallback(() => {
Expand Down Expand Up @@ -122,7 +129,7 @@ const SwapTracker: React.FC = () => {

<TextField
size="small"
placeholder="Search by transaction ID or address..."
placeholder="Search by transaction ID (#N) or address..."
value={search}
onChange={(e) => setSearch(e.target.value)}
sx={{
Expand Down
Loading