|
1 | 1 | import React from 'react'; |
| 2 | +import styled from 'styled-components'; |
2 | 3 | import { Query } from 'react-apollo'; |
3 | | -import { Card, Typography, Divider } from 'antd'; |
| 4 | +import { Card, Typography, Divider, Table, Icon } from 'antd'; |
4 | 5 |
|
5 | 6 | import DashboardSpinner from '../../spinners/DashboardSpinner'; |
6 | 7 |
|
7 | 8 | import { useMarketsContextValue } from '../../../contexts/MarketsContext'; |
8 | 9 | import { useUserContextValue } from '../../../contexts/UserContext'; |
9 | 10 | import { useIntervalContext } from '../../../contexts/IntervalContext'; |
10 | 11 | import { TOP_GAINERS } from '../../../apollo/queries/dashboard'; |
| 12 | +import { truncateDecimals } from '../../../utils/numberUtils'; |
11 | 13 |
|
12 | | -const { Title } = Typography; |
| 14 | +const { Title, Text } = Typography; |
| 15 | +const StyledTable = styled(Table)` |
| 16 | + .ant-table-placeholder { |
| 17 | + border-bottom: 0; |
| 18 | + } |
| 19 | + .ant-table-row { |
| 20 | + td { |
| 21 | + border-bottom: 0; |
| 22 | + } |
| 23 | + } |
| 24 | +`; |
13 | 25 |
|
14 | 26 | const TopGainers = () => { |
15 | 27 | const { token }: any = useUserContextValue(); |
16 | 28 | const { interval }: any = useIntervalContext(); |
17 | | - const { market: exchange }: any = useMarketsContextValue(); |
| 29 | + const { market: { marketCode } }: any = useMarketsContextValue(); |
18 | 30 | return ( |
19 | 31 | <Query<any> |
20 | 32 | query={TOP_GAINERS} |
21 | | - variables={{ token, exchange, interval, criteria: 'priceChangeRatio' }} |
| 33 | + variables={{ token, exchange: marketCode, interval, criteria: 'priceChangeRatio' }} |
22 | 34 | > |
23 | 35 | {({ data, loading, error }) => { |
| 36 | + const dataSource = loading ? |
| 37 | + [] : data.topGainers.map(({ reit, priceChangeRatio }: any) => ({ |
| 38 | + name: reit.name, |
| 39 | + value: <span> |
| 40 | + <Icon type="arrow-up" className="mr-1" /> |
| 41 | + {truncateDecimals(priceChangeRatio * 100)}% |
| 42 | + </span>, |
| 43 | + })); |
| 44 | + const columns = [ |
| 45 | + { title: 'Reit Name', dataIndex: 'name', key: 'name' }, |
| 46 | + { |
| 47 | + title: 'Value', |
| 48 | + dataIndex: 'value', |
| 49 | + key: 'value', |
| 50 | + className: 'text-right', |
| 51 | + render: (text: string) => <Text style={{ color: '#52c41a' }}>{text}</Text>, |
| 52 | + }, |
| 53 | + ]; |
24 | 54 | return ( |
25 | | - <Card className="mb-2 mb-sm-3 p-3" bodyStyle={{ padding: 0 }}> |
| 55 | + <Card className="p-3" style={{ height: '100%' }} bodyStyle={{ padding: 0 }}> |
26 | 56 | <Title level={4}>Top Gainers</Title> |
27 | 57 | <Divider className="my-3" /> |
28 | 58 | <DashboardSpinner isLoading={loading}> |
29 | | - Loading |
| 59 | + <StyledTable |
| 60 | + rowKey={(row: any) => row.name} |
| 61 | + size="middle" |
| 62 | + showHeader={false} |
| 63 | + pagination={false} |
| 64 | + dataSource={dataSource} |
| 65 | + columns={columns} |
| 66 | + /> |
30 | 67 | </DashboardSpinner> |
31 | 68 | </Card> |
32 | 69 | ); |
|
0 commit comments