Browse Source

Start splitting SelectAccount and ReceiveBox

master
meriadec 7 years ago
parent
commit
0643bd24e7
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 52
      src/components/AccountPage.js
  2. 75
      src/components/ReceiveBox.js
  3. 41
      src/components/SelectAccount.js
  4. 8
      src/components/base/Select/index.js
  5. 36
      src/components/modals/Receive.js
  6. 1
      static/i18n/en/translation.yml
  7. 1
      static/i18n/fr/translation.yml

52
src/components/AccountPage.js

@ -2,7 +2,6 @@
import React, { PureComponent, Fragment } from 'react' import React, { PureComponent, Fragment } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import styled from 'styled-components'
import type { MapStateToProps } from 'react-redux' import type { MapStateToProps } from 'react-redux'
import type { Account, AccountData } from 'types/common' import type { Account, AccountData } from 'types/common'
@ -14,8 +13,7 @@ import { getAccountById, getAccountData } from 'reducers/accounts'
import TransactionsList from 'components/TransactionsList' import TransactionsList from 'components/TransactionsList'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import QRCode from 'components/base/QRCode' import ReceiveBox from 'components/ReceiveBox'
import CopyToClipboard from 'components/base/CopyToClipboard'
type Props = { type Props = {
account: Account, account: Account,
@ -27,32 +25,6 @@ const mapStateToProps: MapStateToProps<*, *, *> = (state, props) => ({
accountData: getAccountData(state, props.match.params.id), accountData: getAccountData(state, props.match.params.id),
}) })
const AddressBox = styled(Box).attrs({
borderWidth: 1,
borderColor: 'mouse',
bg: 'cream',
p: 2,
})`
text-align: center;
word-break: break-all;
border-radius: 3px;
user-select: text;
`
const Action = styled(Box).attrs({
color: 'mouse',
fontSize: 0,
})`
font-weight: bold;
text-align: center;
cursor: pointer;
text-transform: uppercase;
&:hover {
color: ${p => p.theme.colors.grey};
}
`
class AccountPage extends PureComponent<Props> { class AccountPage extends PureComponent<Props> {
render() { render() {
const { account, accountData } = this.props const { account, accountData } = this.props
@ -66,32 +38,14 @@ class AccountPage extends PureComponent<Props> {
<Fragment> <Fragment>
<Box horizontal flow={3}> <Box horizontal flow={3}>
<Box grow> <Box grow>
<Card title="Balance" style={{ height: 415 }} align="center" justify="center"> <Card title="Balance" style={{ height: 435 }} align="center" justify="center">
<Text fontSize={6}>{formatBTC(accountData.balance)}</Text> <Text fontSize={6}>{formatBTC(accountData.balance)}</Text>
</Card> </Card>
</Box> </Box>
<Box style={{ width: 300 }}> <Box style={{ width: 300 }}>
<Card title="Receive" flow={3}> <Card title="Receive" flow={3}>
<Box align="center"> <ReceiveBox address={accountData.address} />
<QRCode size={150} data={accountData.address} />
</Box>
<Box align="center" flow={2}>
<Text fontSize={1}>{'Current address'}</Text>
<AddressBox>{accountData.address}</AddressBox>
</Box>
<Box horizontal>
<CopyToClipboard
data={accountData.address}
render={copy => (
<Action flex={1} onClick={copy}>
{'Copy'}
</Action>
)}
/>
<Action flex={1}>{'Print'}</Action>
<Action flex={1}>{'Share'}</Action>
</Box>
</Card> </Card>
</Box> </Box>
</Box> </Box>

75
src/components/ReceiveBox.js

@ -0,0 +1,75 @@
// @flow
import React from 'react'
import styled from 'styled-components'
import Box from 'components/base/Box'
import QRCode from 'components/base/QRCode'
import Icon from 'components/base/Icon'
import CopyToClipboard from 'components/base/CopyToClipboard'
import Text from 'components/base/Text'
type Props = {
address: string,
}
const AddressBox = styled(Box).attrs({
borderWidth: 1,
borderColor: 'mouse',
bg: 'cream',
p: 2,
})`
text-align: center;
word-break: break-all;
border-radius: 3px;
user-select: text;
`
const Action = styled(Box).attrs({
flow: 1,
flex: 1,
color: 'mouse',
fontSize: 0,
})`
font-weight: bold;
text-align: center;
cursor: pointer;
text-transform: uppercase;
&:hover {
color: ${p => p.theme.colors.grey};
}
`
const ReceiveBox = ({ address }: Props) => (
<Box flow={3}>
<Box align="center">
<QRCode size={150} data={address} />
</Box>
<Box align="center" flow={2}>
<Text fontSize={1}>{'Current address'}</Text>
<AddressBox>{address}</AddressBox>
</Box>
<Box horizontal>
<CopyToClipboard
data={address}
render={copy => (
<Action onClick={copy}>
<Icon name="clone" />
<span>{'Copy'}</span>
</Action>
)}
/>
<Action>
<Icon name="print" />
<span>{'Print'}</span>
</Action>
<Action>
<Icon name="share-square-o" />
<span>{'Share'}</span>
</Action>
</Box>
</Box>
)
export default ReceiveBox

41
src/components/SelectAccount.js

@ -0,0 +1,41 @@
// @flow
import React from 'react'
import { connect } from 'react-redux'
import values from 'lodash/values'
import type { MapStateToProps } from 'react-redux'
import { getAccounts } from 'reducers/accounts'
import Select from 'components/base/Select'
import Text from 'components/base/Text'
import type { Account } from 'types/common'
const mapStateToProps: MapStateToProps<*, *, *> = state => ({
accounts: values(getAccounts(state)),
})
type Props = {
accounts: Array<Account>,
onChange: () => Account | void,
value: Account | null,
}
const SelectAccount = ({ accounts, value, onChange }: Props) => (
<Select
value={value}
placeholder="Choose an account"
items={accounts}
keyProp="id"
onChange={onChange}
itemToString={item => (item ? item.name : '')}
renderHighlight={(text, key) => (
<Text key={key} fontWeight="bold">
{text}
</Text>
)}
/>
)
export default connect(mapStateToProps)(SelectAccount)

8
src/components/base/Select/index.js

@ -16,7 +16,7 @@ import Triangles from './Triangles'
type Props = { type Props = {
items: Array<Object>, items: Array<Object>,
value?: Object, value?: Object | null,
itemToString?: Function, itemToString?: Function,
onChange?: Function, onChange?: Function,
fuseOptions?: Object, fuseOptions?: Object,
@ -26,6 +26,7 @@ type Props = {
renderHighlight?: string => Element<*>, renderHighlight?: string => Element<*>,
renderSelected?: Object => Element<*>, renderSelected?: Object => Element<*>,
renderItem?: (*) => Element<*>, renderItem?: (*) => Element<*>,
keyProp?: string,
} }
const Container = styled(Box).attrs({ relative: true, color: 'steel' })`` const Container = styled(Box).attrs({ relative: true, color: 'steel' })``
@ -91,16 +92,17 @@ const FloatingTriangles = styled(Box).attrs({
class Select extends PureComponent<Props> { class Select extends PureComponent<Props> {
static defaultProps = { static defaultProps = {
itemToString: (item: Object) => item.name, itemToString: (item: Object) => item.name,
keyProp: undefined,
} }
renderItems = (items: Array<Object>, downshiftProps: Object) => { renderItems = (items: Array<Object>, downshiftProps: Object) => {
const { renderItem } = this.props const { renderItem, keyProp } = this.props
const { getItemProps, highlightedIndex } = downshiftProps const { getItemProps, highlightedIndex } = downshiftProps
return ( return (
<Dropdown> <Dropdown>
{items.length ? ( {items.length ? (
items.map((item, i) => ( items.map((item, i) => (
<ItemWrapper key={item.key} {...getItemProps({ item })}> <ItemWrapper key={keyProp ? item[keyProp] : item.key} {...getItemProps({ item })}>
<Item highlighted={i === highlightedIndex}> <Item highlighted={i === highlightedIndex}>
{renderItem ? renderItem(item) : <span>{item.name_highlight || item.name}</span>} {renderItem ? renderItem(item) : <span>{item.name_highlight || item.name}</span>}
</Item> </Item>

36
src/components/modals/Receive.js

@ -1,20 +1,48 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { translate } from 'react-i18next'
import Modal, { ModalBody } from 'components/base/Modal' import Modal, { ModalBody } from 'components/base/Modal'
import Text from 'components/base/Text'
import SelectAccount from 'components/SelectAccount'
type Props = {} import type { Account as AccountType, T } from 'types/common'
type Props = {
t: T,
}
type State = {
account: AccountType | null,
}
class ReceiveModal extends PureComponent<Props, State> {
state = {
account: null,
}
handleChangeAccount = account => {
this.setState({ account })
}
class ReceiveModal extends PureComponent<Props> {
render() { render() {
const { account } = this.state
const { t } = this.props
return ( return (
<Modal <Modal
name="receive" name="receive"
render={({ onClose }) => <ModalBody onClose={onClose}>receive modal</ModalBody>} render={({ onClose }) => (
<ModalBody onClose={onClose} flow={3}>
<Text fontSize={4} color="steel">
{t('receive.modalTitle')}
</Text>
<SelectAccount value={account} onChange={this.handleChangeAccount} />
</ModalBody>
)}
/> />
) )
} }
} }
export default ReceiveModal export default translate()(ReceiveModal)

1
static/i18n/en/translation.yml

@ -21,6 +21,7 @@ send:
receive: receive:
title: Receive title: Receive
modalTitle: Receive funds
addAccount: addAccount:
title: Add account title: Add account

1
static/i18n/fr/translation.yml

@ -21,6 +21,7 @@ send:
receive: receive:
title: Recevoir title: Recevoir
modalTitle: Recevoir des fonds
addAccount: addAccount:
title: Ajouter un compte title: Ajouter un compte

Loading…
Cancel
Save