import React from 'react'
import { Row, Col, H2, H4 } from '../../components/Base'
import { ETH_ZERO_ADDR, eqAddr } from '../../lib/wallet'
const NULL_KEY =
'0x0000000000000000000000000000000000000000000000000000000000000000'
const renderAddress = (addr) =>
eqAddr(addr, ETH_ZERO_ADDR)
?
{ '(not set)' }
:
{ addr.slice(0, 14) }
{ addr.slice(14, 28) }
{ addr.slice(28) }
const renderNetworkKey = (hex) => {
const sl = i => hex.slice(i, i + 4)
const rowFrom = i => `${sl(i)}.${sl(i + 4)}.${sl(i + 8)}.${sl(i + 12)}`
return (
hex === NULL_KEY
?
{ '(not set)' }
:
{ hex.slice(0, 2) }
{ rowFrom(2) }
{ rowFrom(18) }
{ rowFrom(34) }
{ rowFrom(50) }
)
}
const KeysAndMetadata = (props) => {
const { pointDetails } = props
return (
{ 'Ownership and Proxy Addresses' }
{ 'Owner' }
{
pointDetails.matchWith({
Nothing: () => ,
Just: (deets) => renderAddress(deets.value.owner)
})
}
{ 'Transfer Proxy' }
{
pointDetails.matchWith({
Nothing: () => ,
Just: (deets) => renderAddress(deets.value.transferProxy)
})
}
{ 'Spawn Proxy' }
{
pointDetails.matchWith({
Nothing: () => ,
Just: (deets) => renderAddress(deets.value.spawnProxy)
})
}
{ 'Mgmt Proxy' }
{
pointDetails.matchWith({
Nothing: () => ,
Just: (deets) => renderAddress(deets.value.managementProxy)
})
}
)
}
const UrbitNetworking = props => {
const { pointDetails } = props
const booted = pointDetails.matchWith({
Nothing: _ => false,
Just: (details) => details.value.keyRevisionNumber > 0
})
const body =
!booted
?
{ '(not set)' }
:
{ 'Authentication' }
{
pointDetails.matchWith({
Nothing: () => ,
Just: (deets) =>
renderNetworkKey(deets.value.authenticationKey)
})
}
{ 'Encryption' }
{
pointDetails.matchWith({
Nothing: () => ,
Just: (deets) =>
renderNetworkKey(deets.value.encryptionKey)
})
}
{ 'Revision' }
{
pointDetails.matchWith({
Nothing: () => '-',
Just: (deets) => deets.value.keyRevisionNumber
})
}
{ 'Continuity era' }
{
pointDetails.matchWith({
Nothing: () => '-',
Just: (deets) => deets.value.continuityNumber
})
}
{ 'Crypto suite version' }
{
pointDetails.matchWith({
Nothing: () => '-',
Just: (deets) => deets.value.cryptoSuiteVersion
})
}
return (
{ 'Public Keys' }
{ body }
)
}
export default KeysAndMetadata