From a577cdf05a06d8f235bc4b937f58a8e8684b1b5c Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sat, 3 Nov 2018 12:02:09 +0100 Subject: [PATCH 1/2] fix(wallet): improve fee estimate presentation --- app/components/Pay/PaySummaryLightning.js | 31 ++++++++++++------- app/components/Pay/PaySummaryOnChain.js | 4 +-- app/components/Pay/messages.js | 9 +++--- app/lib/utils/crypto.js | 6 ++-- .../PaySummaryLightning.spec.js.snap | 10 ++++-- .../PaySummaryOnchain.spec.js.snap | 2 +- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/app/components/Pay/PaySummaryLightning.js b/app/components/Pay/PaySummaryLightning.js index 77556042..d39dbd9a 100644 --- a/app/components/Pay/PaySummaryLightning.js +++ b/app/components/Pay/PaySummaryLightning.js @@ -78,6 +78,23 @@ class PaySummaryLightning extends React.PureComponent { const fiatAmount = satoshisToFiat(satoshis, currentTicker[fiatCurrency].last) const nodeAlias = getNodeAlias(payeeNodeKey, nodes) + // Select an appropriate fee message... + // Default to unknown. + 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) { + feeMessage = messages.fee_less_than_1 + } + // Otherwise, if we have both a min and max fee that are different, present the fee range. + else if (minFee !== null && maxFee !== null && minFee !== maxFee) { + feeMessage = messages.fee_range + } + // Finally, if we at least have a max fee then present it as upto that amount. + else if (maxFee) { + feeMessage = messages.fee_upto + } + return ( @@ -108,7 +125,7 @@ class PaySummaryLightning extends React.PureComponent { - {} + {} @@ -127,10 +144,8 @@ class PaySummaryLightning extends React.PureComponent { - ) : minFee === null || maxFee === null ? ( - ) : ( - + feeMessage && ) } /> @@ -141,13 +156,7 @@ class PaySummaryLightning extends React.PureComponent { left={} right={ - {cryptoCurrencyTicker} - {!isQueryingRoutes && - maxFee && ( - - (+ {maxFee} msats) - - )} + {cryptoCurrencyTicker} } /> diff --git a/app/components/Pay/PaySummaryOnChain.js b/app/components/Pay/PaySummaryOnChain.js index 9799f320..97ccc439 100644 --- a/app/components/Pay/PaySummaryOnChain.js +++ b/app/components/Pay/PaySummaryOnChain.js @@ -122,11 +122,11 @@ class PaySummaryOnChain extends React.Component { ) : !fee ? ( - + ) : ( - {fee} satoshis + {fee} satoshis () diff --git a/app/components/Pay/messages.js b/app/components/Pay/messages.js index 173a8134..25458593 100644 --- a/app/components/Pay/messages.js +++ b/app/components/Pay/messages.js @@ -15,11 +15,12 @@ export default defineMessages({ back: 'Back', send: 'Send', fee: 'Fee', - fee_range: 'between {minFee} and {maxFee} msat', - unknown: 'unknown', + fee_less_than_1: 'less than 1 satoshi', + fee_range: 'between {minFee} and {maxFee} satoshis', + fee_upto: 'up to {maxFee} satoshi', + fee_unknown: 'unknown', + fee_per_byte: 'per byte', amount: 'Amount', - per_byte: 'per byte', - upto: 'up to', total: 'Total', memo: 'Memo', description: diff --git a/app/lib/utils/crypto.js b/app/lib/utils/crypto.js index 39b3a74d..bd327c1a 100644 --- a/app/lib/utils/crypto.js +++ b/app/lib/utils/crypto.js @@ -150,13 +150,13 @@ export const getNodeAlias = (pubkey, nodes = []) => { /** * Given a list of routest, find the minimum fee. * @param {QueryRoutesResponse} routes - * @return {Number} minimum fee. + * @return {Number} minimum fee rounded up to the nearest satoshi. */ export const getMinFee = (routes = []) => { if (!routes || !routes.length) { return null } - return routes.reduce((min, b) => Math.min(min, b.total_fees_msat), routes[0].total_fees_msat) + return routes.reduce((min, b) => Math.min(min, b.total_fees), routes[0].total_fees) } /** @@ -168,7 +168,7 @@ export const getMaxFee = routes => { if (!routes || !routes.length) { return null } - return routes.reduce((max, b) => Math.max(max, b.total_fees_msat), routes[0].total_fees_msat) + return routes.reduce((max, b) => Math.max(max, b.total_fees), routes[0].total_fees) } /** diff --git a/test/unit/components/Pay/__snapshots__/PaySummaryLightning.spec.js.snap b/test/unit/components/Pay/__snapshots__/PaySummaryLightning.spec.js.snap index 2b7e6a7c..56a39e9c 100644 --- a/test/unit/components/Pay/__snapshots__/PaySummaryLightning.spec.js.snap +++ b/test/unit/components/Pay/__snapshots__/PaySummaryLightning.spec.js.snap @@ -81,6 +81,7 @@ exports[`component.Form.PaySummaryLightning should render correctly 1`] = ` textAlign="right" > @@ -99,8 +100,13 @@ exports[`component.Form.PaySummaryLightning should render correctly 1`] = ` right={ } /> diff --git a/test/unit/components/Pay/__snapshots__/PaySummaryOnchain.spec.js.snap b/test/unit/components/Pay/__snapshots__/PaySummaryOnchain.spec.js.snap index 0849acec..9dfbcd42 100644 --- a/test/unit/components/Pay/__snapshots__/PaySummaryOnchain.spec.js.snap +++ b/test/unit/components/Pay/__snapshots__/PaySummaryOnchain.spec.js.snap @@ -99,7 +99,7 @@ exports[`component.Form.PaySummaryOnchain should render correctly 1`] = ` right={ } From 145899aa6bf2257dc653693921ec34a68b549b7e Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 2 Nov 2018 12:51:49 +0100 Subject: [PATCH 2/2] refactor: remove old pay forms --- app/components/Form/Pay/Pay.js | 217 ---------------------- app/components/Form/Pay/Pay.scss | 122 ------------- app/components/Form/Pay/index.js | 3 - app/components/Form/Pay/messages.js | 11 -- app/containers/Activity.js | 3 +- app/containers/App.js | 97 +--------- app/reducers/index.js | 2 - app/reducers/invoice.js | 7 - app/reducers/ipc.js | 9 +- app/reducers/payform.js | 268 ---------------------------- app/reducers/payment.js | 15 +- app/reducers/requestform.js | 2 +- app/reducers/transaction.js | 4 - test/unit/components/Form.spec.js | 41 +---- 14 files changed, 15 insertions(+), 786 deletions(-) delete mode 100644 app/components/Form/Pay/Pay.js delete mode 100644 app/components/Form/Pay/Pay.scss delete mode 100644 app/components/Form/Pay/index.js delete mode 100644 app/components/Form/Pay/messages.js delete mode 100644 app/reducers/payform.js diff --git a/app/components/Form/Pay/Pay.js b/app/components/Form/Pay/Pay.js deleted file mode 100644 index 0f7779f1..00000000 --- a/app/components/Form/Pay/Pay.js +++ /dev/null @@ -1,217 +0,0 @@ -import React, { Component } from 'react' -import PropTypes from 'prop-types' -import { btc } from 'lib/utils' -import PaperPlane from 'components/Icon/PaperPlane' -import ChainLink from 'components/Icon/ChainLink' -import AmountInput from 'components/AmountInput' -import { Button, Dropdown } from 'components/UI' -import { FormattedNumber, FormattedMessage, injectIntl } from 'react-intl' -import messages from './messages' -import styles from './Pay.scss' - -class Pay extends Component { - constructor(props) { - super(props) - this.paymentRequestInput = React.createRef() - } - - componentDidMount() { - const { setPayInput, setPayAmount } = this.props - - // Clear the form of any previous data. - setPayInput('') - setPayAmount('') - - // Focus the payment request input field. - this.paymentRequestInput.current.focus() - } - - componentDidUpdate(prevProps) { - const { - isLn, - payform: { payInput }, - fetchInvoice - } = this.props - - // If LN go retrieve invoice details - if (prevProps.payform.payInput !== payInput && isLn) { - fetchInvoice(payInput) - } - } - - render() { - const { - payform: { payInput, showErrors, invoice }, - nodes, - ticker, - isOnchain, - isLn, - currentAmount, - fiatAmount, - payFormIsValid: { errors, isValid }, - currencyFilters, - setPayAmount, - onPayAmountBlur, - setPayInput, - onPayInputBlur, - onPaySubmit, - setCurrency, - intl - } = this.props - - const displayNodeName = pubkey => { - const node = nodes.find(n => n.pub_key === pubkey) - - if (node && node.alias.length) { - return node.alias - } - - return pubkey ? pubkey.substring(0, 10) : '' - } - - const onCurrencyFilterClick = currency => { - if (!isLn) { - // change the input amount - setPayAmount(btc.convert(ticker.currency, currency, currentAmount)) - } - setCurrency(currency) - } - - return ( -
-
- -

- -

-
- -
-
-
- - - {isOnchain && ( - - - - - - - )} - {isLn && ( - - - {displayNodeName(invoice.destination)} ({invoice.description}) - - - )} - -
-
-