refactor: prevent using reducer's name for field selection
This commit is contained in:
parent
3b7992a9e1
commit
c74b79bf67
|
@ -25,7 +25,7 @@ const fetchSafeTokens = (safeAddress: string) => async (
|
|||
): Promise<void> => {
|
||||
try {
|
||||
const state = getState()
|
||||
const safe = state[SAFE_REDUCER_ID].getIn([SAFE_REDUCER_ID, safeAddress])
|
||||
const safe = state[SAFE_REDUCER_ID].getIn(['safes', safeAddress])
|
||||
const currentTokens = state[TOKEN_REDUCER_ID]
|
||||
|
||||
if (!safe) {
|
||||
|
|
|
@ -11,7 +11,7 @@ const fetchEtherBalance = (safeAddress: string) => async (
|
|||
): Promise<void> => {
|
||||
try {
|
||||
const state = getState()
|
||||
const ethBalance = state[SAFE_REDUCER_ID].getIn([SAFE_REDUCER_ID, safeAddress, 'ethBalance'])
|
||||
const ethBalance = state[SAFE_REDUCER_ID].getIn(['safes', safeAddress, 'ethBalance'])
|
||||
const newEthBalance = await backOff(() => getBalanceInEtherOf(safeAddress))
|
||||
if (newEthBalance !== ethBalance) {
|
||||
dispatch(updateSafe({ address: safeAddress, ethBalance: newEthBalance }))
|
||||
|
|
|
@ -196,7 +196,7 @@ export const loadOutgoingTransactions = async (safeAddress: string): Promise<Saf
|
|||
|
||||
const knownTokens = state[TOKEN_REDUCER_ID]
|
||||
const currentUser = state[PROVIDER_REDUCER_ID].get('account')
|
||||
const safe = state[SAFE_REDUCER_ID].getIn([SAFE_REDUCER_ID, safeAddress])
|
||||
const safe = state[SAFE_REDUCER_ID].getIn(['safes', safeAddress])
|
||||
|
||||
if (!safe) {
|
||||
return defaultResponse
|
||||
|
|
|
@ -341,7 +341,7 @@ export const mockTransaction = (tx: TxToMock, safeAddress: string, state): Promi
|
|||
}
|
||||
|
||||
const knownTokens: Map<string, Token> = state[TOKEN_REDUCER_ID]
|
||||
const safe: SafeRecord = state[SAFE_REDUCER_ID].getIn([SAFE_REDUCER_ID, safeAddress])
|
||||
const safe: SafeRecord = state[SAFE_REDUCER_ID].getIn(['safes', safeAddress])
|
||||
const cancellationTxs = state[CANCELLATION_TRANSACTIONS_REDUCER_ID].get(safeAddress) || Map()
|
||||
const outgoingTxs = state[TRANSACTIONS_REDUCER_ID].get(safeAddress) || List()
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ export default handleActions(
|
|||
const safeAddress = safe.address
|
||||
|
||||
return state.updateIn(
|
||||
[SAFE_REDUCER_ID, safeAddress],
|
||||
['safes', safeAddress],
|
||||
makeSafe({ name: 'LOADED SAFE', address: safeAddress }),
|
||||
(prevSafe) => prevSafe.merge(safe),
|
||||
)
|
||||
|
@ -60,13 +60,13 @@ export default handleActions(
|
|||
|
||||
return state.withMutations((map) => {
|
||||
map
|
||||
.get(SAFE_REDUCER_ID)
|
||||
.get('safes')
|
||||
.keySeq()
|
||||
.forEach((safeAddress) => {
|
||||
const safeActiveTokens = map.getIn([SAFE_REDUCER_ID, safeAddress, 'activeTokens'])
|
||||
const safeActiveTokens = map.getIn(['safes', safeAddress, 'activeTokens'])
|
||||
const activeTokens = safeActiveTokens.add(tokenAddress)
|
||||
|
||||
map.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) => prevSafe.merge({ activeTokens }))
|
||||
map.updateIn(['safes', safeAddress], (prevSafe) => prevSafe.merge({ activeTokens }))
|
||||
})
|
||||
})
|
||||
},
|
||||
|
@ -77,21 +77,21 @@ export default handleActions(
|
|||
// in case of update it shouldn't, because a record would be initialized
|
||||
// with initial props and it would overwrite existing ones
|
||||
|
||||
if (state.hasIn([SAFE_REDUCER_ID, safe.address])) {
|
||||
return state.updateIn([SAFE_REDUCER_ID, safe.address], (prevSafe) => prevSafe.merge(safe))
|
||||
if (state.hasIn(['safes', safe.address])) {
|
||||
return state.updateIn(['safes', safe.address], (prevSafe) => prevSafe.merge(safe))
|
||||
}
|
||||
|
||||
return state.setIn([SAFE_REDUCER_ID, safe.address], makeSafe(safe))
|
||||
return state.setIn(['safes', safe.address], makeSafe(safe))
|
||||
},
|
||||
[REMOVE_SAFE]: (state: SafeReducerMap, action) => {
|
||||
const safeAddress = action.payload
|
||||
|
||||
return state.deleteIn([SAFE_REDUCER_ID, safeAddress])
|
||||
return state.deleteIn(['safes', safeAddress])
|
||||
},
|
||||
[ADD_SAFE_OWNER]: (state: SafeReducerMap, action) => {
|
||||
const { ownerAddress, ownerName, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) =>
|
||||
return state.updateIn(['safes', safeAddress], (prevSafe) =>
|
||||
prevSafe.merge({
|
||||
owners: prevSafe.owners.push(makeOwner({ address: ownerAddress, name: ownerName })),
|
||||
}),
|
||||
|
@ -100,7 +100,7 @@ export default handleActions(
|
|||
[REMOVE_SAFE_OWNER]: (state: SafeReducerMap, action) => {
|
||||
const { ownerAddress, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) =>
|
||||
return state.updateIn(['safes', safeAddress], (prevSafe) =>
|
||||
prevSafe.merge({
|
||||
owners: prevSafe.owners.filter((o) => o.address.toLowerCase() !== ownerAddress.toLowerCase()),
|
||||
}),
|
||||
|
@ -109,7 +109,7 @@ export default handleActions(
|
|||
[REPLACE_SAFE_OWNER]: (state: SafeReducerMap, action) => {
|
||||
const { oldOwnerAddress, ownerAddress, ownerName, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) =>
|
||||
return state.updateIn(['safes', safeAddress], (prevSafe) =>
|
||||
prevSafe.merge({
|
||||
owners: prevSafe.owners
|
||||
.filter((o) => o.address.toLowerCase() !== oldOwnerAddress.toLowerCase())
|
||||
|
@ -120,7 +120,7 @@ export default handleActions(
|
|||
[EDIT_SAFE_OWNER]: (state: SafeReducerMap, action) => {
|
||||
const { ownerAddress, ownerName, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) => {
|
||||
return state.updateIn(['safes', safeAddress], (prevSafe) => {
|
||||
const ownerToUpdateIndex = prevSafe.owners.findIndex(
|
||||
(o) => o.address.toLowerCase() === ownerAddress.toLowerCase(),
|
||||
)
|
||||
|
@ -130,7 +130,7 @@ export default handleActions(
|
|||
},
|
||||
[ADD_SAFE_MODULES]: (state: SafeReducerMap, action) => {
|
||||
const { modulesAddresses, safeAddress } = action.payload
|
||||
return state.setIn([SAFE_REDUCER_ID, safeAddress, 'modules'], modulesAddresses)
|
||||
return state.setIn(['safes', safeAddress, 'modules'], modulesAddresses)
|
||||
},
|
||||
[SET_DEFAULT_SAFE]: (state: SafeReducerMap, action) => state.set('defaultSafe', action.payload),
|
||||
[SET_LATEST_MASTER_CONTRACT_VERSION]: (state: SafeReducerMap, action) =>
|
||||
|
|
Loading…
Reference in New Issue