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