Refactor Balance onShow onHide actions

This commit is contained in:
apanizo 2018-10-24 12:25:18 +02:00
parent 31d0d941ca
commit deac8528fc
1 changed files with 15 additions and 29 deletions

View File

@ -78,6 +78,8 @@ type Props = {
classes: Object, classes: Object,
} }
type Action = 'Token' | 'Send' | 'Receive'
class Balances extends React.Component<Props, State> { class Balances extends React.Component<Props, State> {
state = { state = {
hideZero: false, hideZero: false,
@ -86,28 +88,12 @@ class Balances extends React.Component<Props, State> {
showReceive: false, showReceive: false,
} }
onShowToken = () => { onShow = (action: Action) => () => {
this.setState(() => ({ showToken: true })) this.setState(() => ({ [`show${action}`]: true }))
} }
onHideToken = () => { onHide = (action: Action) => () => {
this.setState(() => ({ showToken: false })) this.setState(() => ({ [`show${action}`]: false }))
}
onShowSend = () => {
this.setState(() => ({ showSend: true }))
}
onHideSend = () => {
this.setState(() => ({ showSend: false }))
}
onShowReceive = () => {
this.setState(() => ({ showReceive: true }))
}
onHideReceive = () => {
this.setState(() => ({ showReceive: false }))
} }
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => { handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
@ -144,16 +130,16 @@ class Balances extends React.Component<Props, State> {
<Paragraph className={classes.zero}>Hide zero balances</Paragraph> <Paragraph className={classes.zero}>Hide zero balances</Paragraph>
</Col> </Col>
<Col xs={6} end="sm"> <Col xs={6} end="sm">
<Paragraph noMargin size="md" color="secondary" className={classes.links} onClick={this.onShowToken}> <Paragraph noMargin size="md" color="secondary" className={classes.links} onClick={this.onShow('Token')}>
Manage Tokens Manage Tokens
</Paragraph> </Paragraph>
<Modal <Modal
title="Manage Tokens" title="Manage Tokens"
description="Enable and disable tokens to be listed" description="Enable and disable tokens to be listed"
handleClose={this.onHideToken} handleClose={this.onHide('Token')}
open={showToken} open={showToken}
> >
<Tokens onClose={this.onHideToken} /> <Tokens onClose={this.onHide('Token')} />
</Modal> </Modal>
</Col> </Col>
</Row> </Row>
@ -174,11 +160,11 @@ class Balances extends React.Component<Props, State> {
)) } )) }
<TableCell component="th" scope="row"> <TableCell component="th" scope="row">
<Row align="end" className={classes.actions}> <Row align="end" className={classes.actions}>
<Button variant="contained" size="small" color="secondary" className={classes.send} onClick={this.onShowSend}> <Button variant="contained" size="small" color="secondary" className={classes.send} onClick={this.onShow('Send')}>
<CallMade className={classNames(classes.leftIcon, classes.iconSmall)} /> <CallMade className={classNames(classes.leftIcon, classes.iconSmall)} />
Send Send
</Button> </Button>
<Button variant="contained" size="small" color="secondary" className={classes.receive} onClick={this.onShowReceive}> <Button variant="contained" size="small" color="secondary" className={classes.receive} onClick={this.onShow('Receive')}>
<CallReceived className={classNames(classes.leftIcon, classes.iconSmall)} /> <CallReceived className={classNames(classes.leftIcon, classes.iconSmall)} />
Receive Receive
</Button> </Button>
@ -190,18 +176,18 @@ class Balances extends React.Component<Props, State> {
<Modal <Modal
title="Send Tokens" title="Send Tokens"
description="Send Tokens Form" description="Send Tokens Form"
handleClose={this.onHideSend} handleClose={this.onHide('Send')}
open={showSend} open={showSend}
> >
<Send onClose={this.onHideSend} /> <Send onClose={this.onHide('Send')} />
</Modal> </Modal>
<Modal <Modal
title="Receive Tokens" title="Receive Tokens"
description="Receive Tokens Form" description="Receive Tokens Form"
handleClose={this.onHideReceive} handleClose={this.onHide('Receive')}
open={showReceive} open={showReceive}
> >
<Receive onClose={this.onHideReceive} /> <Receive onClose={this.onHide('Receive')} />
</Modal> </Modal>
</React.Fragment> </React.Fragment>
) )