(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:
parent
fd5334669a
commit
7d64030b1a
|
@ -75,4 +75,4 @@ export const getIntercomId = () =>
|
||||||
|
|
||||||
export const getExchangeRatesUrl = () => 'https://api.exchangeratesapi.io/latest'
|
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'
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import semverValid from 'semver/functions/valid'
|
import semverValid from 'semver/functions/valid'
|
||||||
import semverLessThan from 'semver/functions/lt'
|
import semverLessThan from 'semver/functions/lt'
|
||||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
import { getGnosisSafeInstanceAt, getSafeMasterContract } from '~/logic/contracts/safeContracts'
|
||||||
import { getSafeLastVersion } from '~/config'
|
import { getSafeLastVersion } from '~/config'
|
||||||
|
|
||||||
export const checkIfSafeNeedsUpdate = async (gnosisSafeInstance, lastSafeVersion) => {
|
export const checkIfSafeNeedsUpdate = async (gnosisSafeInstance, lastSafeVersion) => {
|
||||||
|
@ -15,10 +15,23 @@ export const checkIfSafeNeedsUpdate = async (gnosisSafeInstance, lastSafeVersion
|
||||||
return { current, latest, needUpdate }
|
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) => {
|
export const getSafeVersion = async (safeAddress: string) => {
|
||||||
try {
|
try {
|
||||||
const safeMaster = await getGnosisSafeInstanceAt(safeAddress)
|
const safeMaster = await getGnosisSafeInstanceAt(safeAddress)
|
||||||
return checkIfSafeNeedsUpdate(safeMaster, getSafeLastVersion())
|
const lastSafeVersion = await getCurrentMasterContractLastVersion()
|
||||||
|
return checkIfSafeNeedsUpdate(safeMaster, lastSafeVersion)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
throw err
|
throw err
|
||||||
|
|
Loading…
Reference in New Issue