Browse Source

Add rawValues in RequestAmount

master
Loëck Vézien 7 years ago
parent
commit
be7b8922e9
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 8
      src/components/RequestAmount/index.js
  2. 11
      src/components/base/FormattedVal/index.js
  3. 2
      src/components/modals/Receive/index.js
  4. 15
      src/components/modals/Send/Footer.js
  5. 39
      src/components/modals/Send/index.js

8
src/components/RequestAmount/index.js

@ -206,7 +206,13 @@ export class RequestAmount extends PureComponent<Props, State> {
this.setState({ this.setState({
value: newValue, value: newValue,
}) })
onChange(newValue) onChange({
values: newValue,
rawValues: {
left: Number(newValue.left) * 10 ** unit.left.magnitude,
right: Number(newValue.right),
},
})
} }
handleClickMax = () => { handleClickMax = () => {

11
src/components/base/FormattedVal/index.js

@ -22,10 +22,11 @@ type Props = {
unit?: Unit | null, unit?: Unit | null,
alwaysShowSign?: boolean, alwaysShowSign?: boolean,
showCode?: boolean, showCode?: boolean,
disableRounding?: boolean,
} }
function FormattedVal(props: Props) { function FormattedVal(props: Props) {
const { fiat, isPercent, alwaysShowSign, showCode, ...p } = props const { disableRounding, fiat, isPercent, alwaysShowSign, showCode, ...p } = props
let { val, unit } = props let { val, unit } = props
if (isUndefined(val)) { if (isUndefined(val)) {
@ -47,6 +48,7 @@ function FormattedVal(props: Props) {
} }
text = formatCurrencyUnit(unit, val, { text = formatCurrencyUnit(unit, val, {
alwaysShowSign, alwaysShowSign,
disableRounding,
showCode, showCode,
}) })
} }
@ -59,11 +61,12 @@ function FormattedVal(props: Props) {
} }
FormattedVal.defaultProps = { FormattedVal.defaultProps = {
unit: null,
isPercent: false,
alwaysShowSign: false, alwaysShowSign: false,
showCode: false, disableRounding: false,
fiat: null, fiat: null,
isPercent: false,
showCode: false,
unit: null,
} }
export default FormattedVal export default FormattedVal

2
src/components/modals/Receive/index.js

@ -88,7 +88,7 @@ class ReceiveModal extends PureComponent<Props, State> {
<RequestAmount <RequestAmount
account={account} account={account}
value={amount} value={amount}
onChange={this.handleChangeInput('amount')} onChange={v => this.handleChangeInput('amount')(v.values)}
/> />
</Box> </Box>
<ReceiveBox account={account} amount={amount.left} /> <ReceiveBox account={account} amount={amount.left} />

15
src/components/modals/Send/Footer.js

@ -18,17 +18,19 @@ type Props = {
amount: DoubleVal, amount: DoubleVal,
onNext: Function, onNext: Function,
canNext: boolean, canNext: boolean,
counterValue: string,
} }
function Footer({ account, amount, t, onNext, canNext }: Props) { function Footer({ account, amount, t, onNext, canNext, counterValue }: Props) {
return ( return (
<ModalFooter horizontal align="center"> <ModalFooter horizontal align="center">
<Box grow> <Box grow>
<Label>{t('send:totalSpent')}</Label> <Label>{t('send:totalSpent')}</Label>
<Box horizontal flow={2} align="center"> <Box horizontal flow={2} align="center">
<FormattedVal <FormattedVal
disableRounding
color="dark" color="dark"
val={amount.left * 10 ** account.unit.magnitude} val={amount.left}
unit={account.unit} unit={account.unit}
showCode showCode
/> />
@ -36,7 +38,14 @@ function Footer({ account, amount, t, onNext, canNext }: Props) {
<Text ff="Rubik" fontSize={3}> <Text ff="Rubik" fontSize={3}>
{'('} {'('}
</Text> </Text>
<FormattedVal color="grey" fontSize={3} val={amount.right} fiat="USD" showCode /> <FormattedVal
disableRounding
color="grey"
fontSize={3}
val={amount.right}
fiat={counterValue}
showCode
/>
<Text ff="Rubik" fontSize={3}> <Text ff="Rubik" fontSize={3}>
{')'} {')'}
</Text> </Text>

39
src/components/modals/Send/index.js

@ -1,6 +1,8 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import get from 'lodash/get' import get from 'lodash/get'
@ -9,6 +11,8 @@ import type { DoubleVal } from 'components/RequestAmount'
import { MODAL_SEND } from 'constants' import { MODAL_SEND } from 'constants'
import { getCounterValue } from 'reducers/settings'
import Breadcrumb from 'components/Breadcrumb' import Breadcrumb from 'components/Breadcrumb'
import Modal, { ModalBody, ModalTitle, ModalContent } from 'components/base/Modal' import Modal, { ModalBody, ModalTitle, ModalContent } from 'components/base/Modal'
@ -19,14 +23,22 @@ import StepConnectDevice from './02-step-connect-device'
import StepVerification from './03-step-verification' import StepVerification from './03-step-verification'
import StepConfirmation from './04-step-confirmation' import StepConfirmation from './04-step-confirmation'
const mapStateToProps = state => ({
counterValue: getCounterValue(state),
})
type Props = { type Props = {
t: T, t: T,
counterValue: string,
} }
type State = { type State = {
stepIndex: number, stepIndex: number,
isDeviceReady: boolean, isDeviceReady: boolean,
amount: DoubleVal, amount: {
values: DoubleVal,
rawValues: DoubleVal,
},
account: Account | null, account: Account | null,
recipientAddress: string, recipientAddress: string,
fees: number, fees: number,
@ -45,8 +57,14 @@ const INITIAL_STATE = {
account: null, account: null,
recipientAddress: '', recipientAddress: '',
amount: { amount: {
left: 0, values: {
right: 0, left: 0,
right: 0,
},
rawValues: {
left: 0,
right: 0,
},
}, },
fees: 0, fees: 0,
} }
@ -62,7 +80,7 @@ class SendModal extends PureComponent<Props, State> {
// informations // informations
if (stepIndex === 0) { if (stepIndex === 0) {
const { amount, recipientAddress } = this.state const { amount, recipientAddress } = this.state
return !!amount.left && !!recipientAddress && !!account return !!amount.rawValues.left && !!recipientAddress && !!account
} }
// connect device // connect device
@ -87,21 +105,23 @@ class SendModal extends PureComponent<Props, State> {
createChangeHandler = key => value => this.setState({ [key]: value }) createChangeHandler = key => value => this.setState({ [key]: value })
renderStep = acc => { renderStep = acc => {
const { stepIndex, account } = this.state const { stepIndex, account, amount, ...othersState } = this.state
const step = this._steps[stepIndex] const step = this._steps[stepIndex]
if (!step) { if (!step) {
return null return null
} }
const { Comp } = step const { Comp } = step
const stepProps = { const stepProps = {
...this.state, ...othersState,
amount: amount.values,
account: account || acc, account: account || acc,
} }
return <Comp onChange={this.createChangeHandler} {...stepProps} {...this.props} /> return <Comp onChange={this.createChangeHandler} {...stepProps} {...this.props} />
} }
render() { render() {
const { t } = this.props const { t, counterValue } = this.props
const { stepIndex, amount, account } = this.state const { stepIndex, amount, account } = this.state
return ( return (
@ -120,10 +140,11 @@ class SendModal extends PureComponent<Props, State> {
</ModalContent> </ModalContent>
{acc && ( {acc && (
<Footer <Footer
counterValue={counterValue}
canNext={canNext} canNext={canNext}
onNext={this.handleNextStep} onNext={this.handleNextStep}
account={acc} account={acc}
amount={amount} amount={amount.rawValues}
t={t} t={t}
/> />
)} )}
@ -135,4 +156,4 @@ class SendModal extends PureComponent<Props, State> {
} }
} }
export default translate()(SendModal) export default compose(connect(mapStateToProps), translate())(SendModal)

Loading…
Cancel
Save