Implementation of removing owner logic indepentdently the order
This commit is contained in:
parent
ef17ca59a5
commit
9e6c97aea8
|
@ -23,7 +23,8 @@ type Props = {
|
|||
classes: Object,
|
||||
otherAccounts: string[],
|
||||
errors: Object,
|
||||
// updateInitialProps: () => void,
|
||||
values: Object,
|
||||
updateInitialProps: (initialValues: Object) => void,
|
||||
}
|
||||
|
||||
type State = {
|
||||
|
@ -64,18 +65,32 @@ const getAddressValidators = (addresses: string[], position: number) => {
|
|||
|
||||
const noErrorsOn = (name: string, errors: Object) => errors[name] === undefined
|
||||
|
||||
export const calculateValuesAfterRemoving = (index: number, notRemovedOwners: number, values: Object) => {
|
||||
const initialValues = { ...values }
|
||||
const numOwnersAfterRemoving = notRemovedOwners - 1
|
||||
// muevo indices
|
||||
for (let i = index; i < numOwnersAfterRemoving; i += 1) {
|
||||
initialValues[getOwnerNameBy(i)] = values[getOwnerNameBy(i + 1)]
|
||||
initialValues[getOwnerAddressBy(i)] = values[getOwnerAddressBy(i + 1)]
|
||||
}
|
||||
|
||||
delete initialValues[getOwnerNameBy(numOwnersAfterRemoving)]
|
||||
delete initialValues[getOwnerAddressBy(numOwnersAfterRemoving)]
|
||||
|
||||
return initialValues
|
||||
}
|
||||
|
||||
class SafeOwners extends React.Component<Props, State> {
|
||||
state = {
|
||||
numOwners: 3,
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
onRemoveRow = (index: number) => () => {
|
||||
/*
|
||||
this.props.updateInitialProps({
|
||||
owner0Address: 'moeFeo',
|
||||
})
|
||||
*/
|
||||
const { values } = this.props
|
||||
const { numOwners } = this.state
|
||||
const initialValues = calculateValuesAfterRemoving(index, numOwners, values)
|
||||
this.props.updateInitialProps(initialValues)
|
||||
|
||||
|
||||
this.setState(state => ({
|
||||
numOwners: state.numOwners - 1,
|
||||
|
@ -161,6 +176,7 @@ const SafeOwnersPage = ({ updateInitialProps }: Object) => (controls: React$Node
|
|||
otherAccounts={getAccountsFrom(values)}
|
||||
errors={errors}
|
||||
updateInitialProps={updateInitialProps}
|
||||
values={values}
|
||||
/>
|
||||
</OpenPaper>
|
||||
</React.Fragment>
|
||||
|
|
|
@ -13,8 +13,10 @@ import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
|
|||
import { removeOwner, shouldDecrease, initialValuesFrom } from '~/routes/safe/component/RemoveOwner'
|
||||
import { DECREASE_PARAM } from '~/routes/safe/component/RemoveOwner/RemoveOwnerForm'
|
||||
import { getSafeFrom } from '~/test/utils/safeHelper'
|
||||
import { getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields'
|
||||
import { processTransaction } from '~/logic/safe/safeFrontendOperations'
|
||||
import { allowedRemoveSenderInTxHistoryService } from '~/config'
|
||||
import { calculateValuesAfterRemoving } from '~/routes/open/components/SafeOwnersForm'
|
||||
|
||||
describe('React DOM TESTS > Add and remove owners', () => {
|
||||
const processOwnerModification = async (store, safeAddress, executor, threshold) => {
|
||||
|
@ -46,6 +48,54 @@ describe('React DOM TESTS > Add and remove owners', () => {
|
|||
|
||||
const getAddressesFrom = (safe: Safe) => safe.get('owners').map(owner => owner.get('address'))
|
||||
|
||||
it.only('creates initialValues removing last owner', () => {
|
||||
const numOwners = 3
|
||||
const values = {
|
||||
moe: 'Bart',
|
||||
[getOwnerNameBy(0)]: 'Foo',
|
||||
[getOwnerAddressBy(0)]: '0x1',
|
||||
[getOwnerNameBy(1)]: 'Bar',
|
||||
[getOwnerAddressBy(1)]: '0x2',
|
||||
[getOwnerNameBy(2)]: 'Baz',
|
||||
[getOwnerAddressBy(2)]: '0x3',
|
||||
}
|
||||
|
||||
const indexToRemove = 2
|
||||
const initialValues = calculateValuesAfterRemoving(indexToRemove, numOwners, values)
|
||||
|
||||
expect(initialValues).toEqual({
|
||||
moe: 'Bart',
|
||||
[getOwnerNameBy(0)]: 'Foo',
|
||||
[getOwnerAddressBy(0)]: '0x1',
|
||||
[getOwnerNameBy(1)]: 'Bar',
|
||||
[getOwnerAddressBy(1)]: '0x2',
|
||||
})
|
||||
})
|
||||
|
||||
it.only('creates initialValues removing middle owner', () => {
|
||||
const numOwners = 3
|
||||
const values = {
|
||||
moe: 'Bart',
|
||||
[getOwnerNameBy(0)]: 'Foo',
|
||||
[getOwnerAddressBy(0)]: '0x1',
|
||||
[getOwnerNameBy(1)]: 'Bar',
|
||||
[getOwnerAddressBy(1)]: '0x2',
|
||||
[getOwnerNameBy(2)]: 'Baz',
|
||||
[getOwnerAddressBy(2)]: '0x3',
|
||||
}
|
||||
|
||||
const indexToRemove = 1
|
||||
const initialValues = calculateValuesAfterRemoving(indexToRemove, numOwners, values)
|
||||
|
||||
expect(initialValues).toEqual({
|
||||
moe: 'Bart',
|
||||
[getOwnerNameBy(0)]: 'Foo',
|
||||
[getOwnerAddressBy(0)]: '0x1',
|
||||
[getOwnerNameBy(1)]: 'Baz',
|
||||
[getOwnerAddressBy(1)]: '0x3',
|
||||
})
|
||||
})
|
||||
|
||||
it('adds owner without increasing the threshold', async () => {
|
||||
// GIVEN
|
||||
const numOwners = 2
|
||||
|
|
Loading…
Reference in New Issue