-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtoken-plate.tsx
More file actions
144 lines (130 loc) · 4.09 KB
/
Copy pathtoken-plate.tsx
File metadata and controls
144 lines (130 loc) · 4.09 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React from 'react';
import styled from 'styled-components';
import { TokenType } from '@hooks/use-casper-token';
import {
AlignedFlexRow,
AlignedSpaceBetweenFlexRow,
FlexColumn,
SpacingSize,
getSpacingSize
} from '@libs/layout';
import { SvgIcon, Tooltip, Typography } from '@libs/ui/components';
import { truncateKey } from '@libs/ui/components/hash/utils';
const TokenAmountContainer = styled(FlexColumn)`
max-width: 300px;
`;
const TokenNameContainer = styled.div`
max-width: 200px;
`;
const ListItemContainer = styled(AlignedSpaceBetweenFlexRow)<{
chevron?: boolean;
clickable?: boolean;
}>`
cursor: ${({ clickable }) => (clickable ? 'pointer' : 'default')};
padding: ${({ chevron }) => (chevron ? '10px 12px 10px 16px' : '10px 16px')};
`;
const TokenDetailsContainer = styled(AlignedFlexRow)`
column-gap: ${getSpacingSize(SpacingSize.Tiny)};
row-gap: ${getSpacingSize(SpacingSize.None)};
`;
const LogoImg = styled.img`
width: 32px;
height: 32px;
`;
interface TokenPlateProps {
token: TokenType | null;
chevron?: boolean;
handleOnClick?: () => void;
}
export const TokenPlate = ({
token,
chevron,
handleOnClick
}: TokenPlateProps) => {
const tokenIconFormat = token?.icon?.split('.').pop()?.toLowerCase();
const isTokenIconSvg = tokenIconFormat === 'svg';
const nameTooltipTitle = token?.contractPackageHash ? (
<FlexColumn gap={SpacingSize.Tiny}>
<Typography type="captionRegular" overflowWrap>
{token.name}
</Typography>
<Typography type="captionHash" color="contentSecondary">
{truncateKey(token.contractPackageHash, { size: 'base' })}
</Typography>
</FlexColumn>
) : token?.name && token.name.length > 10 ? (
token.name
) : undefined;
return (
<ListItemContainer
chevron={chevron}
gap={SpacingSize.Small}
onClick={handleOnClick}
clickable={!!handleOnClick}
>
<AlignedFlexRow gap={SpacingSize.Medium}>
{isTokenIconSvg ? (
<SvgIcon src={token?.icon || ''} alt={token?.name} size={32} />
) : (
<LogoImg
src={token?.icon || ''}
alt={token?.name}
title={token?.name}
/>
)}
<FlexColumn>
<TokenNameContainer>
<Tooltip title={nameTooltipTitle} fullWidth overflowWrap>
<Typography type="bodySemiBold" ellipsis loading={!token?.name}>
{token?.name}
</Typography>
</Tooltip>
</TokenNameContainer>
<TokenAmountContainer>
<Tooltip
title={
(token?.amount && token.amount.length > 7) ||
(token?.symbol && token.symbol.length > 6)
? `${token?.amount} ${token?.symbol}`
: undefined
}
placement="bottomLeft"
overflowWrap
fullWidth
>
<TokenDetailsContainer wrap="wrap">
<Typography
type="captionHash"
ellipsis
loading={!token?.amount}
>
{token?.amount}
</Typography>
<Typography
type="captionHash"
color="contentSecondary"
ellipsis={!!(token?.symbol && token.symbol.length > 6)}
loading={!token?.symbol && token?.symbol !== ''}
>
{token?.symbol}
</Typography>
{(token?.name === 'Casper' || token?.amountFiat) && (
<Typography
type="captionRegular"
color="contentSecondary"
loading={!token?.amountFiat}
>
({token?.amountFiat})
</Typography>
)}
</TokenDetailsContainer>
</Tooltip>
</TokenAmountContainer>
</FlexColumn>
</AlignedFlexRow>
<AlignedFlexRow>
{chevron && <SvgIcon src="assets/icons/chevron.svg" size={16} />}
</AlignedFlexRow>
</ListItemContainer>
);
};