diff --git a/src/config/index.js b/src/config/index.js index 6145ac49..b7c3c959 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -75,4 +75,4 @@ export const getIntercomId = () => export const getExchangeRatesUrl = () => 'https://api.exchangeratesapi.io/latest' -export const getSafeLastVersion = () => process.env.REACT_APP_LATEST_SAFE_VERSION \ No newline at end of file +export const getSafeLastVersion = () => process.env.REACT_APP_LATEST_SAFE_VERSION || '1.1.1' \ No newline at end of file diff --git a/src/logic/safe/utils/safeVersion.js b/src/logic/safe/utils/safeVersion.js index c303f0fd..106f3f20 100644 --- a/src/logic/safe/utils/safeVersion.js +++ b/src/logic/safe/utils/safeVersion.js @@ -1,7 +1,7 @@ // @flow import semverValid from 'semver/functions/valid' import semverLessThan from 'semver/functions/lt' -import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' +import { getGnosisSafeInstanceAt, getSafeMasterContract } from '~/logic/contracts/safeContracts' import { getSafeLastVersion } from '~/config' export const checkIfSafeNeedsUpdate = async (gnosisSafeInstance, lastSafeVersion) => { @@ -15,10 +15,23 @@ export const checkIfSafeNeedsUpdate = async (gnosisSafeInstance, lastSafeVersion return { current, latest, needUpdate } } +const getCurrentMasterContractLastVersion = async () => { + const safeMaster = await getSafeMasterContract() + let safeMasterVersion + try { + safeMasterVersion = await safeMaster.VERSION() + } catch (err) { + // Default in case that it's not possible to obtain the version from the contract, returns a hardcoded value or an env variable + safeMasterVersion = getSafeLastVersion() + } + return safeMasterVersion +} + export const getSafeVersion = async (safeAddress: string) => { try { const safeMaster = await getGnosisSafeInstanceAt(safeAddress) - return checkIfSafeNeedsUpdate(safeMaster, getSafeLastVersion()) + const lastSafeVersion = await getCurrentMasterContractLastVersion() + return checkIfSafeNeedsUpdate(safeMaster, lastSafeVersion) } catch (err) { console.error(err) throw err