mirror of https://github.com/lukechilds/polar.git
jamaljsr
5 years ago
9 changed files with 184 additions and 30 deletions
@ -0,0 +1,45 @@ |
|||
import React from 'react'; |
|||
import { BitcoinNode, LightningNode, Status } from 'types'; |
|||
import { StatusBadge } from 'components/common'; |
|||
import DetailsList, { DetailValues } from 'components/common/DetailsList'; |
|||
import SidebarCard from '../SidebarCard'; |
|||
|
|||
interface Props { |
|||
bitcoinNode: BitcoinNode; |
|||
lightningNode: LightningNode; |
|||
} |
|||
|
|||
const Backend: React.FC<Props> = ({ bitcoinNode, lightningNode }) => { |
|||
const backendDetails: DetailValues = [ |
|||
{ label: 'Name', value: bitcoinNode.name }, |
|||
{ label: 'Implementation', value: bitcoinNode.implementation }, |
|||
{ label: 'Version', value: `v${bitcoinNode.version}` }, |
|||
{ |
|||
label: 'Status', |
|||
value: ( |
|||
<StatusBadge status={bitcoinNode.status} text={Status[bitcoinNode.status]} /> |
|||
), |
|||
}, |
|||
]; |
|||
|
|||
const lightningDetails: DetailValues = [ |
|||
{ label: 'Name', value: lightningNode.name }, |
|||
{ label: 'Implementation', value: lightningNode.implementation }, |
|||
{ label: 'Version', value: `v${lightningNode.version}` }, |
|||
{ |
|||
label: 'Status', |
|||
value: ( |
|||
<StatusBadge status={lightningNode.status} text={Status[lightningNode.status]} /> |
|||
), |
|||
}, |
|||
]; |
|||
|
|||
return ( |
|||
<SidebarCard title="Blockchain Backend Connection"> |
|||
<DetailsList title="Lightning Node" details={lightningDetails} /> |
|||
<DetailsList title="Bitcoin Node" details={backendDetails} /> |
|||
</SidebarCard> |
|||
); |
|||
}; |
|||
|
|||
export default Backend; |
@ -0,0 +1,45 @@ |
|||
import React from 'react'; |
|||
import { ILink } from '@mrblenny/react-flow-chart'; |
|||
import { LightningNode, Status } from 'types'; |
|||
import { LinkProperties } from 'utils/chart'; |
|||
import { format } from 'utils/units'; |
|||
import { DetailsList, StatusBadge } from 'components/common'; |
|||
import { DetailValues } from 'components/common/DetailsList'; |
|||
import SidebarCard from '../SidebarCard'; |
|||
|
|||
interface Props { |
|||
link: ILink; |
|||
from: LightningNode; |
|||
to: LightningNode; |
|||
} |
|||
|
|||
const Channel: React.FC<Props> = ({ link, from, to }) => { |
|||
const { fromBalance, toBalance, capacity, status } = link.properties as LinkProperties; |
|||
|
|||
const channelDetails: DetailValues = [ |
|||
{ label: 'Status', value: status }, |
|||
{ label: 'Capacity', value: `${format(capacity)} sats` }, |
|||
{ label: 'Source Balance', value: `${format(fromBalance)} sats` }, |
|||
{ label: 'Destination Balance', value: `${format(toBalance)} sats` }, |
|||
]; |
|||
|
|||
const [fromDetails, toDetails] = [from, to].map(node => [ |
|||
{ label: 'Name', value: node.name }, |
|||
{ label: 'Implementation', value: node.implementation }, |
|||
{ label: 'Version', value: `v${node.version}` }, |
|||
{ |
|||
label: 'Status', |
|||
value: <StatusBadge status={node.status} text={Status[node.status]} />, |
|||
}, |
|||
]); |
|||
|
|||
return ( |
|||
<SidebarCard title="Channel Details"> |
|||
<DetailsList details={channelDetails} /> |
|||
<DetailsList title="Source Node" details={fromDetails} /> |
|||
<DetailsList title="Destination Node" details={toDetails} /> |
|||
</SidebarCard> |
|||
); |
|||
}; |
|||
|
|||
export default Channel; |
@ -0,0 +1,39 @@ |
|||
import React from 'react'; |
|||
import { ILink } from '@mrblenny/react-flow-chart'; |
|||
import { Network } from 'types'; |
|||
import { LinkProperties } from 'utils/chart'; |
|||
import Backend from './Backend'; |
|||
import Channel from './Channel'; |
|||
|
|||
interface Props { |
|||
link: ILink; |
|||
network: Network; |
|||
} |
|||
|
|||
const LinkDetails: React.FC<Props> = ({ link, network }) => { |
|||
let cmp = <div>You've somehow managed to select an invalid link</div>; |
|||
|
|||
const { bitcoin, lightning } = network.nodes; |
|||
const { type } = link.properties as LinkProperties; |
|||
switch (type) { |
|||
case 'backend': |
|||
const bitcoinNode = bitcoin.find(n => n.name === link.to.nodeId); |
|||
const lightningNode = lightning.find(n => n.name === link.from.nodeId); |
|||
if (bitcoinNode && lightningNode) { |
|||
cmp = <Backend bitcoinNode={bitcoinNode} lightningNode={lightningNode} />; |
|||
} |
|||
break; |
|||
case 'open-channel': |
|||
case 'pending-channel': |
|||
const from = lightning.find(n => n.name === link.from.nodeId); |
|||
const to = lightning.find(n => n.name === link.to.nodeId); |
|||
if (from && to) { |
|||
cmp = <Channel link={link} from={from} to={to} />; |
|||
} |
|||
break; |
|||
} |
|||
|
|||
return cmp; |
|||
}; |
|||
|
|||
export default LinkDetails; |
Loading…
Reference in new issue