WA-238 Storybook showing spentToday and disabling withdrawn buttons is limit has been exceeded
This commit is contained in:
parent
706bdba69b
commit
f04eec5f77
|
@ -30,8 +30,20 @@ storiesOf('Routes /safe:address', module)
|
||||||
fetchBalance={() => {}}
|
fetchBalance={() => {}}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add('Safe with 2 owners', () => {
|
.add('Safe with 2 owners and 10ETH as dailyLimit', () => {
|
||||||
const safe = SafeFactory.twoOwnersSafe
|
const safe = SafeFactory.dailyLimitSafe(10, 1.345)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Component
|
||||||
|
safe={safe}
|
||||||
|
provider="METAMASK"
|
||||||
|
balance="2"
|
||||||
|
fetchBalance={() => {}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.add('Safe with dailyLimit reached', () => {
|
||||||
|
const safe = SafeFactory.dailyLimitSafe(10, 10)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Component
|
<Component
|
||||||
|
|
|
@ -7,22 +7,24 @@ import Button from '~/components/layout/Button'
|
||||||
import ListItemText from '~/components/List/ListItemText'
|
import ListItemText from '~/components/List/ListItemText'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
dailyLimit: number,
|
dailyLimit: DailyLimit,
|
||||||
onWithdrawn: () => void,
|
onWithdrawn: () => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WITHDRAWN_BUTTON_TEXT = 'Withdrawn'
|
export const WITHDRAWN_BUTTON_TEXT = 'Withdrawn'
|
||||||
|
|
||||||
const DailyLimit = ({ dailyLimit, onWithdrawn }: Props) => {
|
const DailyLimitComponent = ({ dailyLimit, onWithdrawn }: Props) => {
|
||||||
const limit = dailyLimit.get('value')
|
const limit = dailyLimit.get('value')
|
||||||
const disabled = dailyLimit.get('todaySpent') > limit
|
const spentToday = dailyLimit.get('spentToday')
|
||||||
|
const disabled = spentToday >= limit
|
||||||
|
const text = `${limit} ETH (spent today: ${spentToday} ETH)`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem>
|
<ListItem>
|
||||||
<Avatar>
|
<Avatar>
|
||||||
<NotificationsPaused />
|
<NotificationsPaused />
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<ListItemText primary="Daily Limit" secondary={`${limit} ETH`} />
|
<ListItemText primary="Daily Limit" secondary={text} />
|
||||||
<Button
|
<Button
|
||||||
variant="raised"
|
variant="raised"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
@ -35,4 +37,4 @@ const DailyLimit = ({ dailyLimit, onWithdrawn }: Props) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DailyLimit
|
export default DailyLimitComponent
|
||||||
|
|
|
@ -13,8 +13,8 @@ export const buildOwnersFrom = (names: string[], addresses: string[]) => {
|
||||||
return List(owners)
|
return List(owners)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildDailyLimitFrom = (dailyLimit: number): DailyLimit =>
|
export const buildDailyLimitFrom = (dailyLimit: number, spentToday: number = 0): DailyLimit =>
|
||||||
makeDailyLimit({ value: dailyLimit, spentToday: 0 })
|
makeDailyLimit({ value: dailyLimit, spentToday })
|
||||||
|
|
||||||
const addSafe = createAction(
|
const addSafe = createAction(
|
||||||
ADD_SAFE,
|
ADD_SAFE,
|
||||||
|
|
|
@ -24,8 +24,8 @@ class SafeBuilder {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
withDailyLimit(limit: number) {
|
withDailyLimit(limit: number, spentToday: number = 0) {
|
||||||
const dailyLimit = buildDailyLimitFrom(limit)
|
const dailyLimit = buildDailyLimitFrom(limit, spentToday)
|
||||||
this.safe = this.safe.set('dailyLimit', dailyLimit)
|
this.safe = this.safe.set('dailyLimit', dailyLimit)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,18 @@ export class SafeFactory {
|
||||||
['Adol Metamask', 'Tobias Metamask'],
|
['Adol Metamask', 'Tobias Metamask'],
|
||||||
['0x03db1a8b26d08df23337e9276a36b474510f0023', '0x03db1a8b26d08df23337e9276a36b474510f0024'],
|
['0x03db1a8b26d08df23337e9276a36b474510f0023', '0x03db1a8b26d08df23337e9276a36b474510f0024'],
|
||||||
)
|
)
|
||||||
|
.withDailyLimit(10, 1.34)
|
||||||
|
.get()
|
||||||
|
|
||||||
|
static dailyLimitSafe = (dailyLimit: number, spentToday: number) => aSafe()
|
||||||
|
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0026')
|
||||||
|
.withName('Adol & Tobias Safe')
|
||||||
|
.withConfirmations(2)
|
||||||
|
.withOwner(
|
||||||
|
['Adol Metamask', 'Tobias Metamask'],
|
||||||
|
['0x03db1a8b26d08df23337e9276a36b474510f0023', '0x03db1a8b26d08df23337e9276a36b474510f0024'],
|
||||||
|
)
|
||||||
|
.withDailyLimit(dailyLimit, spentToday)
|
||||||
.get()
|
.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue