WA-238 Not allowing user who has confirmed tx do it again

This commit is contained in:
apanizo 2018-05-30 09:36:28 +02:00
parent 649243c0d3
commit 557a2e17af
2 changed files with 18 additions and 2 deletions

View File

@ -1,5 +1,6 @@
// @flow // @flow
import * as React from 'react' import * as React from 'react'
import { List } from 'immutable'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import openHoc, { type Open } from '~/components/hoc/OpenHoc' import openHoc, { type Open } from '~/components/hoc/OpenHoc'
import ExpandLess from 'material-ui-icons/ExpandLess' import ExpandLess from 'material-ui-icons/ExpandLess'
@ -16,6 +17,8 @@ import Collapsed from '~/routes/safe/component/Transactions/Collapsed'
import { type Transaction } from '~/routes/safe/store/model/transaction' import { type Transaction } from '~/routes/safe/store/model/transaction'
import Hairline from '~/components/layout/Hairline/index' import Hairline from '~/components/layout/Hairline/index'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import { sameAddress } from '~/wallets/ethAddresses'
import { type Confirmation } from '~/routes/safe/store/model/confirmation'
import selector, { type SelectorProps } from './selector' import selector, { type SelectorProps } from './selector'
type Props = Open & SelectorProps & { type Props = Open & SelectorProps & {
@ -29,13 +32,17 @@ export const PROCESS_TXS = 'PROCESS TRANSACTION'
class GnoTransaction extends React.PureComponent<Props, {}> { class GnoTransaction extends React.PureComponent<Props, {}> {
onProccesClick = () => this.props.onProcessTx(this.props.transaction, this.props.confirmed) onProccesClick = () => this.props.onProcessTx(this.props.transaction, this.props.confirmed)
hasConfirmed = (userAddress: string, confirmations: List<Confirmation>): boolean =>
confirmations.filter((conf: Confirmation) => sameAddress(userAddress, conf.get('owner').get('address')) && conf.get('status')).count() > 0
render() { render() {
const { const {
open, toggle, transaction, confirmed, safeName, open, toggle, transaction, confirmed, safeName, userAddress,
} = this.props } = this.props
const txHash = transaction.get('tx') const txHash = transaction.get('tx')
const confirmationText = txHash ? 'Already executed' : `${confirmed} of the ${transaction.get('threshold')} confirmations needed` const confirmationText = txHash ? 'Already executed' : `${confirmed} of the ${transaction.get('threshold')} confirmations needed`
const userConfirmed = this.hasConfirmed(userAddress, transaction.get('confirmations'))
return ( return (
<React.Fragment> <React.Fragment>
@ -66,7 +73,13 @@ class GnoTransaction extends React.PureComponent<Props, {}> {
<ListItemText cut primary="Transaction Hash" secondary={txHash} /> <ListItemText cut primary="Transaction Hash" secondary={txHash} />
</React.Fragment> </React.Fragment>
} }
{ !txHash && { !txHash && userConfirmed &&
<React.Fragment>
<Avatar><CompareArrows /></Avatar>
<ListItemText cut primary="Confirmed" secondary="Waiting for the rest of confirmations" />
</React.Fragment>
}
{ !txHash && !userConfirmed &&
<Button <Button
variant="raised" variant="raised"
color="primary" color="primary"

View File

@ -1,11 +1,14 @@
// @flow // @flow
import { createStructuredSelector } from 'reselect' import { createStructuredSelector } from 'reselect'
import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index' import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
import { userAccountSelector } from '~/wallets/store/selectors/index'
export type SelectorProps = { export type SelectorProps = {
confirmed: confirmationsTransactionSelector, confirmed: confirmationsTransactionSelector,
userAddress: userAccountSelector,
} }
export default createStructuredSelector({ export default createStructuredSelector({
confirmed: confirmationsTransactionSelector, confirmed: confirmationsTransactionSelector,
userAddress: userAccountSelector,
}) })