-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStrategy.tsx
More file actions
104 lines (91 loc) · 3.13 KB
/
Copy pathStrategy.tsx
File metadata and controls
104 lines (91 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { NA } from '@agent-ui-monorepo/util-constants-and-types';
import { InfoCircleOutlined } from '@ant-design/icons';
import { Avatar, Card, Col, Flex, Row, Skeleton, Tooltip, Typography } from 'antd';
import { useMemo } from 'react';
import { COLOR } from '../../constants/colors';
import { PROTOCOLS_MAP, TRADING_TYPE_MAP } from '../../constants/textMaps';
import { usePortfolio } from '../../hooks/usePortfolio';
import { SelectedProtocol } from '../../types';
import { Pill } from '../../ui/Pill';
import { agentName, normalizeProtocol } from '../../utils/agentMap';
const { Title, Text } = Typography;
const TradingStrategyTitle = () => (
<Title level={5} style={{ marginBottom: 0, marginTop: 4 }} type="secondary">
Trading strategy
<Tooltip
title={`Your ${agentName} agent’s strategy sets the threshold parameters that guide its investment decisions. Each strategy comes with a predefined set of thresholds that shape your agent’s activity.`}
>
<InfoCircleOutlined style={{ marginLeft: 6 }} />
</Tooltip>
</Title>
);
const OperatingProtocolsTitle = () => (
<Title level={5} style={{ marginBottom: 0, marginTop: 4 }} type="secondary">
Operating protocols
<Tooltip title="Operating protocols are the protocols your agent uses to allocate funds and manage investments.">
<InfoCircleOutlined style={{ marginLeft: 6 }} />
</Tooltip>
</Title>
);
const Loader = () => <Skeleton.Input style={{ width: 100 }} active size="small" />;
const StrategyContent = () => {
const { isLoading, data } = usePortfolio();
const operatingProtocols = useMemo(() => {
if (!data?.selected_protocols) return [];
return data.selected_protocols.map((protocol: SelectedProtocol) => {
const displayProtocol = normalizeProtocol(protocol);
return (
<Avatar
key={displayProtocol}
size={36}
src={PROTOCOLS_MAP[displayProtocol].logo}
style={{ border: `1px solid ${COLOR.lightGrey}`, padding: 6 }}
/>
);
});
}, [data?.selected_protocols]);
return (
<Row>
<Col md={12} xs={24}>
<Flex vertical gap={8} align="self-start">
<TradingStrategyTitle />
{isLoading ? (
<Loader />
) : !data?.trading_type ? (
NA
) : (
<Pill
type={data.trading_type === 'risky' ? 'danger' : 'primary'}
size="large"
style={{ marginLeft: 0 }}
>
{TRADING_TYPE_MAP[data.trading_type]}
</Pill>
)}
</Flex>
</Col>
<Col md={12} xs={24}>
<Flex vertical gap={8} align="self-start">
<OperatingProtocolsTitle />
{isLoading ? (
<Loader />
) : operatingProtocols.length === 0 ? (
<Text type="secondary">No protocols</Text>
) : (
<Flex gap={8} align="center">
{operatingProtocols}
</Flex>
)}
</Flex>
</Col>
</Row>
);
};
/**
* Trading strategy and protocols
*/
export const Strategy = () => (
<Card className="card-gradient">
<StrategyContent />
</Card>
);