From 5f8ad0a54673bdc768ba3e8f666ebd2f585c5d37 Mon Sep 17 00:00:00 2001 From: tony-blockchain Date: Fri, 26 Oct 2018 00:18:18 +0300 Subject: [PATCH 1/2] fix(XLM): fixed send copies --- .../FirstStep/MaximumAmountLink/index.js | 9 +-- .../FirstStep/MaximumAmountLink/selectors.js | 19 +++++++ .../SendXlm/FirstStep/ModalIcon/index.js | 2 +- .../SendXlm/FirstStep/template.success.js | 8 +-- .../modals/SendXlm/FirstStep/validation.js | 20 +------ .../SendXlm/FirstStep/validationMessages.js | 34 +++-------- .../src/modals/XlmCreateAccountLearn/index.js | 2 +- .../src/modals/XlmReserveLearn/index.js | 57 ++++++------------- .../src/modals/XlmReserveLearn/selectors.js | 46 +++++++++++++++ 9 files changed, 98 insertions(+), 99 deletions(-) create mode 100644 packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/selectors.js create mode 100644 packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/selectors.js diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/index.js b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/index.js index 54fd91db666..c2c7861fefb 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/index.js @@ -1,9 +1,9 @@ import React from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' -import { FormattedMessage } from 'react-intl' import { actions } from 'data' +import { getData } from './selectors' import { Link } from 'blockchain-info-components' const MaximumAmountLink = props => ( @@ -12,10 +12,7 @@ const MaximumAmountLink = props => ( weight={300} onClick={props.actions.firstStepMaximumAmountClicked} > - + {`${props.effectiveBalance} XLM`} ) @@ -24,6 +21,6 @@ const mapDispatchToProps = dispatch => ({ }) export default connect( - undefined, + getData, mapDispatchToProps )(MaximumAmountLink) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/selectors.js b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/selectors.js new file mode 100644 index 00000000000..3cfd04fd163 --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/MaximumAmountLink/selectors.js @@ -0,0 +1,19 @@ +import { prop } from 'ramda' +import BigNumber from 'bignumber.js' + +import { Exchange } from 'blockchain-wallet-v4' + +export const getData = (state, props) => { + const fee = prop('fee', props) + const feeXlm = Exchange.convertXlmToXlm({ + value: fee, + fromUnit: 'STROOP', + toUnit: 'XLM' + }).value + const effectiveBalanceXlm = prop('effectiveBalanceXlm', props) + return { + effectiveBalance: new BigNumber(effectiveBalanceXlm) + .minus(feeXlm) + .toString() + } +} diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/ModalIcon/index.js b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/ModalIcon/index.js index a4c453e126a..f6a5b2247fc 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/ModalIcon/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/ModalIcon/index.js @@ -11,7 +11,7 @@ const ModalIcon = styled(Icon)` ` const ModalIconContainer = ({ showModal, className }) => ( - + ) const mapDispatchToProps = (dispatch, props) => ({ diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/template.success.js b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/template.success.js index 07304e96818..57a240f02a5 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/template.success.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/template.success.js @@ -31,7 +31,6 @@ import { balanceReserveAmount, invalidAmount, insufficientFunds, - maximumAmount, shouldError, shouldWarn } from './validation' @@ -193,12 +192,7 @@ const FirstStep = props => { component={XlmFiatConvertor} error={error} coin='XLM' - validate={[ - required, - invalidAmount, - insufficientFunds, - maximumAmount - ]} + validate={[required, invalidAmount, insufficientFunds]} /> diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validation.js b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validation.js index 31bb1472c27..b26121a7ca2 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validation.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validation.js @@ -4,7 +4,6 @@ import { path, prop } from 'ramda' import { Exchange, utils } from 'blockchain-wallet-v4/src' import { - MaximumAmountMessage, InsufficientFundsMessage, InvalidAmountMessage } from './validationMessages' @@ -72,10 +71,7 @@ export const balanceReserveAmount = (errors, allValues, props) => { toCurrency: currency, rates: prop('rates', props) }).value - if ( - !utils.xlm.overflowsFullBalance(valueStroop, effectiveBalance, reserve) && - utils.xlm.overflowsEffectiveBalance(valueStroop, effectiveBalance) - ) + if (utils.xlm.overflowsEffectiveBalance(valueStroop, effectiveBalance)) errors._error = { currency, message: RESERVE_ERROR, @@ -89,20 +85,6 @@ export const balanceReserveAmount = (errors, allValues, props) => { return errors } -export const maximumAmount = (value, allValues, props) => { - const valueXlm = prop('coin', value) - const valueStroop = Exchange.convertXlmToXlm({ - value: valueXlm, - fromUnit: 'XLM', - toUnit: 'STROOP' - }).value - const effectiveBalance = prop('effectiveBalance', props) - const reserve = prop('reserve', props) - if (utils.xlm.overflowsFullBalance(valueStroop, effectiveBalance, reserve)) - return - return undefined -} - export const shouldError = ({ values, nextProps, diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validationMessages.js b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validationMessages.js index 98b9cf9ce38..a0c2aabe0d1 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validationMessages.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SendXlm/FirstStep/validationMessages.js @@ -12,17 +12,6 @@ const { RESERVE_LEARN_MODAL } = model.components.sendXlm -const Wrapper = styled.div` - display: flex; - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - - > * { - margin: 0 0 0 2px; - } -` - const ErrorBanner = styled(Banner)` > span { display: none; @@ -43,16 +32,6 @@ export const InvalidAmountMessage = () => ( /> ) -export const MaximumAmountMessage = () => ( - - - - -) - export const ShouldCreateAccountMessage = props => ( ( export const ReserveMessage = props => ( - +
+ + {': '} + +
) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/XlmCreateAccountLearn/index.js b/packages/blockchain-wallet-v4-frontend/src/modals/XlmCreateAccountLearn/index.js index 795dbde9001..2f205a8146b 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/XlmCreateAccountLearn/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/XlmCreateAccountLearn/index.js @@ -65,7 +65,7 @@ class XlmCreateAccountLearn extends React.PureComponent {
diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/index.js b/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/index.js index 5bab4b2b680..b58e6042ef6 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/index.js @@ -1,13 +1,13 @@ import React from 'react' +import { compose } from 'redux' +import { connect } from 'react-redux' import PropTypes from 'prop-types' import { FormattedMessage } from 'react-intl' import styled from 'styled-components' -import { currencySymbolMap } from 'services/CoinifyService' +import { getData } from './selectors' import modalEnhancer from 'providers/ModalEnhancer' import { model } from 'data' -import { Exchange } from 'blockchain-wallet-v4/src' -import { BigNumber } from 'bignumber.js' import { Modal, @@ -52,46 +52,22 @@ const Row = styled.div` const Bold = styled.b` font-weight: 400; ` - -const convertXlmToFiat = (rates, currency) => amount => - Exchange.convertXlmToFiat({ - value: amount, - fromUnit: 'XLM', - toCurrency: currency, - rates: rates - }).value - class XlmCreateAccountLearn extends React.PureComponent { render () { const { position, total, close, + currencySymbol, + effectiveBalanceMinusFeeFiat, + effectiveBalanceMinusFeeXlm, + feeFiat, + feeXlm, + reserveFiat, reserveXlm, - rates, - effectiveBalanceXlm, - currency, - fee + totalAmountFiat, + totalAmountXlm } = this.props - const convertToFiat = convertXlmToFiat(rates, currency) - const totalAmountXlm = new BigNumber(effectiveBalanceXlm) - .add(reserveXlm) - .toString() - const totalAmountFiat = convertToFiat(totalAmountXlm) - const reserveFiat = convertToFiat(reserveXlm) - const feeXlm = Exchange.convertXlmToXlm({ - value: fee, - fromUnit: 'STROOP', - toUnit: 'XLM' - }).value - const feeFiat = convertToFiat(feeXlm) - const effectiveBalanceMinusFeeXlm = new BigNumber(effectiveBalanceXlm) - .minus(feeXlm) - .toString() - const effectiveBalanceMinusFeeFiat = convertToFiat( - effectiveBalanceMinusFeeXlm - ) - const currencySymbol = currencySymbolMap[currency] return ( @@ -113,14 +89,14 @@ class XlmCreateAccountLearn extends React.PureComponent {
@@ -204,6 +180,9 @@ XlmCreateAccountLearn.propTypes = { rates: PropTypes.object.isRequired } -export default modalEnhancer(model.components.sendXlm.RESERVE_LEARN_MODAL)( - XlmCreateAccountLearn +const enhance = compose( + modalEnhancer(model.components.sendXlm.RESERVE_LEARN_MODAL), + connect(getData) ) + +export default enhance(XlmCreateAccountLearn) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/selectors.js b/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/selectors.js new file mode 100644 index 00000000000..a1f653dd8ee --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/XlmReserveLearn/selectors.js @@ -0,0 +1,46 @@ +import { Exchange } from 'blockchain-wallet-v4/src' +import { BigNumber } from 'bignumber.js' +import { currencySymbolMap } from 'services/CoinifyService' + +const convertXlmToFiat = (rates, currency) => amount => + Exchange.convertXlmToFiat({ + value: amount, + fromUnit: 'XLM', + toCurrency: currency, + rates: rates + }).value + +export const getData = (state, props) => { + const { reserveXlm, rates, effectiveBalanceXlm, currency, fee } = props + const convertToFiat = convertXlmToFiat(rates, currency) + const totalAmountXlm = new BigNumber(effectiveBalanceXlm) + .add(reserveXlm) + .toString() + const totalAmountFiat = convertToFiat(totalAmountXlm) + const reserveFiat = convertToFiat(reserveXlm) + const feeXlm = Exchange.convertXlmToXlm({ + value: fee, + fromUnit: 'STROOP', + toUnit: 'XLM' + }).value + const feeFiat = convertToFiat(feeXlm) + const effectiveBalanceMinusFeeXlm = new BigNumber(effectiveBalanceXlm) + .minus(feeXlm) + .toString() + const effectiveBalanceMinusFeeFiat = convertToFiat( + effectiveBalanceMinusFeeXlm + ) + const currencySymbol = currencySymbolMap[currency] + + return { + currencySymbol, + effectiveBalanceMinusFeeFiat, + effectiveBalanceMinusFeeXlm, + feeFiat, + feeXlm, + reserveFiat, + reserveXlm, + totalAmountFiat, + totalAmountXlm + } +} From b9cad8bdf523aaa340bf897ab1463a6e4be06d7d Mon Sep 17 00:00:00 2001 From: tony-blockchain Date: Fri, 26 Oct 2018 00:22:57 +0300 Subject: [PATCH 2/2] fix(XLM): fixed rates on maximum click --- .../src/data/components/sendXlm/sagas.js | 3 +-- .../blockchain-wallet-v4/src/redux/common/xlm/selectors.js | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/sendXlm/sagas.js b/packages/blockchain-wallet-v4-frontend/src/data/components/sendXlm/sagas.js index 696a369fe65..be5a33dbb55 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/sendXlm/sagas.js +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/sendXlm/sagas.js @@ -116,9 +116,8 @@ export default ({ coreSagas }) => { const currency = (yield select( selectors.core.settings.getCurrency )).getOrFail('Can not retrieve currency.') - // TODO: update rates to xlm ticker const xlmRates = (yield select( - selectors.core.data.bitcoin.getRates + selectors.core.data.xlm.getRates )).getOrFail('Can not retrieve stellar rates.') const payment = (yield select(S.getPayment)).getOrElse({}) const effectiveBalance = prop('effectiveBalance', payment) diff --git a/packages/blockchain-wallet-v4/src/redux/common/xlm/selectors.js b/packages/blockchain-wallet-v4/src/redux/common/xlm/selectors.js index 1deb1418472..52cd4f0b27e 100644 --- a/packages/blockchain-wallet-v4/src/redux/common/xlm/selectors.js +++ b/packages/blockchain-wallet-v4/src/redux/common/xlm/selectors.js @@ -45,7 +45,6 @@ export const getAccountsInfo = state => { } // getWalletTransactions :: state -> Remote([ProcessedTx]) -// TODO: get xlm transactions export const getWalletTransactions = createDeepEqualSelector( [getAccounts, getLockboxXlmAccounts, getTransactions, getXlmTxNotes], (accountsR, lockboxAccountsR, pages, txNotesR) => {