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

Commit

Permalink
fix(wallet): present correct fee when no route
Browse files Browse the repository at this point in the history
Ensure fee rate is displayed as `unknown` if no routes are found.

Fix #3154
  • Loading branch information
mrfelton committed Nov 9, 2019
1 parent ff4e7ba commit 8b0a351
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
29 changes: 4 additions & 25 deletions renderer/components/Pay/PaySummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,16 @@ import { PAY_FORM_STEPS } from './constants'
import { getFeeRate } from './utils'

const PaySummary = props => {
const { amountInSats, formApi, isOnchain, lndTargetConfirmations } = props
const { amountInSats, formApi, isOnchain, lndTargetConfirmations, onchainFees, routes } = props
const formState = formApi.getState()
const { speed, payReq, isCoinSweep } = formState.values

/**
* getFee - Get the current per byte fee based on the form values.
*
* @returns {number} Fee rate for currently selected conf speed
*/
const getFee = () => {
const { formApi, onchainFees } = props
const formState = formApi.getState()
const { speed } = formState.values

return getFeeRate(onchainFees, speed)
}

if (isOnchain) {
return (
<PaySummaryOnChain
address={payReq}
amount={amountInSats}
fee={getFee()}
fee={getFeeRate(onchainFees, speed)}
isCoinSweep={isCoinSweep}
lndTargetConfirmations={lndTargetConfirmations}
mt={-3}
Expand All @@ -39,19 +26,11 @@ const PaySummary = props => {
)
}

const { routes } = props
let minFee = 0
let maxFeeInclusive = 0
if (routes.length) {
minFee = getMinFee(routes)
maxFeeInclusive = getMaxFeeInclusive(routes)
}

return (
<PaySummaryLightning
amount={amountInSats}
maxFee={maxFeeInclusive}
minFee={minFee}
maxFee={getMaxFeeInclusive(routes)}
minFee={getMinFee(routes)}
mt={-3}
payReq={payReq}
/>
Expand Down
2 changes: 1 addition & 1 deletion renderer/components/Pay/PaySummaryLightning.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PaySummaryLightning extends React.Component {
let feeMessage = messages.fee_unknown

// If thex max fee is 0 or 1 then show a message like "less than 1".
if (maxFee === 0 || maxFee === 1) {
if (maxFee >= 0 && maxFee < 1) {
feeMessage = messages.fee_less_than_1
}
// Otherwise, if we have both a min and max fee that are different, present the fee range.
Expand Down
4 changes: 2 additions & 2 deletions renderer/reducers/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const queryFees = (address, amountInSats) => async (dispatch, getState) =

dispatch({ type: QUERY_FEES_SUCCESS, onchainFees })
} catch (e) {
const error = get(e, 'response.statusText', e)
const error = get(e, 'response.statusText', e.message)
dispatch({ type: QUERY_FEES_FAILURE, error })
}
}
Expand All @@ -225,7 +225,7 @@ export const queryRoutes = (pubKey, amount) => async dispatch => {
})
dispatch({ type: QUERY_ROUTES_SUCCESS, routes })
} catch (e) {
dispatch({ type: QUERY_ROUTES_FAILURE })
dispatch({ type: QUERY_ROUTES_FAILURE, error: e.message })
}
}

Expand Down

0 comments on commit 8b0a351

Please sign in to comment.