(Hotfix) Safe version detection (#579)

* Updates the logic, now search the last version from the contract, if not, go for the env var

* Fix missing await
This commit is contained in:
Agustin Pane 2020-02-18 16:55:25 -03:00 committed by GitHub
parent fd5334669a
commit 7d64030b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -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
export const getSafeLastVersion = () => process.env.REACT_APP_LATEST_SAFE_VERSION || '1.1.1'

View File

@ -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