approve & cancel tx modals wip

This commit is contained in:
Mikhail Mikheev 2019-07-02 19:13:46 +04:00
parent 3aea531b61
commit d98a768b51
4 changed files with 150 additions and 64 deletions

View File

@ -1,9 +1,9 @@
// @flow // @flow
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { List } from 'immutable' import { List } from 'immutable'
import { type Token } from '~/logic/tokens/store/model/token'
import cn from 'classnames' import cn from 'classnames'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import { type Token } from '~/logic/tokens/store/model/token'
import Modal from '~/components/Modal' import Modal from '~/components/Modal'
import ChooseTxType from './screens/ChooseTxType' import ChooseTxType from './screens/ChooseTxType'
import SendFunds from './screens/SendFunds' import SendFunds from './screens/SendFunds'

View File

@ -0,0 +1,43 @@
// @flow
import React from 'react'
import { List } from 'immutable'
import Close from '@material-ui/icons/Close'
import IconButton from '@material-ui/core/IconButton'
import cn from 'classnames'
import { withStyles } from '@material-ui/core/styles'
import Modal from '~/components/Modal'
import Hairline from '~/components/layout/Hairline'
import Paragraph from '~/components/layout/Paragraph'
import Row from '~/components/layout/Row'
import { styles } from './style'
type Props = {
onClose: () => void,
classes: Object,
isOpen: boolean,
createTransaction: Function,
}
const CancelTxModal = ({
onClose, isOpen, classes, createTransaction,
}: Props) => (
<Modal
title="Cancel Transaction"
description="CancelTransaction"
handleClose={onClose}
open={isOpen}
// paperClassName={cn(smallerModalSize && classes.smallerModalWindow)}
>
<Row align="center" grow className={classes.heading}>
<Paragraph weight="bolder" className={classes.headingText} noMargin>
Cancel transaction
</Paragraph>
<IconButton onClick={onClose} disableRipple>
<Close className={classes.closeIcon} />
</IconButton>
</Row>
<Hairline />
</Modal>
)
export default withStyles(styles)(CancelTxModal)

View File

@ -0,0 +1,32 @@
// @flow
import { lg, md, sm } from '~/theme/variables'
export const styles = () => ({
heading: {
padding: `${sm} ${lg}`,
justifyContent: 'space-between',
boxSizing: 'border-box',
maxHeight: '75px',
},
headingText: {
fontSize: '24px',
},
closeIcon: {
height: '35px',
width: '35px',
},
container: {
padding: `${md} ${lg}`,
},
buttonRow: {
height: '84px',
justifyContent: 'center',
position: 'absolute',
bottom: 0,
width: '100%',
},
smallerModalWindow: {
height: 'auto',
position: 'static',
},
})

View File

@ -19,6 +19,7 @@ import { shortVersionOf } from '~/logic/wallets/ethAddresses'
import { secondary } from '~/theme/variables' import { secondary } from '~/theme/variables'
import OwnersList from './OwnersList' import OwnersList from './OwnersList'
import ButtonRow from './ButtonRow' import ButtonRow from './ButtonRow'
import CancelTxModal from './CancelTxModal'
import { styles } from './style' import { styles } from './style'
import { formatDate } from '../columns' import { formatDate } from '../columns'
@ -32,6 +33,8 @@ type Props = {
owners: List<Owner>, owners: List<Owner>,
} }
type OpenModal = 'cancelTx' | 'approveTx' | null
const openIconStyle = { const openIconStyle = {
height: '13px', height: '13px',
color: secondary, color: secondary,
@ -46,6 +49,11 @@ const ExpandedTx = ({
classes, tx, threshold, owners, classes, tx, threshold, owners,
}: Props) => { }: Props) => {
const [tabIndex, setTabIndex] = useState<number>(0) const [tabIndex, setTabIndex] = useState<number>(0)
const [openModal, setOpenModal] = useState<OpenModal>(null)
const openApproveModal = () => setOpenModal('approveTx')
const openCancelModal = () => setOpenModal('cancelTx')
const closeModal = () => setOpenModal(null)
const confirmedLabel = `Confirmed [${tx.confirmations.size}/${threshold}]` const confirmedLabel = `Confirmed [${tx.confirmations.size}/${threshold}]`
const unconfirmedLabel = `Unconfirmed [${owners.size - tx.confirmations.size}]` const unconfirmedLabel = `Unconfirmed [${owners.size - tx.confirmations.size}]`
const txStatus = tx.isExecuted ? 'success' : 'awaiting_confirmations' const txStatus = tx.isExecuted ? 'success' : 'awaiting_confirmations'
@ -65,72 +73,75 @@ const ExpandedTx = ({
} }
return ( return (
<Block> <>
<Row> <Block>
<Col xs={6} layout="column"> <Row>
<Block className={classes.txDataContainer}> <Col xs={6} layout="column">
<Paragraph noMargin> <Block className={classes.txDataContainer}>
<Bold>TX hash: </Bold> <Paragraph noMargin>
{tx.executionTxHash ? ( <Bold>TX hash: </Bold>
<a href={openTxInEtherScan(tx.executionTxHash, 'rinkeby')} target="_blank" rel="noopener noreferrer"> {tx.executionTxHash ? (
{shortVersionOf(tx.executionTxHash, 4)} <a href={openTxInEtherScan(tx.executionTxHash, 'rinkeby')} target="_blank" rel="noopener noreferrer">
{shortVersionOf(tx.executionTxHash, 4)}
<OpenInNew style={openIconStyle} />
</a>
) : (
'n/a'
)}
</Paragraph>
<Paragraph noMargin>
<Bold>TX status: </Bold>
<Span className={classes[txStatus]} style={{ fontWeight: 'bold' }}>
{txStatusToLabel[txStatus]}
</Span>
</Paragraph>
<Paragraph noMargin>
<Bold>TX created: </Bold>
{formatDate(tx.submissionDate)}
</Paragraph>
{tx.executionDate && (
<Paragraph noMargin>
<Bold>TX executed: </Bold>
{formatDate(tx.executionDate)}
</Paragraph>
)}
</Block>
<Hairline />
<Block className={classes.txDataContainer}>
<Paragraph noMargin>
<Bold>
Send
{' '}
{fromWei(toBN(tx.value), 'ether')}
{' '}
{tx.symbol}
{' '}
to:
</Bold>
<br />
<a href={getEtherScanLink(tx.recipient, 'rinkeby')} target="_blank" rel="noopener noreferrer">
{shortVersionOf(tx.recipient, 4)}
<OpenInNew style={openIconStyle} /> <OpenInNew style={openIconStyle} />
</a> </a>
) : (
'n/a'
)}
</Paragraph>
<Paragraph noMargin>
<Bold>TX status: </Bold>
<Span className={classes[txStatus]} style={{ fontWeight: 'bold' }}>
{txStatusToLabel[txStatus]}
</Span>
</Paragraph>
<Paragraph noMargin>
<Bold>TX created: </Bold>
{formatDate(tx.submissionDate)}
</Paragraph>
{tx.executionDate && (
<Paragraph noMargin>
<Bold>TX executed: </Bold>
{formatDate(tx.executionDate)}
</Paragraph> </Paragraph>
)} </Block>
</Block> </Col>
<Hairline /> <Col xs={6} className={classes.rightCol} layout="block">
<Block className={classes.txDataContainer}> <Row>
<Paragraph noMargin> <Tabs value={tabIndex} onChange={handleTabChange} indicatorColor="secondary" textColor="secondary">
<Bold> <Tab label={confirmedLabel} />
Send <Tab label={unconfirmedLabel} />
{' '} </Tabs>
{fromWei(toBN(tx.value), 'ether')} <Hairline color="#c8ced4" />
{' '} </Row>
{tx.symbol} <Row>{tabIndex === 0 && <OwnersList owners={ownersWhoConfirmed} />}</Row>
{' '} <Row>{tabIndex === 1 && <OwnersList owners={ownersUnconfirmed} />}</Row>
to: <ButtonRow onTxApprove={openApproveModal} onTxCancel={openCancelModal} />
</Bold> </Col>
<br /> </Row>
<a href={getEtherScanLink(tx.recipient, 'rinkeby')} target="_blank" rel="noopener noreferrer"> </Block>
{shortVersionOf(tx.recipient, 4)} <CancelTxModal isOpen={openModal === 'cancelTx'} onClose={closeModal} />
<OpenInNew style={openIconStyle} /> </>
</a>
</Paragraph>
</Block>
</Col>
<Col xs={6} className={classes.rightCol} layout="block">
<Row>
<Tabs value={tabIndex} onChange={handleTabChange} indicatorColor="secondary" textColor="secondary">
<Tab label={confirmedLabel} />
<Tab label={unconfirmedLabel} />
</Tabs>
<Hairline color="#c8ced4" />
</Row>
<Row>{tabIndex === 0 && <OwnersList owners={ownersWhoConfirmed} />}</Row>
<Row>{tabIndex === 1 && <OwnersList owners={ownersUnconfirmed} />}</Row>
<ButtonRow />
</Col>
</Row>
</Block>
) )
} }