import React, { useCallback, useState } from 'react'; import { Nothing } from 'folktale/maybe'; import { Grid, Text, H5, Flex } from 'indigo-react'; import { usePointCursor } from 'store/pointCursor'; import { usePointCache } from 'store/pointCache'; import { useLocalRouter } from 'lib/LocalRouter'; import * as need from 'lib/need'; import { segmentNetworkKey } from 'lib/keys'; import { formatDotsWithTime } from 'lib/dateFormat'; import ViewHeader from 'components/ViewHeader'; import MiniBackButton from 'components/MiniBackButton'; import { GenerateButton, BootArvoButton, ForwardButton, } from 'components/Buttons'; import FooterButton from 'components/FooterButton'; import WarningBox from 'components/WarningBox'; import DownloadKeyfileButton from 'components/DownloadKeyfileButton'; const renderNetworkKey = key => { const segments = segmentNetworkKey(key); if (!segments) { return 'Unset'; } return segments.join('\n'); }; function useSetKeys() { const setting = false; const didSet = false; const setKeys = useCallback(async () => {}, []); return { setting, didSet, setKeys, }; } export default function AdminNetworkingKeys() { const { push, names, pop } = useLocalRouter(); const { pointCursor } = usePointCursor(); const { getDetails, getRekeyDate } = usePointCache(); const point = need.point(pointCursor); const details = getDetails(point); const hasKeys = details.matchWith({ Nothing: () => false, Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0, }); const [configuring, setConfiguring] = useState(false); const { setKeys, setting, didSet } = useSetKeys(); const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]); const configureTransaction = useCallback(() => setConfiguring(true), [ setConfiguring, ]); const inDefaultState = !configuring && !setting && !didSet; const renderTitle = () => { if (didSet) { return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.'; } if (setting) { return 'Setting Network Keys...'; } if (!hasKeys) { return 'Networking keys have not yet been set.'; } return 'Networking'; }; const renderButton = () => { if (didSet) { return ; } if (configuring || setting) { return ; } return ( {hasKeys ? 'Reset' : 'Set'} Networking Keys ); }; const renderNetworkKeySection = (title, key) => ( <> {title} {key.matchWith({ Nothing: () => ( Unset ), Just: ({ value: key }) => ( <> 0x {renderNetworkKey(key)} ), })} ); const renderDetail = (title, value) => ( {title} {value.matchWith({ Nothing: () => ( Unset ), Just: ({ value }) => {value}, })} ); const renderDetails = () => { return ( <> {renderNetworkKeySection( 'Authentication', details.map(d => d.authenticationKey) )} {renderNetworkKeySection( 'Encryption', details.map(d => d.encryptionKey) )} {renderDetail('Revision', details.map(d => d.keyRevisionNumber))} {renderDetail('Continuity Era', details.map(d => d.continuityNumber))} {renderDetail( 'Crypto Suite Ver.', details.map(d => d.cryptoSuiteVersion) )} {hasKeys && ( {renderDetail( 'Last Set', getRekeyDate(point).map(date => date.matchWith({ Ok: r => formatDotsWithTime(r.value), Error: () => Nothing(), }) ) )} )} ); }; return ( <> pop()} /> {renderTitle()} {inDefaultState && ( {hasKeys ? 'Here are your public keys that authenticate your Arvo.' : 'Set your networking keys to authenticate with Arvo.'} )} {didSet && ( You need this keyfile to authenticate with Arvo. )} {renderButton()} {inDefaultState && renderDetails()} {didSet && ( <> )} {inDefaultState && ( Relocate )} ); }