-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSystemChat.tsx
More file actions
91 lines (81 loc) · 2.74 KB
/
Copy pathSystemChat.tsx
File metadata and controls
91 lines (81 loc) · 2.74 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
import { NA } from '@agent-ui-monorepo/util-constants-and-types';
import { ArrowRightOutlined } from '@ant-design/icons';
import { Flex, Typography } from 'antd';
import { CSSProperties, ReactNode, useCallback } from 'react';
import { COLOR } from '../../constants/colors';
import { PROTOCOLS_MAP, TRADING_TYPE_MAP } from '../../constants/textMaps';
import { SelectedProtocol, TradingType } from '../../types';
import { Pill } from '../../ui/Pill';
import { normalizeProtocol } from '../../utils/agentMap';
const { Text } = Typography;
const SystemContainerStyles: CSSProperties = {
width: '100%',
marginTop: 0,
padding: '8px 16px',
backgroundColor: COLOR.lightGrey,
borderRadius: 8,
};
type SystemMessageProps = {
type?: 'strategy' | 'protocols';
label: string;
width?: number;
children: ReactNode;
};
const SystemMessage = ({ type, label, children }: SystemMessageProps) => (
<Flex align="center" gap={12} style={SystemContainerStyles}>
<Text type="secondary" style={{ width: type === 'strategy' ? 174 : 200, flex: 'none' }}>
{label}
</Text>
<Flex gap={type === 'strategy' ? 12 : 8} wrap="wrap" align="center">
{children}
</Flex>
</Flex>
);
type TradingStrategyProps = { from: TradingType; to: TradingType };
/**
* Trading strategy update message.
*/
export const TradingStrategy = ({ from, to }: TradingStrategyProps) => {
const getType = useCallback((type: TradingType) => {
if (type === 'balanced') return 'primary';
if (type === 'risky') return 'danger';
}, []);
return (
<SystemMessage label="Trading strategy updated:" type="strategy">
<Pill type={getType(from)} size="large" style={{ marginLeft: 0 }}>
{TRADING_TYPE_MAP[from]}
</Pill>
{to && (
<>
<ArrowRightOutlined />
<Pill type={getType(to)} size="large" style={{ marginLeft: 0 }}>
{TRADING_TYPE_MAP[to]}
</Pill>
</>
)}
</SystemMessage>
);
};
type OperatingProtocolsProps = { protocols: SelectedProtocol[] };
/**
* Operating protocols update message.
*/
export const OperatingProtocols = ({ protocols }: OperatingProtocolsProps) => (
<SystemMessage label="Operating protocols updated:" type="protocols">
{protocols.length === 0
? NA
: protocols.map((protocol) => {
const displayProtocol = normalizeProtocol(protocol);
return (
<Pill size="large" key={displayProtocol} style={{ marginLeft: 0, paddingRight: 16 }}>
<img
src={PROTOCOLS_MAP[displayProtocol].logo}
alt={displayProtocol}
style={{ width: 18, height: 18 }}
/>
{PROTOCOLS_MAP[displayProtocol].name}
</Pill>
);
})}
</SystemMessage>
);