Adds update owner's list to the polling function

This commit is contained in:
apane 2019-11-14 12:19:48 -03:00
parent 625e414fcf
commit 54cb38b864
7 changed files with 51 additions and 5 deletions

View File

@ -196,6 +196,7 @@ const Layout = (props: Props) => {
network={network} network={network}
userAddress={userAddress} userAddress={userAddress}
createTransaction={createTransaction} createTransaction={createTransaction}
safe={safe}
/> />
)} )}
/> />

View File

@ -10,6 +10,7 @@ import { TX_NOTIFICATION_TYPES } from '~/logic/safe/transactions'
import CheckOwner from './screens/CheckOwner' import CheckOwner from './screens/CheckOwner'
import ThresholdForm from './screens/ThresholdForm' import ThresholdForm from './screens/ThresholdForm'
import ReviewRemoveOwner from './screens/Review' import ReviewRemoveOwner from './screens/Review'
import type { Safe } from '~/routes/safe/store/models/safe'
const styles = () => ({ const styles = () => ({
biggerModalWindow: { biggerModalWindow: {
@ -34,6 +35,7 @@ type Props = {
removeSafeOwner: Function, removeSafeOwner: Function,
enqueueSnackbar: Function, enqueueSnackbar: Function,
closeSnackbar: Function, closeSnackbar: Function,
safe: Safe
} }
type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner' type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner'
@ -48,6 +50,7 @@ export const sendRemoveOwner = async (
closeSnackbar: Function, closeSnackbar: Function,
createTransaction: Function, createTransaction: Function,
removeSafeOwner: Function, removeSafeOwner: Function,
safe: Safe,
) => { ) => {
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const safeOwners = await gnosisSafe.getOwners() const safeOwners = await gnosisSafe.getOwners()
@ -69,7 +72,7 @@ export const sendRemoveOwner = async (
closeSnackbar, closeSnackbar,
) )
if (txHash) { if (txHash && safe.threshold === 1) {
removeSafeOwner({ safeAddress, ownerAddress: ownerAddressToRemove }) removeSafeOwner({ safeAddress, ownerAddress: ownerAddressToRemove })
} }
} }
@ -88,6 +91,7 @@ const RemoveOwner = ({
removeSafeOwner, removeSafeOwner,
enqueueSnackbar, enqueueSnackbar,
closeSnackbar, closeSnackbar,
safe,
}: Props) => { }: Props) => {
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner') const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
const [values, setValues] = useState<Object>({}) const [values, setValues] = useState<Object>({})
@ -130,6 +134,7 @@ const RemoveOwner = ({
closeSnackbar, closeSnackbar,
createTransaction, createTransaction,
removeSafeOwner, removeSafeOwner,
safe,
) )
} }

View File

@ -32,6 +32,7 @@ import ReplaceOwnerIcon from './assets/icons/replace-owner.svg'
import RenameOwnerIcon from './assets/icons/rename-owner.svg' import RenameOwnerIcon from './assets/icons/rename-owner.svg'
import RemoveOwnerIcon from '../assets/icons/bin.svg' import RemoveOwnerIcon from '../assets/icons/bin.svg'
import Paragraph from '~/components/layout/Paragraph/index' import Paragraph from '~/components/layout/Paragraph/index'
import type { Safe } from '~/routes/safe/store/models/safe'
export const RENAME_OWNER_BTN_TEST_ID = 'rename-owner-btn' export const RENAME_OWNER_BTN_TEST_ID = 'rename-owner-btn'
export const REMOVE_OWNER_BTN_TEST_ID = 'remove-owner-btn' export const REMOVE_OWNER_BTN_TEST_ID = 'remove-owner-btn'
@ -53,6 +54,7 @@ type Props = {
replaceSafeOwner: Function, replaceSafeOwner: Function,
editSafeOwner: Function, editSafeOwner: Function,
granted: boolean, granted: boolean,
safe: Safe
} }
type State = { type State = {
@ -111,6 +113,7 @@ class ManageOwners extends React.Component<Props, State> {
replaceSafeOwner, replaceSafeOwner,
editSafeOwner, editSafeOwner,
granted, granted,
safe,
} = this.props } = this.props
const { const {
showAddOwner, showAddOwner,
@ -235,6 +238,7 @@ class ManageOwners extends React.Component<Props, State> {
userAddress={userAddress} userAddress={userAddress}
createTransaction={createTransaction} createTransaction={createTransaction}
removeSafeOwner={removeSafeOwner} removeSafeOwner={removeSafeOwner}
safe={safe}
/> />
<ReplaceOwnerModal <ReplaceOwnerModal
onClose={this.onHide('ReplaceOwner')} onClose={this.onHide('ReplaceOwner')}

View File

@ -19,6 +19,7 @@ import ManageOwners from './ManageOwners'
import actions, { type Actions } from './actions' import actions, { type Actions } from './actions'
import { styles } from './style' import { styles } from './style'
import RemoveSafeIcon from './assets/icons/bin.svg' import RemoveSafeIcon from './assets/icons/bin.svg'
import type { Safe } from '~/routes/safe/store/models/safe'
export const OWNERS_SETTINGS_TAB_TEST_ID = 'owner-settings-tab' export const OWNERS_SETTINGS_TAB_TEST_ID = 'owner-settings-tab'
@ -43,6 +44,7 @@ type Props = Actions & {
replaceSafeOwner: Function, replaceSafeOwner: Function,
editSafeOwner: Function, editSafeOwner: Function,
userAddress: string, userAddress: string,
safe: Safe
} }
type Action = 'RemoveSafe' type Action = 'RemoveSafe'
@ -87,6 +89,7 @@ class Settings extends React.Component<Props, State> {
removeSafeOwner, removeSafeOwner,
replaceSafeOwner, replaceSafeOwner,
editSafeOwner, editSafeOwner,
safe,
} = this.props } = this.props
return ( return (
@ -152,6 +155,7 @@ class Settings extends React.Component<Props, State> {
replaceSafeOwner={replaceSafeOwner} replaceSafeOwner={replaceSafeOwner}
editSafeOwner={editSafeOwner} editSafeOwner={editSafeOwner}
granted={granted} granted={granted}
safe={safe}
/> />
)} )}
{menuOptionIndex === 3 && ( {menuOptionIndex === 3 && (

View File

@ -1,5 +1,5 @@
// @flow // @flow
import fetchSafe from '~/routes/safe/store/actions/fetchSafe' import fetchSafe, { checkAndUpdateSafeOwners } from '~/routes/safe/store/actions/fetchSafe'
import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances' import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances'
import fetchEtherBalance from '~/routes/safe/store/actions/fetchEtherBalance' import fetchEtherBalance from '~/routes/safe/store/actions/fetchEtherBalance'
import createTransaction from '~/routes/safe/store/actions/createTransaction' import createTransaction from '~/routes/safe/store/actions/createTransaction'
@ -28,4 +28,5 @@ export default {
fetchTransactions, fetchTransactions,
updateSafe, updateSafe,
fetchEtherBalance, fetchEtherBalance,
checkAndUpdateSafeOwners,
} }

View File

@ -89,9 +89,9 @@ class SafeView extends React.Component<Props, State> {
checkForUpdates() { checkForUpdates() {
const { const {
safeUrl, activeTokens, fetchTokenBalances, fetchEtherBalance, safeUrl, activeTokens, fetchTokenBalances, fetchEtherBalance, checkAndUpdateSafeOwners,
} = this.props } = this.props
checkAndUpdateSafeOwners(safeUrl)
fetchTokenBalances(safeUrl, activeTokens) fetchTokenBalances(safeUrl, activeTokens)
fetchEtherBalance(safeUrl) fetchEtherBalance(safeUrl)
} }

View File

@ -5,9 +5,11 @@ import { type GlobalState } from '~/store/index'
import { makeOwner } from '~/routes/safe/store/models/owner' import { makeOwner } from '~/routes/safe/store/models/owner'
import type { SafeProps } from '~/routes/safe/store/models/safe' import type { SafeProps } from '~/routes/safe/store/models/safe'
import addSafe from '~/routes/safe/store/actions/addSafe' import addSafe from '~/routes/safe/store/actions/addSafe'
import { getOwners, getSafeName } from '~/logic/safe/utils' 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 updateSafe from '~/routes/safe/store/actions/updateSafe'
const buildOwnersFrom = ( const buildOwnersFrom = (
safeOwners: string[], safeOwners: string[],
@ -35,6 +37,35 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
return safe return safe
} }
const getLocalSafe = async (safeAddress: string) => {
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}
return storedSafes[safeAddress]
}
export const checkAndUpdateSafeOwners = (safeAddress: string) => async (
dispatch: ReduxDispatch<GlobalState>,
) => {
// 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()
const localOwners = localSafe.owners.map((localOwner) => localOwner.address)
if (remoteOwners.length !== localOwners.length) {
dispatch(updateSafe({ address: safeAddress, owners: remoteOwners }))
return
}
// eslint-disable-next-line no-restricted-syntax
for (const remoteIterator of remoteOwners) {
if (!localOwners.includes(remoteIterator)) {
dispatch(updateSafe({ address: safeAddress, owners: remoteOwners }))
return
}
}
}
// eslint-disable-next-line consistent-return
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => { export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
try { try {
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE' const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'