-
Notifications
You must be signed in to change notification settings - Fork 295
/
MetadataValueView.tsx
76 lines (69 loc) · 1.78 KB
/
MetadataValueView.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
// @flow
import React from 'react';
import type {
MetadataBytes,
MetadataInteger,
MetadataList,
MetadataMap,
MetadataString,
MetadataValue,
} from '../../../../types/TransactionMetadata';
import styles from './TransactionMetadataView.scss';
/**
* NOTE: These components are currently not used because we simply
* JSON.stringify the metadata for transactions. This can be
* used as the basis for a more sophisticated implementation
* later on:
*/
function IntegerView({ value }: { value: MetadataInteger }) {
return <p>{value.int}</p>;
}
function StringView({ value }: { value: MetadataString }) {
return <p>{value.string}</p>;
}
function BytesView({ value }: { value: MetadataBytes }) {
return <p>{value.bytes}</p>;
}
function ListView({ value }: { value: MetadataList }) {
return (
<ol className={styles.list}>
{value.list.map((v, index) => (
// eslint-disable-next-line react/no-array-index-key
<li key={index}>
<MetadataValueView value={v} />
</li>
))}
</ol>
);
}
function MapView({ value }: { value: MetadataMap }) {
return (
<ol className={styles.map}>
{value.map.map((v, index) => (
// eslint-disable-next-line react/no-array-index-key
<li key={index}>
<MetadataValueView value={v.k} />: <MetadataValueView value={v.v} />
</li>
))}
</ol>
);
}
function MetadataValueView(props: { value: MetadataValue }) {
const { value } = props;
if (value.int) {
return <IntegerView value={value} />;
}
if (value.string) {
return <StringView value={value} />;
}
if (value.bytes) {
return <BytesView value={value} />;
}
if (value.list) {
return <ListView value={value} />;
}
if (value.map) {
return <MapView value={value} />;
}
return null;
}