Browse Source

Add ReceiveBox in Receive modal, and add posibility to set amount for QRCode

master
Loëck Vézien 7 years ago
parent
commit
a5e242bf32
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 9
      src/components/ReceiveBox.js
  2. 69
      src/components/modals/Receive.js

9
src/components/ReceiveBox.js

@ -10,6 +10,7 @@ import CopyToClipboard from 'components/base/CopyToClipboard'
import Text from 'components/base/Text' import Text from 'components/base/Text'
type Props = { type Props = {
amount?: string,
address: string, address: string,
} }
@ -41,10 +42,10 @@ const Action = styled(Box).attrs({
} }
` `
const ReceiveBox = ({ address }: Props) => ( const ReceiveBox = ({ amount, address }: Props) => (
<Box flow={3}> <Box flow={3}>
<Box align="center"> <Box align="center">
<QRCode size={150} data={address} /> <QRCode size={150} data={`bitcoin:${address}${amount ? `?amount=${amount}` : ''}`} />
</Box> </Box>
<Box align="center" flow={2}> <Box align="center" flow={2}>
<Text fontSize={1}>{'Current address'}</Text> <Text fontSize={1}>{'Current address'}</Text>
@ -72,4 +73,8 @@ const ReceiveBox = ({ address }: Props) => (
</Box> </Box>
) )
ReceiveBox.defaultProps = {
amount: undefined,
}
export default ReceiveBox export default ReceiveBox

69
src/components/modals/Receive.js

@ -1,14 +1,19 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent, Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import get from 'lodash/get' import get from 'lodash/get'
import { MODAL_RECEIVE } from 'constants' import { MODAL_RECEIVE } from 'constants'
import Box from 'components/base/Box'
import Button from 'components/base/Button'
import Input from 'components/base/Input'
import Label from 'components/base/Label'
import Modal, { ModalBody } from 'components/base/Modal' import Modal, { ModalBody } from 'components/base/Modal'
import Text from 'components/base/Text' import ReceiveBox from 'components/ReceiveBox'
import SelectAccount from 'components/SelectAccount' import SelectAccount from 'components/SelectAccount'
import Text from 'components/base/Text'
import type { Account as AccountType, T } from 'types/common' import type { Account as AccountType, T } from 'types/common'
@ -18,10 +23,12 @@ type Props = {
type State = { type State = {
account: AccountType | null, account: AccountType | null,
amount: string,
} }
const defaultState = { const defaultState = {
account: null, account: null,
amount: '',
} }
class ReceiveModal extends PureComponent<Props, State> { class ReceiveModal extends PureComponent<Props, State> {
@ -29,34 +36,64 @@ class ReceiveModal extends PureComponent<Props, State> {
...defaultState, ...defaultState,
} }
handleChangeAccount = account => { getAccount(data) {
this.setState({ account }) const { account } = this.state
return account || get(data, 'account')
} }
handleChangeInput = key => value =>
this.setState({
[key]: value,
})
handleClose = () => handleClose = () =>
this.setState({ this.setState({
...defaultState, ...defaultState,
}) })
render() { render() {
const { account } = this.state const { amount } = this.state
const { t } = this.props const { t } = this.props
return ( return (
<Modal <Modal
name={MODAL_RECEIVE} name={MODAL_RECEIVE}
onClose={this.handleClose} onClose={this.handleClose}
render={({ data, onClose }) => ( render={({ data, onClose }) => {
<ModalBody onClose={onClose} flow={3}> const account = this.getAccount(data)
<Text fontSize={4} color="steel"> return (
{t('receive.modalTitle')} <ModalBody onClose={onClose} flow={3}>
</Text> <Text fontSize={4} color="steel">
<SelectAccount {t('receive.modalTitle')}
value={account || get(data, 'account')} </Text>
onChange={this.handleChangeAccount} <Box flow={1}>
/> <Label>Account</Label>
</ModalBody> <SelectAccount value={account} onChange={this.handleChangeInput('account')} />
)} </Box>
{account &&
account.data && (
<Fragment>
<Box flow={1}>
<Label>Request amount</Label>
<Input
type="number"
min={0}
max={account.data.balance / 1e8}
onChange={this.handleChangeInput('amount')}
/>
</Box>
<ReceiveBox amount={amount} address={get(account, 'data.address', '')} />
</Fragment>
)}
<Box horizontal justify="center">
<Button primary onClick={onClose}>
Close
</Button>
</Box>
</ModalBody>
)
}}
/> />
) )
} }

Loading…
Cancel
Save