show confirm button only if an owner has not confirmed tx, show button row only to owners

This commit is contained in:
Mikhail Mikheev 2019-07-03 16:38:00 +04:00
parent 7d3930cbc6
commit 9801e68343
5 changed files with 56 additions and 16 deletions

View File

@ -25,9 +25,14 @@ import Settings from './Settings'
export const SETTINGS_TAB_BTN_TESTID = 'settings-tab-btn' export const SETTINGS_TAB_BTN_TESTID = 'settings-tab-btn'
export const SAFE_VIEW_NAME_HEADING_TESTID = 'safe-name-heading' export const SAFE_VIEW_NAME_HEADING_TESTID = 'safe-name-heading'
type State = {
tabIndex: number,
}
type Props = SelectorProps & { type Props = SelectorProps & {
classes: Object, classes: Object,
granted: boolean, granted: boolean,
updateSafe: Function,
createTransaction: Function, createTransaction: Function,
fetchTransactions: Function, fetchTransactions: Function,
} }
@ -102,6 +107,7 @@ class Layout extends React.Component<Props, State> {
fetchTransactions, fetchTransactions,
updateSafe, updateSafe,
transactions, transactions,
userAddress,
} = this.props } = this.props
const { tabIndex } = this.state const { tabIndex } = this.state
@ -160,6 +166,8 @@ class Layout extends React.Component<Props, State> {
transactions={transactions} transactions={transactions}
fetchTransactions={fetchTransactions} fetchTransactions={fetchTransactions}
safeAddress={address} safeAddress={address}
userAddress={userAddress}
granted={granted}
/> />
)} )}
{tabIndex === 2 && ( {tabIndex === 2 && (

View File

@ -11,6 +11,7 @@ type Props = {
onTxConfirm: Function, onTxConfirm: Function,
onTxCancel: Function, onTxCancel: Function,
classes: Object, classes: Object,
showConfirmBtn: boolean,
} }
const styles = () => ({ const styles = () => ({
@ -32,18 +33,22 @@ const styles = () => ({
}, },
}) })
const ButtonRow = ({ classes, onTxCancel, onTxConfirm }: Props) => ( const ButtonRow = ({
classes, onTxCancel, onTxConfirm, showConfirmBtn,
}: Props) => (
<Row align="center" className={classes.buttonRow}> <Row align="center" className={classes.buttonRow}>
<Button className={classes.button} variant="contained" minWidth={140} color="secondary" onClick={onTxCancel}> <Button className={classes.button} variant="contained" minWidth={140} color="secondary" onClick={onTxCancel}>
<BlockIcon className={classes.icon} /> <BlockIcon className={classes.icon} />
{' '} {' '}
Cancel TX Cancel TX
</Button> </Button>
{showConfirmBtn && (
<Button className={classes.button} variant="contained" minWidth={140} color="primary" onClick={onTxConfirm}> <Button className={classes.button} variant="contained" minWidth={140} color="primary" onClick={onTxConfirm}>
<EditIcon className={classes.icon} /> <EditIcon className={classes.icon} />
{' '} {' '}
Confirm TX Confirm TX
</Button> </Button>
)}
</Row> </Row>
) )

View File

@ -32,6 +32,8 @@ type Props = {
tx: Transaction, tx: Transaction,
threshold: number, threshold: number,
owners: List<Owner>, owners: List<Owner>,
granted: boolean,
userAddress: string,
} }
type OpenModal = 'cancelTx' | 'approveTx' | null type OpenModal = 'cancelTx' | 'approveTx' | null
@ -47,7 +49,7 @@ const txStatusToLabel = {
} }
const ExpandedTx = ({ const ExpandedTx = ({
classes, tx, threshold, owners, classes, tx, threshold, owners, granted, userAddress,
}: Props) => { }: Props) => {
const [tabIndex, setTabIndex] = useState<number>(0) const [tabIndex, setTabIndex] = useState<number>(0)
const [openModal, setOpenModal] = useState<OpenModal>(null) const [openModal, setOpenModal] = useState<OpenModal>(null)
@ -61,9 +63,15 @@ const ExpandedTx = ({
const ownersWhoConfirmed = [] const ownersWhoConfirmed = []
const ownersUnconfirmed = [] const ownersUnconfirmed = []
let currentUserAlreadyConfirmed = false
owners.forEach((owner) => { owners.forEach((owner) => {
if (tx.confirmations.find(conf => conf.owner.address === owner.address)) { if (tx.confirmations.find(conf => conf.owner.address === owner.address)) {
ownersWhoConfirmed.push(owner) ownersWhoConfirmed.push(owner)
if (owner.address === userAddress) {
currentUserAlreadyConfirmed = true
}
} else { } else {
ownersUnconfirmed.push(owner) ownersUnconfirmed.push(owner)
} }
@ -117,7 +125,7 @@ const ExpandedTx = ({
{' '} {' '}
{tx.symbol} {tx.symbol}
{' '} {' '}
to: to:
</Bold> </Bold>
<br /> <br />
<a href={getEtherScanLink(tx.recipient, 'rinkeby')} target="_blank" rel="noopener noreferrer"> <a href={getEtherScanLink(tx.recipient, 'rinkeby')} target="_blank" rel="noopener noreferrer">
@ -137,7 +145,13 @@ const ExpandedTx = ({
</Row> </Row>
<Row>{tabIndex === 0 && <OwnersList owners={ownersWhoConfirmed} />}</Row> <Row>{tabIndex === 0 && <OwnersList owners={ownersWhoConfirmed} />}</Row>
<Row>{tabIndex === 1 && <OwnersList owners={ownersUnconfirmed} />}</Row> <Row>{tabIndex === 1 && <OwnersList owners={ownersUnconfirmed} />}</Row>
<ButtonRow onTxConfirm={openApproveModal} onTxCancel={openCancelModal} /> {granted && (
<ButtonRow
onTxConfirm={openApproveModal}
onTxCancel={openCancelModal}
showConfirmBtn={!currentUserAlreadyConfirmed}
/>
)}
</Col> </Col>
</Row> </Row>
</Block> </Block>

View File

@ -32,12 +32,13 @@ type Props = {
transactions: List<Transaction>, transactions: List<Transaction>,
threshold: number, threshold: number,
owners: List<Owner>, owners: List<Owner>,
userAddress: string,
granted: boolean,
} }
const TxsTable = (props: Props) => { const TxsTable = ({
const { classes, transactions, threshold, owners, granted, userAddress,
classes, transactions, threshold, owners, }: Props) => {
} = props
const [expandedTx, setExpandedTx] = useState<string | null>(null) const [expandedTx, setExpandedTx] = useState<string | null>(null)
const handleTxExpand = (nonce) => { const handleTxExpand = (nonce) => {
@ -100,6 +101,8 @@ const TxsTable = (props: Props) => {
tx={row[TX_TABLE_RAW_TX_ID]} tx={row[TX_TABLE_RAW_TX_ID]}
threshold={threshold} threshold={threshold}
owners={owners} owners={owners}
granted={granted}
userAddress={userAddress}
/> />
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@ -12,6 +12,8 @@ type Props = {
fetchTransactions: Function, fetchTransactions: Function,
transactions: List<Transaction>, transactions: List<Transaction>,
owners: List<Owner>, owners: List<Owner>,
userAddress: string,
granted: boolean,
} }
class Transactions extends React.Component<Props, {}> { class Transactions extends React.Component<Props, {}> {
@ -22,13 +24,21 @@ class Transactions extends React.Component<Props, {}> {
} }
render() { render() {
const { transactions, owners, threshold } = this.props const {
transactions, owners, threshold, userAddress, granted,
} = this.props
const hasTransactions = transactions.size > 0 const hasTransactions = transactions.size > 0
return ( return (
<React.Fragment> <React.Fragment>
{hasTransactions ? ( {hasTransactions ? (
<TxsTable transactions={transactions} threshold={threshold} owners={owners} /> <TxsTable
transactions={transactions}
threshold={threshold}
owners={owners}
userAddress={userAddress}
granted={granted}
/>
) : ( ) : (
<NoTransactions /> <NoTransactions />
)} )}