-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d366bfb
commit 80d51b9
Showing
11 changed files
with
232 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { ApiOutlined, CloseOutlined, InboxOutlined } from '@ant-design/icons'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Button, Card, Collapse, Flex, Spin, Typography } from 'antd'; | ||
import { isEmpty, isNull } from 'lodash'; | ||
import { CSSProperties, ReactNode, useContext, useMemo } from 'react'; | ||
|
||
import { COLOR } from '@/constants/colors'; | ||
import { FIVE_SECONDS_INTERVAL } from '@/constants/intervals'; | ||
import { REACT_QUERY_KEYS } from '@/constants/react-query-keys'; | ||
import { NA } from '@/constants/symbols'; | ||
import { OnlineStatusContext } from '@/context/OnlineStatusProvider'; | ||
import { Pages } from '@/enums/Pages'; | ||
import { useElectronApi } from '@/hooks/useElectronApi'; | ||
import { usePageState } from '@/hooks/usePageState'; | ||
import { useService } from '@/hooks/useService'; | ||
import { useServices } from '@/hooks/useServices'; | ||
|
||
import { CardTitle } from '../Card/CardTitle'; | ||
|
||
const { Text } = Typography; | ||
|
||
const MIN_HEIGHT = 400; | ||
const ICON_STYLE: CSSProperties = { fontSize: 48, color: COLOR.TEXT_LIGHT }; | ||
const CURRENT_ACTIVITY_STYLE: CSSProperties = { | ||
background: 'linear-gradient(180deg, #FCFCFD 0%, #EEF0F7 100%)', | ||
}; | ||
|
||
const Container = ({ children }: { children: ReactNode }) => ( | ||
<Flex | ||
vertical | ||
gap={16} | ||
align="center" | ||
justify="center" | ||
style={{ height: MIN_HEIGHT }} | ||
> | ||
{children} | ||
</Flex> | ||
); | ||
|
||
const Loading = () => ( | ||
<Container> | ||
<Spin /> | ||
</Container> | ||
); | ||
|
||
const ErrorLoadingData = ({ refetch }: { refetch: () => void }) => ( | ||
<Container> | ||
<ApiOutlined style={ICON_STYLE} /> | ||
<Text type="secondary">Error loading data</Text> | ||
<Button onClick={refetch}>Try again</Button> | ||
</Container> | ||
); | ||
|
||
const NoData = () => ( | ||
<Container> | ||
<InboxOutlined style={ICON_STYLE} /> | ||
<Text type="secondary"> | ||
There's no previous agent activity recorded yet | ||
</Text> | ||
</Container> | ||
); | ||
|
||
export const AgentActivityPage = () => { | ||
const electronApi = useElectronApi(); | ||
const { isOnline } = useContext(OnlineStatusContext); | ||
const { goto } = usePageState(); | ||
|
||
const { selectedService } = useServices(); | ||
const { isServiceRunning } = useService(selectedService?.service_config_id); | ||
|
||
const { data, isLoading, isError, refetch } = useQuery({ | ||
queryKey: REACT_QUERY_KEYS.AGENT_ACTIVITY, | ||
queryFn: async () => { | ||
const result = await electronApi?.healthCheck?.(); | ||
if (result && 'error' in result) throw new Error(result.error); | ||
return result; | ||
}, | ||
select: (data) => { | ||
if (!data || !('response' in data) || !data.response) return null; | ||
|
||
// The latest activity should go at the top, so sort the rounds accordingly | ||
const rounds = [...(data.response?.rounds || [])].reverse(); | ||
const roundsInfo = data.response?.rounds_info; | ||
return { rounds, roundsInfo }; | ||
}, | ||
enabled: isServiceRunning, | ||
refetchOnWindowFocus: false, | ||
refetchInterval: (query) => { | ||
if (query.state.error) return false; // Stop refetching when there's an error | ||
return isOnline ? FIVE_SECONDS_INTERVAL : false; | ||
}, | ||
}); | ||
|
||
const activity = useMemo(() => { | ||
if (isLoading) return <Loading />; | ||
if (isError) return <ErrorLoadingData refetch={refetch} />; | ||
if (!isServiceRunning) return <NoData />; | ||
if (isNull(data) || isEmpty(data)) return <NoData />; | ||
|
||
const items = data.rounds.map((item, index) => { | ||
const isCurrent = index === 0; | ||
const roundName = data.roundsInfo?.[item]?.name || item; | ||
return { | ||
key: `${item}-${index}`, | ||
label: isCurrent ? ( | ||
<Flex vertical gap={4}> | ||
<Text type="secondary" className="text-xs"> | ||
Current activity | ||
</Text> | ||
<Text className="text-sm loading-ellipses">{roundName}</Text> | ||
</Flex> | ||
) : ( | ||
<Text className="text-sm">{roundName}</Text> | ||
), | ||
children: ( | ||
<Text | ||
type="secondary" | ||
className="text-sm" | ||
style={{ marginLeft: '26px' }} | ||
> | ||
{data.roundsInfo?.[item]?.description || NA} | ||
</Text> | ||
), | ||
style: isCurrent ? CURRENT_ACTIVITY_STYLE : undefined, | ||
}; | ||
}); | ||
|
||
return ( | ||
<Collapse | ||
items={items} | ||
bordered={false} | ||
style={{ background: 'transparent' }} | ||
/> | ||
); | ||
}, [data, isError, isLoading, isServiceRunning, refetch]); | ||
|
||
return ( | ||
<Card | ||
title={<CardTitle title="Agent activity" />} | ||
bordered={false} | ||
styles={{ body: { padding: '1px 0 24px' } }} | ||
extra={ | ||
<Button | ||
size="large" | ||
icon={<CloseOutlined />} | ||
onClick={() => goto(Pages.Main)} | ||
/> | ||
} | ||
> | ||
{activity} | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Button } from 'antd'; | ||
|
||
import { Pages } from '@/enums/Pages'; | ||
import { usePageState } from '@/hooks/usePageState'; | ||
|
||
export const WhatIsAgentDoing = () => { | ||
const { goto } = usePageState(); | ||
return ( | ||
<Button | ||
type="link" | ||
className="p-0 text-xs" | ||
onClick={() => goto(Pages.AgentActivity)} | ||
> | ||
What's my agent doing? | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ export enum Pages { | |
RewardsHistory, | ||
AddBackupWalletViaSafe, | ||
SwitchAgent, | ||
AgentActivity, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters