Adds update owner's list to the polling function

This commit is contained in:
apane 2019-11-14 13:46:35 -03:00
parent 54cb38b864
commit 1c8f6b42c5
1 changed files with 15 additions and 13 deletions

View File

@ -9,7 +9,8 @@ import { getOwners, getSafeName, SAFES_KEY } from '~/logic/safe/utils'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3' import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import { loadFromStorage } from '~/utils/storage' import { loadFromStorage } from '~/utils/storage'
import updateSafe from '~/routes/safe/store/actions/updateSafe' import removeSafeOwner from '~/routes/safe/store/actions/removeSafeOwner'
import addSafeOwner from '~/routes/safe/store/actions/addSafeOwner'
const buildOwnersFrom = ( const buildOwnersFrom = (
safeOwners: string[], safeOwners: string[],
@ -48,21 +49,22 @@ export const checkAndUpdateSafeOwners = (safeAddress: string) => async (
// Check if the owner's safe did change and update them // Check if the owner's safe did change and update them
const [gnosisSafe, localSafe] = await Promise.all([getGnosisSafeInstanceAt(safeAddress), getLocalSafe(safeAddress)]) const [gnosisSafe, localSafe] = await Promise.all([getGnosisSafeInstanceAt(safeAddress), getLocalSafe(safeAddress)])
const remoteOwners = await gnosisSafe.getOwners() const remoteOwners = await gnosisSafe.getOwners()
// Converts from [ { address, ownerName} ] to address array
const localOwners = localSafe.owners.map((localOwner) => localOwner.address) const localOwners = localSafe.owners.map((localOwner) => localOwner.address)
if (remoteOwners.length !== localOwners.length) { // If the remote owners does not contain a local address, we remove that local owner
dispatch(updateSafe({ address: safeAddress, owners: remoteOwners })) localOwners.forEach((localAddress) => {
return if (!remoteOwners.includes(localAddress)) {
dispatch(removeSafeOwner({ safeAddress, ownerAddress: localAddress }))
} }
})
// eslint-disable-next-line no-restricted-syntax // If the remote has an owner that we don't have locally, we add it
for (const remoteIterator of remoteOwners) { remoteOwners.forEach((remoteAddress) => {
if (!localOwners.includes(remoteIterator)) { if (!localOwners.includes(remoteAddress)) {
dispatch(updateSafe({ address: safeAddress, owners: remoteOwners })) dispatch(addSafeOwner({ safeAddress, ownerAddress: remoteAddress, ownerName: 'UNKNOWN' }))
return
}
} }
})
} }
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return