WA-238 disable Withdrawn button

This commit is contained in:
apanizo 2018-06-04 13:26:07 +02:00
parent d7ff250c18
commit e10828e5c4
3 changed files with 19 additions and 3 deletions

View File

@ -10,14 +10,16 @@ import { type DailyLimit } from '~/routes/safe/store/model/dailyLimit'
type Props = {
dailyLimit: DailyLimit,
onWithdrawn: () => void,
balance: string,
}
export const WITHDRAWN_BUTTON_TEXT = 'Withdrawn'
const DailyLimitComponent = ({ dailyLimit, onWithdrawn }: Props) => {
const DailyLimitComponent = ({ dailyLimit, balance, onWithdrawn }: Props) => {
const limit = dailyLimit.get('value')
const spentToday = dailyLimit.get('spentToday')
const disabled = spentToday >= limit
const disabled = spentToday >= limit || Number(balance) === 0
const text = `${limit} ETH (spent today: ${spentToday} ETH)`
return (

View File

@ -71,7 +71,7 @@ class GnoSafe extends React.PureComponent<SafeProps, State> {
<Owners owners={safe.owners} />
<Confirmations confirmations={safe.get('confirmations')} />
<Address address={safe.get('address')} />
<DailyLimit dailyLimit={safe.get('dailyLimit')} onWithdrawn={this.onWithdrawn} />
<DailyLimit balance={balance} dailyLimit={safe.get('dailyLimit')} onWithdrawn={this.onWithdrawn} />
<MultisigTx balance={balance} onAddTx={this.onAddTx} onSeeTxs={this.onListTransactions} />
</List>
</Col>

View File

@ -104,4 +104,18 @@ describe('React DOM TESTS > Withdrawn funds from safe', () => {
expect(addTxButton.props.disabled).toBe(false)
})
it('Withdrawn button disabled when balance is 0', async () => {
const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView)
// $FlowFixMe
const buttons = TestUtils.scryRenderedComponentsWithType(Safe, Button)
const addTxButton = buttons[0]
expect(addTxButton.props.children).toEqual(WITHDRAWN_BUTTON_TEXT)
expect(addTxButton.props.disabled).toBe(true)
await addEtherTo(address, '0.1')
await sleep(1800)
expect(addTxButton.props.disabled).toBe(false)
})
})