-
Notifications
You must be signed in to change notification settings - Fork 3
/
Card.tsx
369 lines (341 loc) · 11.8 KB
/
Card.tsx
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import { Box, Button, styled, useTheme } from "@mui/material";
import { t } from "i18next";
import { FunctionComponent, SVGProps, useEffect, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { details } from "src/commons/routers";
import { getShortHash } from "src/commons/utils/helper";
import DynamicEllipsisText from "src/components/DynamicEllipsisText";
import Card from "src/components/commons/Card";
import CustomTooltip from "src/components/commons/CustomTooltip";
import InfoSolidIcon from "src/components/commons/InfoSolidIcon";
import { LockedTimelock, OpenTimeLock, SigNative } from "src/commons/resources";
import DesPlutusVersion from "./DesPlutusVersion";
const NativeScriptCard: React.FC<{ data: NativeScriptsList; hasBeforeAndAfter: boolean }> = ({ data }) => {
const theme = useTheme();
const containerRef = useRef<HTMLDivElement>(null);
const [isOverflowing, setIsOverflowing] = useState(false);
const [isCloseAllTooltip, setIsCloseAllTooltip] = useState(false);
useEffect(() => {
const container = containerRef.current;
if (container) {
const isOverflowingHorizontally = container?.scrollWidth > container?.clientWidth;
setIsOverflowing(isOverflowingHorizontally);
}
}, [isOverflowing]);
useEffect(() => {
const onCloseWhenChangeTab = () => {
if (document.visibilityState === "visible") {
setIsCloseAllTooltip(true);
}
};
document.addEventListener("visibilitychange", onCloseWhenChangeTab);
return () => {
document.removeEventListener("visibilitychange", onCloseWhenChangeTab);
};
}, []);
return (
<Item>
<Box p={2} height={"100%"} display={"block"} component={Link} to={details.nativeScriptDetail(data.scriptHash)}>
<Row>
<Title>{t("common.scriptHash")}: </Title>
<Box width={"calc(100% - 100px)"} color={`${theme.palette.primary.main} !important`}>
<DynamicEllipsisText customTruncateFold={[4, 4]} value={data.scriptHash || ""} isTooltip />
</Box>
</Row>
<Row>
<Title width={"100%"}>{t("nativeScript.policy")}: </Title>
<Value>
<Box mt={1} display={"flex"} flexWrap={"wrap"}>
<TimeLockChip isOpen={data.isOpen} />
<MultiSigChip isMultiSig={data.isMultiSig} />
</Box>
</Value>
</Row>
<Row>
<Title>{t("nativeScript.assetHolders")}: </Title>
<Value>{data.numberOfAssetHolders || 0}</Value>
</Row>
<Row>
<Title>{t("nativeScript.tokens")}: </Title>
<Value>{data.numberOfTokens || 0}</Value>
</Row>
<Row>
{data.tokens &&
data.tokens.map((item, index) => {
return (
<Box
component={isOverflowing ? CustomTooltip : Box}
closeTooltip={isCloseAllTooltip}
setIsCloseTooltip={() => setIsCloseAllTooltip(true)}
key={index}
title={isOverflowing ? item.displayName || getShortHash(item.fingerprint) || "" : null}
>
<Link to={details.token(item.fingerprint)}>
<Chip
pl={`${item.metadata && item.metadata.logo ? "4px" : 1} !important`}
mb={1}
maxWidth={"130px !important"}
>
<Box display={"flex"} alignItems={"center"} height={"100%"}>
{item.metadata && item.metadata.logo && (
<Box
height={23}
mr={1}
width={23}
borderRadius={"50%"}
sx={{
backgroundImage: `url(${item?.metadata?.logo})`,
backgroundPosition: "center",
backgroundSize: "contain",
backgroundRepeat: "no-repeat"
}}
/>
)}
<Box
overflow={"hidden"}
textOverflow={"ellipsis"}
ref={containerRef}
sx={{
textWrap: "nowrap"
}}
>
{item.displayName || getShortHash(item.fingerprint, 10, 6) || ""}
</Box>
</Box>
</Chip>
</Link>
</Box>
);
})}
{(data.numberOfTokens || 0) > (data.tokens || []).length && (
<Box
display={"block"}
height={"100%"}
component={Link}
p={1}
mb={1}
fontSize={14}
to={details.nativeScriptDetail(data.scriptHash, "token")}
color={`${theme.palette.primary.main} !important`}
>
{t("glossary.more")}
</Box>
)}
{!data.tokens && (
<Box
textAlign={"center"}
fontSize={16}
lineHeight={"18.75px"}
width={"100%"}
py={1}
color={theme.isDark ? theme.palette.secondary.light : theme.palette.secondary[600]}
>
{t("nativeScript.noToken")}
</Box>
)}
</Row>
</Box>
</Item>
);
};
const SmartContractCard: React.FC<{ data: ScriptSmartContracts }> = ({ data }) => {
const theme = useTheme();
const [openDesPlutusVersion, setOpenDesPlutusVersion] = useState(false);
const version = {
PLUTUSV1: "Plutus V1",
PLUTUSV2: "Plutus V2",
PLUTUSV3: "Plutus V3"
};
return (
<Item>
<Box p={2} height={"100%"} display={"block"} component={Link} to={details.smartContract(data.scriptHash)}>
<Row>
<Title>{t("common.scriptHash")}: </Title>
<Box width={"calc(100% - 100px)"} color={`${theme.palette.primary.main} !important`}>
<DynamicEllipsisText customTruncateFold={[4, 4]} value={data.scriptHash || ""} isTooltip />
</Box>
</Row>
<Row>
<Title>{t("Version")}: </Title>
<Value>
{data.scriptVersion ? version[data.scriptVersion] : ""}
<Box
component={Button}
m={0}
p={0}
width={24}
minWidth={24}
ml={1}
borderRadius={"50%"}
onClick={(event) => {
setOpenDesPlutusVersion(true);
event.stopPropagation();
event.preventDefault();
}}
>
<InfoSolidIcon />
</Box>
</Value>
</Row>
<Row>
<Title>{t("smartContract.totalTrx")}: </Title>
<Value>{data.txCount || 0}</Value>
</Row>
<Row>
<Title>{t("smartContract.trxPurpose")}: </Title>
{data.txPurposes && data.txPurposes.length > 0
? data.txPurposes.map((item, index) => {
return (
<Chip key={index}>
<Box display={"flex"} alignItems={"center"} height={"100%"}>
{item}
</Box>
</Chip>
);
})
: t("common.N/A")}
</Row>
</Box>
<DesPlutusVersion open={openDesPlutusVersion} onClose={() => setOpenDesPlutusVersion(false)} />
</Item>
);
};
export { SmartContractCard, NativeScriptCard };
const Item = styled(Card)`
width: 100%;
height: 100%;
background: ${({ theme }) => (theme.isDark ? theme.palette.secondary[100] : theme.palette.secondary[700])};
box-shadow: 2px 2px 10px 0px #43465633;
&:hover {
box-shadow: ${({ theme }) =>
theme.isDark ? ` 2px 2px 10px 0px ${theme.palette.secondary[100]}` : theme.shadow.cardHover};
}
`;
const Row = styled(Box)(({ theme }) => {
return {
display: "flex",
alignItems: "center",
flexWrap: "wrap",
color: theme.palette.secondary.light,
marginBottom: theme.spacing(1),
":last-child": {
marginBottom: 0
}
};
});
const Title = styled(Box)(({ theme }) => {
return {
fontSize: "16px",
fontWeight: "bold",
marginRight: theme.spacing(1)
};
});
const Value = styled(Box)(() => {
return {
fontSize: "16px"
};
});
const Chip = styled(Box)(({ theme }) => {
return {
padding: theme.spacing(0.5, 1),
border: `1px solid ${theme.palette.primary.main}`,
background: theme.isDark ? theme.palette.secondary[700] : theme.palette.primary[200],
borderRadius: theme.spacing(2),
marginRight: theme.spacing(0.5),
fontSize: 12,
maxWidth: "120px",
overflow: "hidden",
textOverflow: "ellipsis",
height: 20
};
});
export const TimeLockChip: React.FC<{ isOpen: boolean | null }> = ({ isOpen }) => {
if (isOpen) {
return <ChipContainer Icon={OpenTimeLock} message="Open" variant="success" />;
}
return <ChipContainer Icon={LockedTimelock} message="Locked" variant="warning" />;
};
export const MultiSigChip: React.FC<{ isMultiSig: boolean }> = ({ isMultiSig }) => {
if (isMultiSig) {
return <ChipContainer Icon={SigNative} message="Multi-Sig" variant="info" />;
}
return <ChipContainer Icon={SigNative} message="Single-Sig" variant="info" />;
};
export const ChipContainer: React.FC<{
Icon?: string | FunctionComponent<SVGProps<SVGSVGElement>>;
message?: string | JSX.Element;
titleTooltip?: string;
variant?: "success" | "warning" | "info" | "error" | "gray";
messageColor?: string;
}> = ({ Icon, message, variant, titleTooltip, messageColor }) => {
const theme = useTheme();
const color = (variant?: "success" | "warning" | "info" | "error" | "gray") => {
switch (variant) {
case "success":
return theme.palette.success[700];
case "info":
return theme.isDark ? theme.palette.primary[500] : theme.palette.primary.main;
case "warning":
return theme.palette.warning[700];
case "error":
return theme.palette.error[700];
case "gray":
return theme.palette.secondary[600];
default:
return theme.palette.success[700];
}
};
const backgroundColor = (variant?: "success" | "warning" | "info" | "error" | "gray") => {
switch (variant) {
case "success":
return theme.palette.success[100];
case "info":
return theme.palette.primary[200];
case "warning":
return theme.palette.warning[100];
case "error":
return theme.palette.error[100];
case "gray":
return theme.isDark ? theme.palette.secondary[100] : theme.palette.primary[100];
default:
return theme.palette.success[100];
}
};
return (
<CustomTooltip title={titleTooltip || ""}>
<Chip
pl={`${Icon ? "4px" : 1} !important`}
mb={1}
bgcolor={`${backgroundColor(variant)} !important`}
borderColor={`${color(variant)} !important`}
>
<Box display={"flex"} alignItems={"center"} height={"100%"}>
{Icon && (
<Box
height={23}
mr={1}
width={23}
borderRadius={"50%"}
bgcolor={`${color(variant)} !important`}
display={"flex"}
alignItems={"center"}
justifyContent={"center"}
>
<Icon />
</Box>
)}
<Box
overflow={"hidden"}
textOverflow={"ellipsis"}
color={({ palette }) => messageColor || palette.secondary.light}
sx={{
textWrap: "nowrap"
}}
>
{message}
</Box>
</Box>
</Chip>
</CustomTooltip>
);
};