diff --git a/src/config/index.js b/src/config/index.js index 51a5919c..6145ac49 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -74,3 +74,5 @@ export const getIntercomId = () => : "plssl1fl" export const getExchangeRatesUrl = () => 'https://api.exchangeratesapi.io/latest' + +export const getSafeLastVersion = () => process.env.REACT_APP_LATEST_SAFE_VERSION \ No newline at end of file diff --git a/src/logic/notifications/notificationTypes.js b/src/logic/notifications/notificationTypes.js index 2afbd846..dc1c0488 100644 --- a/src/logic/notifications/notificationTypes.js +++ b/src/logic/notifications/notificationTypes.js @@ -67,7 +67,10 @@ export type Notifications = { // AddressBook ADDRESS_BOOK_NEW_ENTRY_SUCCESS: Notification, ADDRESS_BOOK_EDIT_ENTRY_SUCCESS: Notification, - ADDRESS_BOOK_DELETE_ENTRY_SUCCESS: Notification + ADDRESS_BOOK_DELETE_ENTRY_SUCCESS: Notification, + + // Safe Version + SAFE_NEW_VERSION_AVAILABLE: Notification, } export const NOTIFICATIONS: Notifications = { @@ -221,4 +224,10 @@ export const NOTIFICATIONS: Notifications = { message: 'Entry deleted successfully', options: { variant: SUCCESS, persist: false, preventDuplicate: false }, }, + + // Safe Version + SAFE_NEW_VERSION_AVAILABLE: { + message: 'There is a new version available for this Safe', + options: { variant: WARNING, persist: false, preventDuplicate: true }, + }, } diff --git a/src/logic/safe/utils/safeVersion.js b/src/logic/safe/utils/safeVersion.js new file mode 100644 index 00000000..cb6773ea --- /dev/null +++ b/src/logic/safe/utils/safeVersion.js @@ -0,0 +1,22 @@ +// @flow +import semverValid from 'semver/functions/valid' +import semverLessThan from 'semver/functions/lt' +import { getSafeMasterContract } from '~/logic/contracts/safeContracts' +import { getSafeLastVersion } from '~/config' + +export const getSafeVersion = async () => { + let current + let latest + try { + const safeMaster = await getSafeMasterContract() + const safeMasterVersion = await safeMaster.VERSION() + current = semverValid(safeMasterVersion) + latest = semverValid(getSafeLastVersion()) + const needUpdate = latest ? semverLessThan(current, latest) : false + + return { current, latest, needUpdate } + } catch (err) { + console.error(err) + throw err + } +} diff --git a/src/routes/safe/components/Settings/SafeDetails/index.jsx b/src/routes/safe/components/Settings/SafeDetails/index.jsx index f9c4090a..70f8c165 100644 --- a/src/routes/safe/components/Settings/SafeDetails/index.jsx +++ b/src/routes/safe/components/Settings/SafeDetails/index.jsx @@ -2,8 +2,6 @@ import React, { useEffect } from 'react' import { makeStyles } from '@material-ui/core/styles' import { withSnackbar } from 'notistack' -import semverLessThan from 'semver/functions/lt' -import semverValid from 'semver/functions/valid' import Block from '~/components/layout/Block' import Col from '~/components/layout/Col' import Field from '~/components/forms/Field' @@ -17,7 +15,7 @@ import Button from '~/components/layout/Button' import { getNotificationsFromTxType, showSnackbar } from '~/logic/notifications' import { TX_NOTIFICATION_TYPES } from '~/logic/safe/transactions' import { styles } from './style' -import { getSafeMasterContract } from '~/logic/contracts/safeContracts' +import { getSafeVersion } from '~/logic/safe/utils/safeVersion' export const SAFE_NAME_INPUT_TEST_ID = 'safe-name-input' export const SAFE_NAME_SUBMIT_BTN_TEST_ID = 'change-safe-name-btn' @@ -48,18 +46,11 @@ const SafeDetails = (props: Props) => { useEffect(() => { const getVersion = async () => { - let current - let latest try { - const safeMaster = await getSafeMasterContract() - const safeMasterVersion = await safeMaster.VERSION() - current = semverValid(safeMasterVersion) - latest = semverValid(process.env.REACT_APP_LATEST_SAFE_VERSION) - const needUpdate = semverLessThan(current, latest) - + const { current, latest, needUpdate } = await getSafeVersion() setSafeVersions({ current, latest, needUpdate }) } catch (err) { - setSafeVersions({ current: current || 'Version not defined' }) + setSafeVersions({ current: 'Version not defined' }) console.error(err) } } diff --git a/src/routes/safe/store/middleware/notificationsMiddleware.js b/src/routes/safe/store/middleware/notificationsMiddleware.js index 08555d56..faf98ddd 100644 --- a/src/routes/safe/store/middleware/notificationsMiddleware.js +++ b/src/routes/safe/store/middleware/notificationsMiddleware.js @@ -14,8 +14,10 @@ import { getIncomingTxAmount } from '~/routes/safe/components/Transactions/TxsTa import updateSafe from '~/routes/safe/store/actions/updateSafe' import { safesMapSelector } from '~/routes/safe/store/selectors' import { isUserOwner } from '~/logic/wallets/ethAddresses' +import { ADD_SAFE } from '~/routes/safe/store/actions/addSafe' +import { getSafeVersion } from '~/logic/safe/utils/safeVersion' -const watchedActions = [ADD_TRANSACTIONS, ADD_INCOMING_TRANSACTIONS] +const watchedActions = [ADD_TRANSACTIONS, ADD_INCOMING_TRANSACTIONS, ADD_SAFE] const notificationsMiddleware = (store: Store) => ( next: Function, @@ -112,6 +114,22 @@ const notificationsMiddleware = (store: Store) => ( }) break } + case ADD_SAFE: { + const { needUpdate } = await getSafeVersion() + const { safe } = action.payload + const notificationKey = `${safe.address}` + if (needUpdate) { + dispatch( + enqueueSnackbar( + enhanceSnackbarForAction( + NOTIFICATIONS.SAFE_NEW_VERSION_AVAILABLE, + notificationKey, + ), + ), + ) + } + break + } default: break }