-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
26 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
import semverSatisfies from 'semver/functions/satisfies' | ||
|
||
export enum FEATURES { | ||
SAFE_TX_GAS_OPTIONAL, | ||
SAFE_TX_GUARDS, | ||
SAFE_FALLBACK_HANDLER, | ||
ETH_SIGN | ||
export enum SAFE_FEATURES { | ||
SAFE_TX_GAS_OPTIONAL = 'SAFE_TX_GAS_OPTIONAL', | ||
SAFE_TX_GUARDS = 'SAFE_TX_GUARDS', | ||
SAFE_FALLBACK_HANDLER = 'SAFE_FALLBACK_HANDLER', | ||
ETH_SIGN = 'ETH_SIGN' | ||
} | ||
|
||
const FEATURES_BY_VERSION: Record<string, string> = { | ||
[FEATURES.SAFE_TX_GAS_OPTIONAL]: '>=1.3.0', | ||
[FEATURES.SAFE_TX_GUARDS]: '>=1.3.0', | ||
[FEATURES.SAFE_FALLBACK_HANDLER]: '>=1.1.1', | ||
[FEATURES.ETH_SIGN]: '>=1.1.0' | ||
const SAFE_FEATURES_BY_VERSION: Record<SAFE_FEATURES, string> = { | ||
[SAFE_FEATURES.SAFE_TX_GAS_OPTIONAL]: '>=1.3.0', | ||
[SAFE_FEATURES.SAFE_TX_GUARDS]: '>=1.3.0', | ||
[SAFE_FEATURES.SAFE_FALLBACK_HANDLER]: '>=1.1.1', | ||
[SAFE_FEATURES.ETH_SIGN]: '>=1.1.0' | ||
} | ||
|
||
const isEnabledByVersion = (feature: FEATURES, version: string): boolean => { | ||
if (!(feature in FEATURES_BY_VERSION)) { | ||
return true | ||
// Note: gatewau returns `SafeInfo['version']` as `null` for unsupported contracts | ||
export const hasSafeFeature = (feature: SAFE_FEATURES, version: string | null): boolean => { | ||
if (!version || !(feature in SAFE_FEATURES_BY_VERSION)) { | ||
return false | ||
} | ||
return semverSatisfies(version, FEATURES_BY_VERSION[feature]) | ||
} | ||
|
||
export const enabledFeatures = (version: string): FEATURES[] => { | ||
const features = Object.values(FEATURES) as FEATURES[] | ||
return features.filter((feature) => isEnabledByVersion(feature, version)) | ||
} | ||
|
||
export const hasFeature = (name: FEATURES, version: string): boolean => { | ||
return enabledFeatures(version).includes(name) | ||
return semverSatisfies(version, SAFE_FEATURES_BY_VERSION[feature]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters