Skip to content

Commit

Permalink
feat: don't show circle when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed May 23, 2022
1 parent e3c961f commit fa832a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ export const ProgressToNextUpdate: React.FC<
useEffect(() => {
const id = setInterval(() => {
const time = calculateTime(updatedAt, timeToUpdate);
setValue(calculateTime(updatedAt, timeToUpdate));
if (time >= 100) {
setValue(0);
clearInterval(id);
return;
}
setValue(calculateTime(updatedAt, timeToUpdate));
}, 500);
}, 1000);
return () => clearInterval(id);
}, [timeToUpdate, updatedAt]);

useEffect(() => {
if (isLoading) {
setValue(0);
}
}, [isLoading]);

return (
<Box
sx={{
Expand Down
15 changes: 3 additions & 12 deletions packages/widget/src/components/SwapRoutes/SwapRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ import { useNavigate } from 'react-router-dom';
import { useCurrentRoute, useSwapRoutes } from '../../hooks';
import { routes } from '../../utils/routes';
import { CardContainer, CardTitle } from '../Card';
import { ProgressToNextUpdate } from '../ProgressToNextUpdate';
import { SwapRouteCard } from '../SwapRouteCard';
import { Stack } from './SwapRoutes.style';
import { SwapRoutesUpdateProgress } from './SwapRoutesUpdateProgress';

export const SwapRoutes: React.FC<BoxProps> = ({ mb }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const [currentRoute] = useCurrentRoute();
const {
routes: swapRoutes,
isLoading,
isFetching,
dataUpdatedAt,
refetchTime,
} = useSwapRoutes();
const { routes: swapRoutes, isLoading, isFetching } = useSwapRoutes();

const handleCardClick = useCallback(() => {
navigate(routes.swapRoutes);
Expand All @@ -34,10 +28,7 @@ export const SwapRoutes: React.FC<BoxProps> = ({ mb }) => {
return (
<CardContainer mb={mb}>
<CardTitle>{t('swap.routes')}</CardTitle>
<ProgressToNextUpdate
updatedAt={dataUpdatedAt}
timeToUpdate={refetchTime}
isLoading={isLoading || isFetching}
<SwapRoutesUpdateProgress
sx={{
position: 'absolute',
top: 16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import { ProgressToNextUpdate } from '../ProgressToNextUpdate';
export const SwapRoutesUpdateProgress: React.FC<BoxProps> = (props) => {
const { isLoading, isFetching, dataUpdatedAt, refetchTime } = useSwapRoutes();

if (isLoading) {
return null;
}

return (
<ProgressToNextUpdate
updatedAt={dataUpdatedAt}
timeToUpdate={refetchTime}
isLoading={isLoading || isFetching}
isLoading={isFetching}
{...props}
/>
);
Expand Down

0 comments on commit fa832a4

Please sign in to comment.