WA-238 Adding Daily Limit when showing safe route
This commit is contained in:
parent
7a05972d7f
commit
d3ab3ec658
|
@ -3,7 +3,7 @@ import * as React from 'react'
|
|||
import { connect } from 'react-redux'
|
||||
import contract from 'truffle-contract'
|
||||
import Page from '~/components/layout/Page'
|
||||
import { getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom } from '~/routes/open/utils/safeDataExtractor'
|
||||
import { getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom, getDailyLimitFrom } from '~/routes/open/utils/safeDataExtractor'
|
||||
import { getWeb3 } from '~/wallets/getWeb3'
|
||||
import { promisify } from '~/utils/promisify'
|
||||
import Safe from '#/GnosisSafe.json'
|
||||
|
@ -26,12 +26,13 @@ const createSafe = async (safeContract, values, userAccount, addSafe) => {
|
|||
const numConfirmations = getThresholdFrom(values)
|
||||
const name = getSafeNameFrom(values)
|
||||
const owners = getNamesFrom(values)
|
||||
const dailyLimit = getDailyLimitFrom(values)
|
||||
|
||||
const web3 = getWeb3()
|
||||
safeContract.setProvider(web3.currentProvider)
|
||||
|
||||
const safe = await safeContract.new(accounts, numConfirmations, 0, 0, { from: userAccount, gas: '5000000' })
|
||||
addSafe(name, safe.address, numConfirmations, owners, accounts)
|
||||
addSafe(name, safe.address, numConfirmations, dailyLimit, owners, accounts)
|
||||
return safe
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
// @flow
|
||||
export const getDailyLimitFrom = (values: Object): number => Number(values.limit)
|
||||
|
||||
export const getAccountsFrom = (values: Object): string[] => {
|
||||
const accounts = Object.keys(values).sort().filter(key => /^owner\d+Address$/.test(key))
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// @flow
|
||||
import * as React from 'react'
|
||||
import { ListItem } from 'material-ui/List'
|
||||
import Avatar from 'material-ui/Avatar'
|
||||
import NotificationsPaused from 'material-ui-icons/NotificationsPaused'
|
||||
import ListItemText from '~/components/List/ListItemText'
|
||||
|
||||
type Props = {
|
||||
limit: number,
|
||||
}
|
||||
|
||||
const DailyLimit = ({ limit }: Props) => (
|
||||
<ListItem>
|
||||
<Avatar>
|
||||
<NotificationsPaused />
|
||||
</Avatar>
|
||||
<ListItemText primary="Daily Limit" secondary={`${limit} ETH`} />
|
||||
</ListItem>
|
||||
)
|
||||
|
||||
export default DailyLimit
|
|
@ -12,6 +12,7 @@ import Address from './Address'
|
|||
import Balance from './Balance'
|
||||
import Owners from './Owners'
|
||||
import Confirmations from './Confirmations'
|
||||
import DailyLimit from './DailyLimit'
|
||||
|
||||
type SafeProps = {
|
||||
safe: Safe,
|
||||
|
@ -34,6 +35,7 @@ class GnoSafe extends React.PureComponent<SafeProps> {
|
|||
<Owners owners={safe.owners} />
|
||||
<Confirmations confirmations={safe.get('confirmations')} />
|
||||
<Address address={safe.get('address')} />
|
||||
<DailyLimit limit={safe.get('dailyLimit')} />
|
||||
</List>
|
||||
</Col>
|
||||
<Col xs={12} center="xs" sm={8} margin="xl" layout="block">
|
||||
|
|
|
@ -15,13 +15,14 @@ export const buildOwnersFrom = (names: string[], addresses: string[]) => {
|
|||
const addSafe = createAction(
|
||||
ADD_SAFE,
|
||||
(
|
||||
name: string, address: string, confirmations: number,
|
||||
name: string, address: string,
|
||||
confirmations: number, dailyLimit: number,
|
||||
ownersName: string[], ownersAddress: string[],
|
||||
): SafeProps => {
|
||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||
|
||||
return ({
|
||||
address, name, confirmations, owners,
|
||||
address, name, confirmations, owners, dailyLimit,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
|
|
@ -8,6 +8,7 @@ export type SafeProps = {
|
|||
address: string,
|
||||
confirmations: number,
|
||||
owners: List<Owner>,
|
||||
dailyLimit: number,
|
||||
}
|
||||
|
||||
export const makeSafe: RecordFactory<SafeProps> = Record({
|
||||
|
@ -15,6 +16,7 @@ export const makeSafe: RecordFactory<SafeProps> = Record({
|
|||
address: '',
|
||||
confirmations: 0,
|
||||
owners: List([]),
|
||||
dailyLimit: 0,
|
||||
})
|
||||
|
||||
export type Safe = RecordOf<SafeProps>
|
||||
|
|
|
@ -24,6 +24,11 @@ class SafeBuilder {
|
|||
return this
|
||||
}
|
||||
|
||||
withDailyLimit(limit: number) {
|
||||
this.safe = this.safe.set('dailyLimit', limit)
|
||||
return this
|
||||
}
|
||||
|
||||
withOwner(names: string[], adresses: string[]) {
|
||||
const owners = buildOwnersFrom(names, adresses)
|
||||
this.safe = this.safe.set('owners', owners)
|
||||
|
@ -42,6 +47,7 @@ export class SafeFactory {
|
|||
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0025')
|
||||
.withName('Adol ICO Safe')
|
||||
.withConfirmations(1)
|
||||
.withDailyLimit(10)
|
||||
.withOwner(['Adol Metamask'], ['0x03db1a8b26d08df23337e9276a36b474510f0023'])
|
||||
.get()
|
||||
|
||||
|
|
|
@ -23,27 +23,31 @@ const aStore = (initState) => {
|
|||
const providerReducerTests = () => {
|
||||
describe('Safe Actions[addSafe]', () => {
|
||||
let store
|
||||
let address
|
||||
let formValues
|
||||
beforeEach(() => {
|
||||
store = aStore()
|
||||
})
|
||||
|
||||
it('reducer should return SafeRecord from form values', () => {
|
||||
// GIVEN
|
||||
const address = '0x03db1a8b26d08df23337e9276a36b474510f0025'
|
||||
const formValues = {
|
||||
address = '0x03db1a8b26d08df23337e9276a36b474510f0025'
|
||||
formValues = {
|
||||
[SafeFields.FIELD_NAME]: 'Adol ICO Safe',
|
||||
[SafeFields.FIELD_CONFIRMATIONS]: 1,
|
||||
[SafeFields.FIELD_OWNERS]: 1,
|
||||
[SafeFields.FIELD_DAILY_LIMIT]: 10,
|
||||
[SafeFields.getOwnerAddressBy(0)]: '0x03db1a8b26d08df23337e9276a36b474510f0023',
|
||||
[SafeFields.getOwnerNameBy(0)]: 'Adol Metamask',
|
||||
address,
|
||||
}
|
||||
})
|
||||
|
||||
it('reducer should return SafeRecord from form values', () => {
|
||||
// GIVEN in beforeEach method
|
||||
|
||||
// WHEN
|
||||
store.dispatch(addSafe(
|
||||
formValues[SafeFields.FIELD_NAME],
|
||||
formValues.address,
|
||||
formValues[SafeFields.FIELD_CONFIRMATIONS],
|
||||
formValues[SafeFields.FIELD_DAILY_LIMIT],
|
||||
getNamesFrom(formValues),
|
||||
getAccountsFrom(formValues),
|
||||
))
|
||||
|
@ -54,22 +58,14 @@ const providerReducerTests = () => {
|
|||
})
|
||||
|
||||
it('reducer loads information from localStorage', async () => {
|
||||
// GIVEN
|
||||
const address = '0x03db1a8b26d08df23337e9276a36b474510f0025'
|
||||
const formValues = {
|
||||
[SafeFields.FIELD_NAME]: 'Adol ICO Safe',
|
||||
[SafeFields.FIELD_CONFIRMATIONS]: 1,
|
||||
[SafeFields.FIELD_OWNERS]: 1,
|
||||
[SafeFields.getOwnerAddressBy(0)]: '0x03db1a8b26d08df23337e9276a36b474510f0023',
|
||||
[SafeFields.getOwnerNameBy(0)]: 'Adol Metamask',
|
||||
address,
|
||||
}
|
||||
// GIVEN in beforeEach method
|
||||
|
||||
// WHEN
|
||||
store.dispatch(addSafe(
|
||||
formValues[SafeFields.FIELD_NAME],
|
||||
formValues.address,
|
||||
formValues[SafeFields.FIELD_CONFIRMATIONS],
|
||||
formValues[SafeFields.FIELD_DAILY_LIMIT],
|
||||
getNamesFrom(formValues),
|
||||
getAccountsFrom(formValues),
|
||||
))
|
||||
|
|
Loading…
Reference in New Issue