Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release #40

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
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
Next Next commit
feat: use ticker instead of debounce
belopash committed Nov 26, 2024
commit 4db0f144026696a50bc9fbf766a186550caa9db6
2 changes: 1 addition & 1 deletion src/api/subsquid-network-squid/settings-graphql.ts
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ export function useNetworkSummary() {
epoch: res.epoches.length ? res.epoches[0] : undefined,
};
},
refetchInterval: 6000, // a half of block time in l1
refetchInterval: 12_000, // block time in l1
},
);

14 changes: 14 additions & 0 deletions src/hooks/useTicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect, useState } from 'react';

export function useTicker<T>(ticker: () => T, ms: number = 1000) {
const [tickerValue, setTickerValue] = useState(ticker());

useEffect(() => {
const interval = setInterval(() => {
setTickerValue(ticker());
}, ms);
return () => clearInterval(interval);
}, [ms, ticker]);

return tickerValue;
}
9 changes: 6 additions & 3 deletions src/pages/DashboardPage/Summary.tsx
Original file line number Diff line number Diff line change
@@ -21,12 +21,12 @@ import {
} from '@mui/material';
import Grid from '@mui/material/Unstable_Grid2';
import { AreaChart, Area, ResponsiveContainer, Tooltip, TooltipProps } from 'recharts';
import { useDebounce } from 'use-debounce';

import { useNetworkSummary } from '@api/subsquid-network-squid';
import SquaredChip from '@components/Chip/SquaredChip';
import { HelpTooltip } from '@components/HelpTooltip';
import { Loader } from '@components/Loader';
import { useTicker } from '@hooks/useTicker';
import { useContracts } from '@network/useContracts';

export function ColumnLabel({ children, color }: PropsWithChildren<{ color?: string }>) {
@@ -112,8 +112,7 @@ function CurrentEpoch() {

const [epochEnd, setEpochEnd] = useState<number>(Date.now());

const [curTime] = useDebounce(Date.now(), 1000);

const curTime = useTicker(() => Date.now(), 1000);
const epochEndsIn = useMemo(() => relativeDateFormat(curTime, epochEnd), [curTime, epochEnd]);

useEffect(() => {
@@ -230,11 +229,15 @@ function AprChart({ data }: { data: { date: string; value: number }[] }) {
// contentStyle={{ transition: 'all ease-out 5500ms' }}
content={<AprTooltip />}
animationDuration={0}
// animationEasing="ease-out"
cursor={{
stroke: theme.palette.text.secondary,
strokeWidth: 2,
strokeDasharray: 6,
}}
cursorStyle={{
transition: 'all ease-out 300ms !important',
}}
defaultIndex={Math.max(data.length - 2, 0)}
active
allowEscapeViewBox={{ x: true }}
4 changes: 2 additions & 2 deletions src/pages/WorkersPage/WorkerStatus.tsx
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ import { dateFormat, relativeDateFormat } from '@i18n';
import { CircleRounded } from '@mui/icons-material';
import { Box, Chip as MaterialChip, Tooltip, chipClasses, styled } from '@mui/material';
import capitalize from 'lodash-es/capitalize';
import { useDebounce } from 'use-debounce';

import { WorkerStatus as Status, Worker } from '@api/subsquid-network-squid';
import { useTicker } from '@hooks/useTicker';

export const Chip = styled(MaterialChip)(({ theme }) => ({
// [`&.${chipClasses.colorSuccess}`]: {
@@ -55,7 +55,7 @@ export function WorkerStatusChip({
return { label: capitalize(worker.status), color: 'primary' };
}, [worker.jailReason, worker.jailed, worker.online, worker.status]);

const [curTimestamp] = useDebounce(Date.now(), 1000);
const curTimestamp = useTicker(() => Date.now(), 1000);
const timeLeft = useMemo(
() =>
worker.statusChangeAt ? relativeDateFormat(curTimestamp, worker.statusChangeAt) : undefined,
5 changes: 3 additions & 2 deletions src/pages/WorkersPage/WorkerUndelegate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo, useState } from 'react';

import { dateFormat, relativeDateFormat } from '@i18n';
import { percentFormatter, tokenFormatter } from '@lib/formatters/formatters';
import { percentFormatter } from '@lib/formatters/formatters';
import { fromSqd, toSqd } from '@lib/network';
import { Lock } from '@mui/icons-material';
import { LoadingButton } from '@mui/lab';
@@ -20,6 +20,7 @@ import { Form, FormDivider, FormikSelect, FormikTextInput, FormRow } from '@comp
import { HelpTooltip } from '@components/HelpTooltip';
import { SourceWalletOption } from '@components/SourceWallet';
import { useSquidHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useTicker } from '@hooks/useTicker';
import { useContracts } from '@network/useContracts';

import { EXPECTED_APR_TIP, useExpectedAprAfterDelegation } from './WorkerDelegate';
@@ -57,7 +58,7 @@ export function WorkerUndelegate({

const isLocked = useMemo(() => !!sources?.length && !sources?.some(d => !d.locked), [sources]);

const [curTimestamp] = useDebounce(Date.now(), 1000);
const curTimestamp = useTicker(() => Date.now(), 1000);
const { unlockedAt, timeLeft } = useMemo(() => {
const min = sources?.reduce(
(r, d) => {