add modules
This commit is contained in:
parent
51634e559d
commit
2d8da9ca98
|
@ -0,0 +1,7 @@
|
|||
import { createAction } from 'redux-actions'
|
||||
|
||||
export const ADD_SAFE_MODULES = 'ADD_SAFE_MODULES'
|
||||
|
||||
const addSafeModules = createAction(ADD_SAFE_MODULES)
|
||||
|
||||
export default addSafeModules
|
|
@ -13,6 +13,7 @@ import updateSafe from 'src/routes/safe/store/actions/updateSafe'
|
|||
import { makeOwner } from 'src/routes/safe/store/models/owner'
|
||||
|
||||
import { checksumAddress } from 'src/utils/checksumAddress'
|
||||
import addSafeModules from './addSafeModules'
|
||||
|
||||
const buildOwnersFrom = (
|
||||
safeOwners,
|
||||
|
@ -73,8 +74,8 @@ export const buildSafe = async (safeAdd, safeName, latestMasterContractVersion?:
|
|||
export const checkAndUpdateSafe = (safeAdd) => async (dispatch) => {
|
||||
const safeAddress = checksumAddress(safeAdd)
|
||||
// Check if the owner's safe did change and update them
|
||||
const safeParams = ['getThreshold', 'nonce', 'getOwners']
|
||||
const [[remoteThreshold, remoteNonce, remoteOwners], localSafe] = await Promise.all([
|
||||
const safeParams = ['getThreshold', 'nonce', 'getOwners', 'getModules']
|
||||
const [[remoteThreshold, remoteNonce, remoteOwners, remoteModules], localSafe] = await Promise.all([
|
||||
generateBatchRequests({
|
||||
abi: GnosisSafeSol.abi,
|
||||
address: safeAddress,
|
||||
|
@ -88,6 +89,13 @@ export const checkAndUpdateSafe = (safeAdd) => async (dispatch) => {
|
|||
const localThreshold = localSafe ? localSafe.threshold : undefined
|
||||
const localNonce = localSafe ? localSafe.nonce : undefined
|
||||
|
||||
dispatch(
|
||||
addSafeModules({
|
||||
safeAddress,
|
||||
modulesAddresses: remoteModules,
|
||||
}),
|
||||
)
|
||||
|
||||
if (localNonce !== Number(remoteNonce)) {
|
||||
dispatch(updateSafe({ address: safeAddress, nonce: Number(remoteNonce) }))
|
||||
}
|
||||
|
|
|
@ -12,8 +12,9 @@ import { SET_DEFAULT_SAFE } from 'src/routes/safe/store/actions/setDefaultSafe'
|
|||
import { SET_LATEST_MASTER_CONTRACT_VERSION } from 'src/routes/safe/store/actions/setLatestMasterContractVersion'
|
||||
import { UPDATE_SAFE } from 'src/routes/safe/store/actions/updateSafe'
|
||||
import { makeOwner } from 'src/routes/safe/store/models/owner'
|
||||
import makeSafe from 'src/routes/safe/store/models/safe'
|
||||
import makeSafe, { SafeRecord } from 'src/routes/safe/store/models/safe'
|
||||
import { checksumAddress } from 'src/utils/checksumAddress'
|
||||
import { ADD_SAFE_MODULES } from '../actions/addSafeModules'
|
||||
|
||||
export const SAFE_REDUCER_ID = 'safes'
|
||||
|
||||
|
@ -40,15 +41,24 @@ export const buildSafe = (storedSafe) => {
|
|||
return safe
|
||||
}
|
||||
|
||||
export interface SafeStore {
|
||||
defaultSafe: SafeRecord | any
|
||||
safes: Map<string, Map<keyof SafeRecord, SafeRecord[keyof SafeRecord]>>
|
||||
latestMasterContractVersion: string
|
||||
}
|
||||
|
||||
type ValueOf<T> = T[keyof T]
|
||||
export type SafeStoreState = Map<keyof SafeStore, ValueOf<SafeStore>>
|
||||
|
||||
export default handleActions(
|
||||
{
|
||||
[UPDATE_SAFE]: (state, action) => {
|
||||
[UPDATE_SAFE]: (state: SafeStoreState, action) => {
|
||||
const safe = action.payload
|
||||
const safeAddress = safe.address
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) => prevSafe.merge(safe))
|
||||
},
|
||||
[ACTIVATE_TOKEN_FOR_ALL_SAFES]: (state, action) => {
|
||||
[ACTIVATE_TOKEN_FOR_ALL_SAFES]: (state: SafeStoreState, action) => {
|
||||
const tokenAddress = action.payload
|
||||
|
||||
return state.withMutations((map) => {
|
||||
|
@ -63,7 +73,7 @@ export default handleActions(
|
|||
})
|
||||
})
|
||||
},
|
||||
[ADD_SAFE]: (state, action) => {
|
||||
[ADD_SAFE]: (state: SafeStoreState, action) => {
|
||||
const { safe } = action.payload
|
||||
|
||||
// if you add a new Safe it needs to be set as a record
|
||||
|
@ -76,12 +86,12 @@ export default handleActions(
|
|||
|
||||
return state.setIn([SAFE_REDUCER_ID, safe.address], makeSafe(safe))
|
||||
},
|
||||
[REMOVE_SAFE]: (state, action) => {
|
||||
[REMOVE_SAFE]: (state: SafeStoreState, action) => {
|
||||
const safeAddress = action.payload
|
||||
|
||||
return state.deleteIn([SAFE_REDUCER_ID, safeAddress])
|
||||
},
|
||||
[ADD_SAFE_OWNER]: (state, action) => {
|
||||
[ADD_SAFE_OWNER]: (state: SafeStoreState, action) => {
|
||||
const { ownerAddress, ownerName, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) =>
|
||||
|
@ -90,7 +100,11 @@ export default handleActions(
|
|||
}),
|
||||
)
|
||||
},
|
||||
[REMOVE_SAFE_OWNER]: (state, action) => {
|
||||
[ADD_SAFE_MODULES]: (state: SafeStoreState, action) => {
|
||||
const { modulesAddresses, safeAddress } = action.payload
|
||||
return state.setIn([SAFE_REDUCER_ID, safeAddress, 'modules'], modulesAddresses)
|
||||
},
|
||||
[REMOVE_SAFE_OWNER]: (state: SafeStoreState, action) => {
|
||||
const { ownerAddress, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) =>
|
||||
|
@ -99,7 +113,7 @@ export default handleActions(
|
|||
}),
|
||||
)
|
||||
},
|
||||
[REPLACE_SAFE_OWNER]: (state, action) => {
|
||||
[REPLACE_SAFE_OWNER]: (state: SafeStoreState, action) => {
|
||||
const { oldOwnerAddress, ownerAddress, ownerName, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) =>
|
||||
|
@ -110,7 +124,7 @@ export default handleActions(
|
|||
}),
|
||||
)
|
||||
},
|
||||
[EDIT_SAFE_OWNER]: (state, action) => {
|
||||
[EDIT_SAFE_OWNER]: (state: SafeStoreState, action) => {
|
||||
const { ownerAddress, ownerName, safeAddress } = action.payload
|
||||
|
||||
return state.updateIn([SAFE_REDUCER_ID, safeAddress], (prevSafe) => {
|
||||
|
@ -121,14 +135,13 @@ export default handleActions(
|
|||
return prevSafe.merge({ owners: updatedOwners })
|
||||
})
|
||||
},
|
||||
[SET_DEFAULT_SAFE]: (state, action) => state.set('defaultSafe', action.payload),
|
||||
[SET_LATEST_MASTER_CONTRACT_VERSION]: (state, action) => state.set('latestMasterContractVersion', action.payload),
|
||||
[SET_DEFAULT_SAFE]: (state: SafeStoreState, action) => state.set('defaultSafe', action.payload),
|
||||
[SET_LATEST_MASTER_CONTRACT_VERSION]: (state: SafeStoreState, action) =>
|
||||
state.set('latestMasterContractVersion', action.payload),
|
||||
},
|
||||
Map({
|
||||
// $FlowFixMe
|
||||
defaultSafe: undefined,
|
||||
safes: Map(),
|
||||
// $FlowFixMe
|
||||
latestMasterContractVersion: '',
|
||||
}),
|
||||
)
|
||||
|
|
|
@ -11,10 +11,11 @@ import { SAFE_REDUCER_ID } from 'src/routes/safe/store/reducer/safe'
|
|||
import { TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/transactions'
|
||||
|
||||
import { checksumAddress } from 'src/utils/checksumAddress'
|
||||
import makeSafe, { SafeRecord, SafeRecordProps } from '../models/safe'
|
||||
|
||||
const safesStateSelector = (state) => state[SAFE_REDUCER_ID]
|
||||
|
||||
export const safesMapSelector = (state) => state[SAFE_REDUCER_ID].get('safes')
|
||||
export const safesMapSelector = (state) => safesStateSelector(state).get('safes')
|
||||
|
||||
export const safesListSelector = createSelector(safesMapSelector, (safes) => safes.toList())
|
||||
|
||||
|
@ -106,30 +107,36 @@ export const safeIncomingTransactionsSelector = createSelector(
|
|||
},
|
||||
)
|
||||
|
||||
export const safeSelector = createSelector(safesMapSelector, safeParamAddressFromStateSelector, (safes, address) => {
|
||||
export const safeSelector = createSelector(safesMapSelector, safeParamAddressFromStateSelector, (safes, address):
|
||||
| SafeRecord
|
||||
| undefined => {
|
||||
if (!address) {
|
||||
return undefined
|
||||
}
|
||||
const checksumed = checksumAddress(address)
|
||||
const safe = safes.get(checksumed)
|
||||
|
||||
return safe
|
||||
return safes.get(checksumed)
|
||||
})
|
||||
|
||||
export const safeActiveTokensSelector = createSelector(safeSelector, (safe) => {
|
||||
if (!safe) {
|
||||
return List()
|
||||
}
|
||||
export const safeActiveTokensSelector = createSelector(
|
||||
safeSelector,
|
||||
(safe): Set<string> => {
|
||||
if (!safe) {
|
||||
return Set()
|
||||
}
|
||||
|
||||
return safe.activeTokens
|
||||
})
|
||||
return safe.activeTokens
|
||||
},
|
||||
)
|
||||
|
||||
export const safeActiveAssetsSelector = createSelector(safeSelector, (safe) => {
|
||||
if (!safe) {
|
||||
return List()
|
||||
}
|
||||
return safe.activeAssets
|
||||
})
|
||||
export const safeActiveAssetsSelector = createSelector(
|
||||
safeSelector,
|
||||
(safe): Set<string> => {
|
||||
if (!safe) {
|
||||
return Set<string>()
|
||||
}
|
||||
return safe.activeAssets
|
||||
},
|
||||
)
|
||||
|
||||
export const safeActiveAssetsListSelector = createSelector(safeActiveAssetsSelector, (safeList) => {
|
||||
if (!safeList) {
|
||||
|
@ -159,15 +166,22 @@ export const safeActiveAssetsSelectorBySafe = (safeAddress, safes) => safes.get(
|
|||
export const safeBlacklistedAssetsSelectorBySafe = (safeAddress, safes) =>
|
||||
safes.get(safeAddress).get('blacklistedAssets')
|
||||
|
||||
export const safeBalancesSelector = createSelector(safeSelector, (safe) => {
|
||||
if (!safe) {
|
||||
return List()
|
||||
}
|
||||
export const safeBalancesSelector = createSelector(
|
||||
safeSelector,
|
||||
(safe): Map<string, string> => {
|
||||
if (!safe) {
|
||||
return Map()
|
||||
}
|
||||
|
||||
return safe.balances
|
||||
})
|
||||
return safe.balances
|
||||
},
|
||||
)
|
||||
|
||||
export const safeFieldSelector = (field) => (safe) => safe?.[field]
|
||||
const baseSafe = makeSafe()
|
||||
|
||||
export const safeFieldSelector = (field: keyof SafeRecordProps) => (
|
||||
safe: SafeRecord,
|
||||
): SafeRecord[keyof SafeRecordProps] => safe.get(field, baseSafe.get(field))
|
||||
|
||||
export const safeNameSelector = createSelector(safeSelector, safeFieldSelector('name'))
|
||||
|
||||
|
@ -183,6 +197,8 @@ export const safeNonceSelector = createSelector(safeSelector, safeFieldSelector(
|
|||
|
||||
export const safeOwnersSelector = createSelector(safeSelector, safeFieldSelector('owners'))
|
||||
|
||||
export const safeModulesSelector = createSelector(safeSelector, safeFieldSelector('modules'))
|
||||
|
||||
export const safeFeaturesEnabledSelector = createSelector(safeSelector, safeFieldSelector('featuresEnabled'))
|
||||
|
||||
export const getActiveTokensAddressesForAllSafes = createSelector(safesListSelector, (safes) => {
|
||||
|
|
Loading…
Reference in New Issue