diff --git a/src/routes/safe/container/actions.js b/src/routes/safe/container/actions.js index 19145afb..d10c0b1a 100644 --- a/src/routes/safe/container/actions.js +++ b/src/routes/safe/container/actions.js @@ -1,5 +1,5 @@ // @flow -import fetchSafe, { checkAndUpdateSafeOwners } from '~/routes/safe/store/actions/fetchSafe' +import fetchSafe, { checkAndUpdateSafe } from '~/routes/safe/store/actions/fetchSafe' import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances' import fetchEtherBalance from '~/routes/safe/store/actions/fetchEtherBalance' import createTransaction from '~/routes/safe/store/actions/createTransaction' @@ -31,5 +31,5 @@ export default { activateTokensByBalance, updateSafe, fetchEtherBalance, - checkAndUpdateSafeOwners, + checkAndUpdateSafeOwners: checkAndUpdateSafe, } diff --git a/src/routes/safe/store/actions/fetchSafe.js b/src/routes/safe/store/actions/fetchSafe.js index 6d9da670..a038f34e 100644 --- a/src/routes/safe/store/actions/fetchSafe.js +++ b/src/routes/safe/store/actions/fetchSafe.js @@ -11,6 +11,7 @@ import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3' import { loadFromStorage } from '~/utils/storage' import removeSafeOwner from '~/routes/safe/store/actions/removeSafeOwner' import addSafeOwner from '~/routes/safe/store/actions/addSafeOwner' +import updateSafeThreshold from '~/routes/safe/store/actions/updateSafeThreshold' const buildOwnersFrom = ( safeOwners: string[], @@ -43,13 +44,19 @@ const getLocalSafe = async (safeAddress: string) => { return storedSafes[safeAddress] } -export const checkAndUpdateSafeOwners = (safeAddress: string) => async (dispatch: ReduxDispatch) => { +export const checkAndUpdateSafe = (safeAddress: string) => async (dispatch: ReduxDispatch) => { // Check if the owner's safe did change and update them const [gnosisSafe, localSafe] = await Promise.all([getGnosisSafeInstanceAt(safeAddress), getLocalSafe(safeAddress)]) + const remoteOwners = await gnosisSafe.getOwners() // Converts from [ { address, ownerName} ] to address array const localOwners = localSafe.owners.map((localOwner) => localOwner.address) + // Updates threshold values + const threshold = await gnosisSafe.getThreshold() + localSafe.threshold = threshold.toNumber() + + dispatch(updateSafeThreshold({ safeAddress, threshold: threshold.toNumber() })) // If the remote owners does not contain a local address, we remove that local owner localOwners.forEach((localAddress) => { if (!remoteOwners.includes(localAddress)) { diff --git a/src/routes/safe/store/actions/updateSafeThreshold.js b/src/routes/safe/store/actions/updateSafeThreshold.js new file mode 100644 index 00000000..caad74ab --- /dev/null +++ b/src/routes/safe/store/actions/updateSafeThreshold.js @@ -0,0 +1,8 @@ +// @flow +import { createAction } from 'redux-actions' + +export const UPDATE_SAFE_THRESHOLD = 'UPDATE_SAFE_THRESHOLD' + +const updateSafeThreshold = createAction(UPDATE_SAFE_THRESHOLD) + +export default updateSafeThreshold diff --git a/src/routes/safe/store/reducer/safe.js b/src/routes/safe/store/reducer/safe.js index df7fed82..6e1aad6f 100644 --- a/src/routes/safe/store/reducer/safe.js +++ b/src/routes/safe/store/reducer/safe.js @@ -12,6 +12,7 @@ import { REMOVE_SAFE_OWNER } from '~/routes/safe/store/actions/removeSafeOwner' import { REPLACE_SAFE_OWNER } from '~/routes/safe/store/actions/replaceSafeOwner' import { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner' import { SET_DEFAULT_SAFE } from '~/routes/safe/store/actions/setDefaultSafe' +import { UPDATE_SAFE_THRESHOLD } from '~/routes/safe/store/actions/updateSafeThreshold' export const SAFE_REDUCER_ID = 'safes' @@ -115,6 +116,13 @@ export default handleActions( return prevSafe.merge({ owners: updatedOwners }) }) }, + [UPDATE_SAFE_THRESHOLD]: (state: SafeReducerState, action: ActionType): SafeReducerState => { + const { safeAddress, threshold } = action.payload + + return state.updateIn(['safes', safeAddress], (prevSafe) => { + return prevSafe.set('threshold', threshold) + }) + }, [SET_DEFAULT_SAFE]: (state: SafeReducerState, action: ActionType): SafeReducerState => state.set('defaultSafe', action.payload), }, Map({