make progress bar smooth on bridge-in tab
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
4de736ea08
commit
b7823f19dd
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -47,11 +47,8 @@ import { networkAvgBlockSpeed } from "../../constants";
|
||||
|
||||
const DECIMALS_PREFIX = "bridge-in-decimals";
|
||||
|
||||
const BridgeStatusCard = ({ totalValidators, pendingValidators, tapestryDraft }) => {
|
||||
const BridgeStatusCard = ({ progressPercent, totalValidators, pendingValidators, tapestryDraft }) => {
|
||||
const theme = useTheme();
|
||||
const progressPercent = totalValidators > 0
|
||||
? (pendingValidators / totalValidators) * 100
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<Box mt="30px" sx={{ mb: { xs: "0px", md: "-30px" }}}>
|
||||
@ -91,6 +88,7 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
const { casperApi, client, account } = useUnstableProvider();
|
||||
const { gatekeepedApy } = useGatekeeperApy(chainId);
|
||||
|
||||
const [msSinceLastBlock, setMsSinceLastBlock] = useState(0);
|
||||
const [nextEraIn, setNextEraIn] = useState(null);
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
@ -164,6 +162,38 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
}
|
||||
);
|
||||
|
||||
const { data: attestationDelay } = useSWR(
|
||||
casperApi ? ['attestationDelay', casperApi] : null,
|
||||
() => casperApi.constants.GhostWeaver.AttestationDelay(),
|
||||
);
|
||||
|
||||
const { data: weavingDelay } = useSWR(
|
||||
casperApi ? ['weavingDelay', casperApi] : null,
|
||||
() => casperApi.constants.GhostWeaver.WeavingDelay(),
|
||||
);
|
||||
|
||||
const { data: currentBlockNumber } = useSWR(
|
||||
casperApi ? ['currentBlockNumber', casperApi] : null,
|
||||
() => casperApi.query.System.Number.getValue(),
|
||||
{
|
||||
refreshInterval: 12000,
|
||||
revalidateOnFocus: true
|
||||
}
|
||||
);
|
||||
|
||||
const { data: nextConsensusAttempt, error } = useSWR(
|
||||
casperApi ? ['nextConsensusAttempt', casperApi] : null,
|
||||
async () => {
|
||||
const key = BigInt(chainId);
|
||||
const res = await casperApi.query.GhostWeaver.NextConsensusAttemptBlocks.getValue(key);
|
||||
return res;
|
||||
},
|
||||
{
|
||||
refreshInterval: 12000,
|
||||
revalidateOnFocus: true
|
||||
}
|
||||
);
|
||||
|
||||
const { data: networkAttestations } = useSWR(
|
||||
casperApi ? ['networkAttestations', casperApi, chainId] : null,
|
||||
async () => {
|
||||
@ -358,6 +388,36 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setMsSinceLastBlock(0);
|
||||
|
||||
const startTime = Date.now();
|
||||
const interval = setInterval(() => {
|
||||
setMsSinceLastBlock(Date.now() - startTime);
|
||||
}, 500);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [currentBlockNumber]);
|
||||
|
||||
const progressPercent = useMemo(() => {
|
||||
if (!nextConsensusAttempt || !attestationDelay || !weavingDelay) return 5;
|
||||
|
||||
const total = tapestryDraft ? weavingDelay : attestationDelay;
|
||||
const end = tapestryDraft ? tapestryDraft.until : nextConsensusAttempt;
|
||||
|
||||
const remaining = end - currentBlockNumber;
|
||||
const passed = Number(total) - remaining;
|
||||
const progress = passed * 100 / Number(total);
|
||||
|
||||
// TODO
|
||||
const virtualBlocksPassed = Math.min(msSinceLastBlock / 12000, 1);
|
||||
const smoothBlocksPassed = passed + virtualBlocksPassed;
|
||||
|
||||
const smoothProgress = (smoothBlocksPassed * 100) / Number(total);
|
||||
|
||||
return Math.min(Math.max(smoothProgress, 3), 100);
|
||||
}, [currentBlockNumber, tapestryDraft, nextConsensusAttempt, msSinceLastBlock, attestationDelay, weavingDelay]);
|
||||
|
||||
return (
|
||||
<Box minHeight="calc(100vh - 43px)">
|
||||
<PageTitle name="GHOST Bridge-In" subtitle={`${bridgeNumbers} Bridge-In ${ghstSymbol ? ghstSymbol : "CSPR"} into ${bridgeNumbers} Stake\u00B2`} />
|
||||
@ -412,6 +472,7 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
</MetricCollection>
|
||||
|
||||
<BridgeStatusCard
|
||||
progressPercent={progressPercent}
|
||||
tapestryDraft={tapestryDraft}
|
||||
totalValidators={weaverAuthorities ? weaverAuthorities.length : 0}
|
||||
pendingValidators={
|
||||
|
||||
Loading…
Reference in New Issue
Block a user