WA-238 Adapting dailyLimit in safes to store the amount spent

This commit is contained in:
apanizo 2018-05-11 15:25:16 +02:00
parent 5f1931c039
commit 1e42b3d67e
5 changed files with 45 additions and 22 deletions

View File

@ -7,13 +7,17 @@ import Button from '~/components/layout/Button'
import ListItemText from '~/components/List/ListItemText' import ListItemText from '~/components/List/ListItemText'
type Props = { type Props = {
limit: number, dailyLimit: number,
onWithdrawn: () => void, onWithdrawn: () => void,
} }
export const WITHDRAWN_BUTTON_TEXT = 'Withdrawn' export const WITHDRAWN_BUTTON_TEXT = 'Withdrawn'
const DailyLimit = ({ limit, onWithdrawn }: Props) => ( const DailyLimit = ({ dailyLimit, onWithdrawn }: Props) => {
const limit = dailyLimit.get('value')
const disabled = dailyLimit.get('todaySpent') > limit
return (
<ListItem> <ListItem>
<Avatar> <Avatar>
<NotificationsPaused /> <NotificationsPaused />
@ -23,10 +27,12 @@ const DailyLimit = ({ limit, onWithdrawn }: Props) => (
variant="raised" variant="raised"
color="primary" color="primary"
onClick={onWithdrawn} onClick={onWithdrawn}
disabled={disabled}
> >
{WITHDRAWN_BUTTON_TEXT} {WITHDRAWN_BUTTON_TEXT}
</Button> </Button>
</ListItem> </ListItem>
) )
}
export default DailyLimit export default DailyLimit

View File

@ -55,7 +55,7 @@ class GnoSafe extends React.PureComponent<SafeProps, State> {
<Owners owners={safe.owners} /> <Owners owners={safe.owners} />
<Confirmations confirmations={safe.get('confirmations')} /> <Confirmations confirmations={safe.get('confirmations')} />
<Address address={safe.get('address')} /> <Address address={safe.get('address')} />
<DailyLimit limit={safe.get('dailyLimit')} onWithdrawn={this.onWithdrawn} /> <DailyLimit dailyLimit={safe.dailyLimit} onWithdrawn={this.onWithdrawn} />
</List> </List>
</Col> </Col>
<Col sm={12} center="xs" md={7} margin="xl" layout="column"> <Col sm={12} center="xs" md={7} margin="xl" layout="column">

View File

@ -1,7 +1,7 @@
// @flow // @flow
import { List } from 'immutable' import { List } from 'immutable'
import { createAction } from 'redux-actions' import { createAction } from 'redux-actions'
import { type SafeProps } from '~/routes/safe/store/model/safe' import { makeDailyLimit, type DailyLimit, type SafeProps } from '~/routes/safe/store/model/safe'
import { makeOwner, type Owner } from '~/routes/safe/store/model/owner' import { makeOwner, type Owner } from '~/routes/safe/store/model/owner'
export const ADD_SAFE = 'ADD_SAFE' export const ADD_SAFE = 'ADD_SAFE'
@ -12,14 +12,18 @@ export const buildOwnersFrom = (names: string[], addresses: string[]) => {
return List(owners) return List(owners)
} }
export const buildDailyLimitFrom = (dailyLimit: number): DailyLimit =>
makeDailyLimit({ value: dailyLimit, spentToday: 0 })
const addSafe = createAction( const addSafe = createAction(
ADD_SAFE, ADD_SAFE,
( (
name: string, address: string, name: string, address: string,
confirmations: number, dailyLimit: number, confirmations: number, limit: number,
ownersName: string[], ownersAddress: string[], ownersName: string[], ownersAddress: string[],
): SafeProps => { ): SafeProps => {
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress) const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
const dailyLimit: DailyLimit = buildDailyLimitFrom(limit)
return ({ return ({
address, name, confirmations, owners, dailyLimit, address, name, confirmations, owners, dailyLimit,

View File

@ -3,6 +3,18 @@ import { List, Record } from 'immutable'
import type { RecordFactory, RecordOf } from 'immutable' import type { RecordFactory, RecordOf } from 'immutable'
import type { Owner } from '~/routes/safe/store/model/owner' import type { Owner } from '~/routes/safe/store/model/owner'
export type DailyLimitProps = {
value: number,
spentToday: number,
}
export const makeDailyLimit: RecordFactory<DailyLimitProps> = Record({
value: 0,
spentToday: 0,
})
export type DailyLimit = RecordOf<DailyLimitProps>
export type SafeProps = { export type SafeProps = {
name: string, name: string,
address: string, address: string,
@ -16,7 +28,7 @@ export const makeSafe: RecordFactory<SafeProps> = Record({
address: '', address: '',
confirmations: 0, confirmations: 0,
owners: List([]), owners: List([]),
dailyLimit: 0, dailyLimit: makeDailyLimit(),
}) })
export type Safe = RecordOf<SafeProps> export type Safe = RecordOf<SafeProps>

View File

@ -1,6 +1,6 @@
// @flow // @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe' import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom } from '~/routes/safe/store/actions' import { buildOwnersFrom, buildDailyLimitFrom } from '~/routes/safe/store/actions'
class SafeBuilder { class SafeBuilder {
safe: Safe safe: Safe
@ -25,7 +25,8 @@ class SafeBuilder {
} }
withDailyLimit(limit: number) { withDailyLimit(limit: number) {
this.safe = this.safe.set('dailyLimit', limit) const dailyLimit = buildDailyLimitFrom(limit)
this.safe = this.safe.set('dailyLimit', dailyLimit)
return this return this
} }