Skip to content

Commit

Permalink
refactor: extract LndConnectionStringEditor component
Browse files Browse the repository at this point in the history
  • Loading branch information
korhaliv committed Mar 7, 2019
1 parent 5ff15ce commit 618999f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions app/components/UI/LndConnectionStringEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Box, Flex } from 'rebass'
import { withFormApi } from 'informed'
import Padlock from 'components/Icon/Padlock'
import { LndConnectionStringInput, Toggle, Span, Label } from '.'

function LndConnectionStringEditor({ formApi, field, hideStringMessage, ...rest }) {
const isDisabled = formApi.getValue('hideLndConnectUri')

const getValue = isDisabled => {
// create obfuscated value if TextArea is disabled
if (isDisabled) {
const LND_CONNECT_PREFIX = 'lndconnect://'
const lndconnectUri = formApi.getValue(field) || ''
const lndconnectUriBody = lndconnectUri.substr(lndconnectUri.indexOf(LND_CONNECT_PREFIX))
// replace all chars with *
return { value: `${LND_CONNECT_PREFIX}${lndconnectUriBody.replace(/./g, '*')}` }
}
return {}
}

return (
<Box>
<LndConnectionStringInput
{...rest}
{...getValue(isDisabled)}
disabled={isDisabled}
field={field}
rows={12}
validateOnBlur
validateOnChange
required
/>
<Flex justifyContent="space-between" alignItems="center" mt={3}>
<Flex>
<Span color="gray" fontSize="s" mr={2}>
<Padlock />
</Span>
<Label htmlFor="private">{hideStringMessage}</Label>
</Flex>
<Flex>
<Toggle field="hideLndConnectUri" initialValue />
</Flex>
</Flex>
</Box>
)
}

LndConnectionStringEditor.propTypes = {
formApi: PropTypes.object.isRequired,
hideStringMessage: PropTypes.object.isRequired,
field: PropTypes.string.isRequired
}

export default withFormApi(LndConnectionStringEditor)
1 change: 1 addition & 0 deletions app/components/UI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export Label from './Label'
export LightningInvoiceInput from './LightningInvoiceInput'
export Link from './Link'
export LndConnectionStringInput from './LndConnectionStringInput'
export LndConnectionStringEditor from './LndConnectionStringEditor'
export MainContent from './MainContent'
export Message from './Message'
export Modal from './Modal'
Expand Down

0 comments on commit 618999f

Please sign in to comment.