Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(ui): cleanup route summary display
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Nov 7, 2020
1 parent c8721fb commit b9591f1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 46 deletions.
40 changes: 1 addition & 39 deletions renderer/components/Activity/PaymentModal/Htlc.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Flex } from 'rebass/styled-components'
import { useIntl } from 'react-intl'
import { CoinBig } from '@zap/utils/coin'
import { getDisplayNodeName } from 'reducers/payment/utils'
import { Truncate } from 'components/Util'
import { Text } from 'components/UI'
import { CryptoSelector, CryptoValue } from 'containers/UI'
import ArrowRight from 'components/Icon/ArrowRight'
import messages from './messages'

const HtlcHops = ({ hops, ...rest }) => {
const { formatMessage, formatNumber } = useIntl()
return (
<Flex {...rest} flexDirection="column">
{hops.map(hop => {
const displayName = getDisplayNodeName(hop)
const hasFee = CoinBig(hop.feeMsat).gt(0)
return (
<Flex
key={hop.pubKey}
alignItems="center"
className="hint--top-left"
data-hint={formatMessage(
{ ...messages[hasFee ? 'htlc_hop_fee' : 'htlc_hop_no_fee'] },
{ hopFee: formatNumber(hop.feeMsat), cryptoUnitName: 'msat' }
)}
justifyContent="flex-end"
my={1}
>
<Flex alignItems="center" color="gray" mx={2}>
<ArrowRight />
</Flex>
<Truncate maxlen={50} text={displayName} />
</Flex>
)
})}
</Flex>
)
}

HtlcHops.propTypes = {
hops: PropTypes.array.isRequired,
}
import HtlcHops from './HtlcHops'

const Htlc = ({ route, isAmountVisible = true, ...rest }) => {
const amountExcludingFees = CoinBig(route.totalAmt)
Expand Down
50 changes: 50 additions & 0 deletions renderer/components/Activity/PaymentModal/HtlcHops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Flex } from 'rebass/styled-components'
import { useIntl } from 'react-intl'
import { CoinBig } from '@zap/utils/coin'
import { getDisplayNodeName } from 'reducers/payment/utils'
import { Truncate } from 'components/Util'
import ArrowRight from 'components/Icon/ArrowRight'
import messages from './messages'

const HtlcHops = ({ hops, ...rest }) => {
const { formatMessage, formatNumber } = useIntl()
return (
<Flex {...rest} flexDirection="column">
{hops.map((hop, index) => {
const displayName = getDisplayNodeName(hop)
const hasFee = CoinBig(hop.feeMsat).gt(0)
const isLast = index === hops.length - 1
const multiHop = hops.length > 1
return (
<Flex
key={hop.pubKey}
alignItems="center"
className="hint--top-left"
color={isLast ? null : 'grey'}
data-hint={formatMessage(
{ ...messages[hasFee ? 'htlc_hop_fee' : 'htlc_hop_no_fee'] },
{ hopFee: formatNumber(hop.feeMsat), cryptoUnitName: 'msat' }
)}
justifyContent="flex-end"
my={1}
>
{multiHop && (
<Flex alignItems="center" color="gray" mx={2} opacity={isLast ? 1 : 0.5}>
<ArrowRight />
</Flex>
)}
<Truncate maxlen={50} text={displayName} />
</Flex>
)
})}
</Flex>
)
}

HtlcHops.propTypes = {
hops: PropTypes.array.isRequired,
}

export default HtlcHops
16 changes: 11 additions & 5 deletions renderer/components/Activity/PaymentModal/PaymentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class PaymentModal extends React.PureComponent {
const { item, intl, ...rest } = this.props
const memo = item && getTag(item.paymentRequest, 'description')
const htlcs = item.htlcs.filter(htlc => htlc.status === 'SUCCEEDED')
const isMpp = htlcs.length > 1
const isRouted = htlcs.filter(htlc => htlc.route.hops.length > 1).length > 0

return (
<Panel {...rest}>
Expand Down Expand Up @@ -109,12 +111,16 @@ class PaymentModal extends React.PureComponent {
}
/>

<Bar variant="light" />
{(isMpp || isRouted) && (
<>
<Bar variant="light" />

<DataRow
left={<FormattedMessage {...messages.htlc_title} />}
right={<Route htlcs={htlcs} />}
/>
<DataRow
left={<FormattedMessage {...messages.htlc_title} />}
right={<Route htlcs={htlcs} />}
/>
</>
)}
</Panel.Body>
</Panel>
)
Expand Down
1 change: 1 addition & 0 deletions renderer/components/Activity/PaymentModal/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export PaymentModal from './PaymentModal'
export Route from './Route'
export Htlc from './Htlc'
export HtlcHops from './HtlcHops'
4 changes: 2 additions & 2 deletions renderer/components/Pay/PaySummaryLightning.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BigArrowRight from 'components/Icon/BigArrowRight'
import { Bar, DataRow, Link, Spinner, Text, Tooltip } from 'components/UI'
import { CryptoSelector, CryptoValue, FiatValue } from 'containers/UI'
import { Truncate } from 'components/Util'
import { Htlc } from 'components/Activity/PaymentModal'
import { HtlcHops } from 'components/Activity/PaymentModal'
import messages from './messages'

const ConfigLink = ({ feeLimit, openModal, ...rest }) => (
Expand Down Expand Up @@ -161,7 +161,7 @@ class PaySummaryLightning extends React.Component {
</Box>
<Box width={5 / 11}>
{route ? (
<Htlc route={route} />
<HtlcHops hops={route.hops} isAmountVisible={false} />
) : (
<Text className="hint--bottom-left" data-hint={payeeNodeKey} textAlign="right">
<Truncate maxlen={nodeAlias ? 30 : 15} text={nodeAlias || payeeNodeKey} />
Expand Down

0 comments on commit b9591f1

Please sign in to comment.