on c6f53ef help sign in
bridge/src/components/NetworkingKeys.js
116 lines 3.2 kB history raw
1import React from 'react';
2import { Grid, Flex, H5, Text } from 'indigo-react';
3import { Just, Nothing } from 'folktale/maybe';
5import { formatDotsWithTime } from 'lib/dateFormat';
6import { segmentNetworkKey, CURVE_ZERO_ADDR } from 'lib/keys';
8import { usePointCache } from 'store/pointCache';
10const chainKeyProp = name => d =>
11 d[name] === CURVE_ZERO_ADDR ? Nothing() : Just(d[name]);
13const renderNetworkKey = key => {
14 const segments = segmentNetworkKey(key);
16 if (!segments) {
17 return 'Unset';
18 }
20 return segments.join('\n');
21};
23export default function NetworkingKeys({ point }) {
24 const { getDetails, getRekeyDate } = usePointCache();
26 const details = getDetails(point);
28 const hasKeys = details.matchWith({
29 Nothing: () => false,
30 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
31 // we actually don't mind the default NaN behavior of parseInt here,
32 // since NaN > 0 === false and that's a reasonable result
33 });
35 const renderNetworkKeySection = (title, key) => (
36 <>
37 <Grid.Item full as={H5} className="mt3 gray4">
38 {title}
39 </Grid.Item>
40 {key.matchWith({
41 Nothing: () => (
42 <Grid.Item full as="code" className="f5 mono gray4">
43 Unset
44 </Grid.Item>
45 ),
46 Just: ({ value: key }) => (
47 <>
48 <Grid.Item full as="code" className="f5 mono wrap">
49 0x
50 </Grid.Item>
51 <Grid.Item full as="code" className="f5 mono wrap">
52 {renderNetworkKey(key)}
53 </Grid.Item>
54 </>
55 ),
56 })}
57 </>
58 );
60 const renderDetail = (title, value) => (
61 <Flex.Item as={Flex} col>
62 <Flex.Item as={H5} className="gray4">
63 {title}
64 </Flex.Item>
65 {value.matchWith({
66 Nothing: () => (
67 <Flex.Item as={Text} className="f5 gray4">
68 Unset
69 </Flex.Item>
70 ),
71 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
72 })}
73 </Flex.Item>
74 );
76 return (
77 <>
78 {renderNetworkKeySection(
79 'Authentication',
80 details.chain(chainKeyProp('authenticationKey'))
81 )}
82 {renderNetworkKeySection(
83 'Encryption',
84 details.chain(chainKeyProp('encryptionKey'))
85 )}
86 <Grid.Item full as={Flex} row justify="between" className="mt3">
87 {renderDetail(
88 'Revision',
89 details.map(d => d.keyRevisionNumber)
90 )}
91 {renderDetail(
92 'Continuity Era',
93 details.map(d => d.continuityNumber)
94 )}
95 {renderDetail(
96 'Crypto Suite Ver.',
97 details.map(d => d.cryptoSuiteVersion)
98 )}
99 </Grid.Item>
100 {/* TODO: retrieve last rekeydate, if possible? */}
101 {hasKeys && (
102 <Grid.Item full as={Flex} row justify="between" className="mt3">
103 {renderDetail(
104 'Last Set',
105 getRekeyDate(point).map(date =>
106 date.matchWith({
107 Ok: r => formatDotsWithTime(r.value),
108 Error: () => 'No date available',
109 })
110 )
111 )}
112 </Grid.Item>
113 )}
114 </>
115 );