forked from LN-Zap/zap-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract LndConnectionStringEditor component
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters