Skip to content

Commit 1f91773

Browse files
authored
Merge pull request #81 from valory-xyz/mohan/gas-and-trading-balance
feat: gas and trading balance update
2 parents d4cacab + 49e2d8b commit 1f91773

File tree

3 files changed

+93
-10
lines changed

3 files changed

+93
-10
lines changed
+85-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,99 @@
1-
import { QuestionCircleTwoTone } from '@ant-design/icons';
2-
import { Tooltip, Typography } from 'antd';
1+
import { ArrowUpOutlined, QuestionCircleTwoTone } from '@ant-design/icons';
2+
import { Spin, Tooltip, Typography } from 'antd';
3+
import { useMemo } from 'react';
4+
import styled from 'styled-components';
35

4-
import { balanceFormat } from '@/common-util/numberFormatters';
6+
import { COLOR } from '@/constants';
57
import { useBalance } from '@/hooks';
68

79
import { CardSection } from '../styled/CardSection';
810

11+
const { Text } = Typography;
12+
13+
const Dot = styled.span`
14+
position: relative;
15+
display: inline-block;
16+
width: 8px;
17+
height: 8px;
18+
border-radius: 50%;
19+
margin-right: 8px;
20+
border: 2px solid #ffffff;
21+
box-shadow:
22+
rgb(0 0 0 / 7%) 0px 2px 4px 0px,
23+
rgb(0 0 0 / 3%) 0px 0px 4px 2px;
24+
`;
25+
const EmptyDot = styled(Dot)`
26+
background-color: ${COLOR.RED};
27+
`;
28+
const FineDot = styled(Dot)`
29+
background-color: ${COLOR.GREEN_2};
30+
`;
31+
const LowDot = styled(Dot)`
32+
background-color: ${COLOR.PURPLE};
33+
`;
34+
35+
const BalanceStatus = () => {
36+
const { isLoaded, totalEthBalance } = useBalance();
37+
38+
const status = useMemo(() => {
39+
if (!totalEthBalance || totalEthBalance === 0) {
40+
return { statusName: 'Empty', StatusComponent: EmptyDot };
41+
}
42+
43+
if (totalEthBalance < 0.1) {
44+
return { statusName: 'Low', StatusComponent: LowDot };
45+
}
46+
47+
return { statusName: 'Fine', StatusComponent: FineDot };
48+
}, [totalEthBalance]);
49+
50+
if (!isLoaded) {
51+
return <Spin />;
52+
}
53+
54+
const { statusName, StatusComponent } = status;
55+
return (
56+
<>
57+
<StatusComponent />
58+
<Text>{statusName}</Text>
59+
</>
60+
);
61+
};
62+
63+
const TooltipContent = styled.div`
64+
font-size: 77.5%;
65+
a {
66+
margin-top: 6px;
67+
display: inline-block;
68+
}
69+
`;
70+
971
export const MainGasBalance = () => {
10-
const { totalEthBalance } = useBalance();
1172
return (
1273
<CardSection justify="space-between" border>
13-
<Typography.Text type="secondary" strong>
74+
<Text>
1475
Gas and trading balance&nbsp;
15-
<Tooltip title="Gas balance is the amount of XDAI you have to pay for transactions.">
76+
<Tooltip
77+
title={
78+
<TooltipContent>
79+
Your agent uses this balance to pay for transactions and other
80+
trading activity on-chain.
81+
<br />
82+
{/* TODO: ask link */}
83+
<a href="https://docs.openlaw.io/olas/olas-eth" target="_blank">
84+
Track activity on blockchain explorer{' '}
85+
<ArrowUpOutlined style={{ rotate: '45deg' }} />
86+
</a>
87+
</TooltipContent>
88+
}
89+
>
1690
<QuestionCircleTwoTone />
1791
</Tooltip>
18-
</Typography.Text>
19-
<Typography.Text strong>
20-
{balanceFormat(totalEthBalance, 2)} XDAI&nbsp;
21-
</Typography.Text>
92+
</Text>
93+
94+
<Text strong>
95+
<BalanceStatus />
96+
</Text>
2297
</CardSection>
2398
);
2499
};

frontend/constants/color.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export const COLOR = {
33
GREEN_2: '#00F422',
44
PURPLE: '#722ed1',
55
BLUE: '#1677FF',
6+
ORANGE: '#FAAD14',
67
};

frontend/styles/globals.scss

+7
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ button, input, select, textarea, .ant-input-suffix {
2323
-webkit-app-region: no-drag;
2424
}
2525

26+
// antd overrides
2627
.ant-card-head {
2728
-webkit-app-region: drag;
2829
}
2930

31+
.ant-alert {
32+
.anticon {
33+
margin-top: 3px;
34+
}
35+
}
36+
3037
.antd-card {
3138
background-color: white;
3239
overflow-y: scroll;

0 commit comments

Comments
 (0)