Skip to content
Permalink
Browse files

fix(settings): incorrect autopilot saving

  • Loading branch information...
korhaliv committed Apr 8, 2019
1 parent 95a742b commit 19f0cbf71f20e5fe3e58fbd5560ccdae5a9786bd
Showing with 25 additions and 10 deletions.
  1. +3 −3 renderer/components/Home/AutopilotAllocation.js
  2. +22 −7 renderer/components/Home/WalletLauncher.js
@@ -5,14 +5,14 @@ import { asField } from 'informed'
import PropTypes from 'prop-types'
import { BasicRange, BasicInput } from 'components/UI'

const AutopilotAllocation = ({ fieldState, fieldApi, initialValue, sliderWidthNumber }) => {
const AutopilotAllocation = ({ fieldState, fieldApi, sliderWidthNumber }) => {
return (
<Flex alignItems="center" justifyContent="flex-end">
<BasicRange
field="autopilotAllocation"
fieldApi={fieldApi}
fieldState={fieldState}
id="autopilotAllocation"
initialValue={initialValue}
max="100"
min="0"
ml="auto"
@@ -21,6 +21,7 @@ const AutopilotAllocation = ({ fieldState, fieldApi, initialValue, sliderWidthNu
/>
<BasicInput
css={{ 'text-align': 'right' }}
field="autopilotAllocation"
fieldApi={fieldApi}
fieldState={fieldState}
id="autopilotAllocation"
@@ -39,7 +40,6 @@ const AutopilotAllocation = ({ fieldState, fieldApi, initialValue, sliderWidthNu
AutopilotAllocation.propTypes = {
fieldApi: PropTypes.object.isRequired,
fieldState: PropTypes.object.isRequired,
initialValue: PropTypes.object.isRequired,
sliderWidthNumber: PropTypes.number,
}

@@ -29,11 +29,26 @@ const autopilotDefaults = {
autopilotAllocation: allocation * 100,
}

// cleans up autopay settings if autopilot flag is turned
const formatAutopilot = values => {
const result = Object.assign({}, values)
if (!values.autopilot) {
// remove autopilot related fields if it's turned off
delete result.autopilotAllocation
delete result.autopilotMaxchannels
delete result.autopilotMaxchansize
delete result.autopilotMinchansize
delete result.autopilotMinconfs
delete result.autopilotPrivate
}
return result
}

// converts form format to db/lnd compatible format
const formToWalletFormat = values => {
const result = Object.assign({}, values)
const { autopilotAllocation } = result
if (autopilotAllocation) {
const result = Object.assign({}, formatAutopilot(values))
const { autopilot, autopilotAllocation } = result
if (autopilot && autopilotAllocation) {
// result expects the autopilot allocation to be a decimal.
result.autopilotAllocation = autopilotAllocation / 100
}
@@ -42,9 +57,9 @@ const formToWalletFormat = values => {

// converts db/lnd format to form compatible format
const walletToFormFormat = values => {
const result = Object.assign({}, values)
const { autopilotAllocation } = result
if (autopilotAllocation) {
const result = Object.assign({}, formatAutopilot(values))
const { autopilot, autopilotAllocation } = result
if (autopilot && autopilotAllocation) {
// Lnd expects the autopilot allocation to be in [0..100]
result.autopilotAllocation = autopilotAllocation * 100
}
@@ -321,7 +336,7 @@ class WalletLauncher extends React.Component {
}
// local node
return !unsafeShallowCompare(
clean(Object.assign({}, { autopilot: false }, formToWalletFormat(autopilotDefaults), wallet)),
clean(formatAutopilot(Object.assign({}, { autopilot: false }, autopilotDefaults, wallet))),
clean(
formToWalletFormat(
Object.assign({}, { autopilot: false }, autopilotDefaults, formState.values)

0 comments on commit 19f0cbf

Please sign in to comment.
You can’t perform that action at this time.