mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
- Add centralized chain accessor module (lib/api/luxnet/chains.ts) exposing all 14 chain VMs (C/X/P/A/B/D/G/I/K/O/Q/R/T/Z) plus utility APIs - Refactor pchain/client.ts to re-export from centralized module - Wire DEX page to use DexVMAPI (getStats, getPools, getMarkets) with demo data fallback when D-Chain RPC is unavailable - Add B-Chain bridge API module (lib/api/bchain/) using BridgeVMAPI (getSignerSetInfo, getWaitlist) for signer set stats - Update Bridge page to show live bridge signer count from B-Chain - Fix stale E2E tests: use >= minimum thresholds instead of exact counts (block/tx counts grow over time), use describe blocks
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import React from 'react';
|
|
|
|
import type { BridgeOverviewStats } from './types';
|
|
|
|
import { getBChain } from 'lib/api/luxnet/chains';
|
|
|
|
const BRIDGE_STALE_TIME_MS = 60_000;
|
|
const BRIDGE_QUERY_KEY = 'bchain:bridgeData' as const;
|
|
|
|
const EMPTY_STATS: BridgeOverviewStats = {
|
|
signerCount: 0,
|
|
threshold: 0,
|
|
epoch: 0,
|
|
waitlistSize: 0,
|
|
};
|
|
|
|
async function fetchBridgeData(): Promise<BridgeOverviewStats> {
|
|
try {
|
|
const bchain = getBChain();
|
|
const [ signerSet, waitlist ] = await Promise.all([
|
|
bchain.getSignerSetInfo(),
|
|
bchain.getWaitlist(),
|
|
]);
|
|
|
|
return {
|
|
signerCount: signerSet.totalSigners ?? signerSet.signers?.length ?? 0,
|
|
threshold: signerSet.threshold ?? 0,
|
|
epoch: signerSet.epoch ?? 0,
|
|
waitlistSize: waitlist?.length ?? 0,
|
|
};
|
|
} catch { /* B-Chain RPC unavailable */ }
|
|
|
|
return EMPTY_STATS;
|
|
}
|
|
|
|
export interface UseBridgeDataResult {
|
|
readonly stats: BridgeOverviewStats;
|
|
readonly isLoading: boolean;
|
|
}
|
|
|
|
export function useBridgeData(): UseBridgeDataResult {
|
|
const query = useQuery({
|
|
queryKey: [ BRIDGE_QUERY_KEY ],
|
|
queryFn: fetchBridgeData,
|
|
staleTime: BRIDGE_STALE_TIME_MS,
|
|
});
|
|
|
|
const stats = React.useMemo(
|
|
() => query.data ?? EMPTY_STATS,
|
|
[ query.data ],
|
|
);
|
|
|
|
return {
|
|
stats,
|
|
isLoading: query.isLoading,
|
|
};
|
|
}
|