Skip to content

Commit

Permalink
fix: first reward notification shown many times
Browse files Browse the repository at this point in the history
  • Loading branch information
Atatakai authored and Atatakai committed Jul 17, 2024
1 parent fb7efcb commit c6c7082
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 5 additions & 1 deletion frontend/components/Main/MainNeedsFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const COVER_PREV_BLOCK_BORDER_STYLE = { marginTop: '-1px' };

const useNeedsFunds = () => {
const { getServiceTemplates } = useServiceTemplates();
const serviceTemplate = useMemo(() => getServiceTemplates()[0], []);

const serviceTemplate = useMemo(
() => getServiceTemplates()[0],
[getServiceTemplates],
);

const { storeState } = useStore();
const { safeBalance, totalOlasStakedBalance } = useBalance();
Expand Down
16 changes: 7 additions & 9 deletions frontend/components/Main/MainRewards.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InfoCircleOutlined } from '@ant-design/icons';
import { Button, Flex, Modal, Skeleton, Tag, Tooltip, Typography } from 'antd';
import Image from 'next/image';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';

import { useBalance } from '@/hooks/useBalance';
import { useElectronApi } from '@/hooks/useElectronApi';
Expand Down Expand Up @@ -73,30 +73,28 @@ const NotifyRewards = () => {

const [canShowNotification, setCanShowNotification] = useState(false);

const firstRewardRef = useRef<number>();

// hook to set the flag to show the notification
useEffect(() => {
if (!isEligibleForRewards) return;
if (!storeState) return;
if (storeState?.firstRewardNotificationShown) return;
if (!availableRewardsForEpochEth) return;

firstRewardRef.current = availableRewardsForEpochEth;
setCanShowNotification(true);
}, [
isEligibleForRewards,
availableRewardsForEpochEth,
showNotification,
storeState,
]);
}, [isEligibleForRewards, availableRewardsForEpochEth, storeState]);

// hook to show desktop app notification
useEffect(() => {
if (!canShowNotification) return;

showNotification?.(
'Your agent earned its first staking rewards!',
`Congratulations! Your agent just got the first reward for you! Your current balance: ${availableRewardsForEpochEth} OLAS`,
`Congratulations! Your agent just got the first reward for you! Your current balance: ${firstRewardRef.current} OLAS`,
);
}, [canShowNotification, availableRewardsForEpochEth, showNotification]);
}, [canShowNotification, showNotification]);

const closeNotificationModal = useCallback(() => {
setCanShowNotification(false);
Expand Down

0 comments on commit c6c7082

Please sign in to comment.