Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit a2cd631

Browse files
authored
Refactor: chain features and versioned features (#3120)
* Refactor: chain features and versioned features * Update FEATURES type * Fix tests
1 parent ca010e9 commit a2cd631

File tree

16 files changed

+71
-90
lines changed

16 files changed

+71
-90
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
"@gnosis.pm/safe-core-sdk": "^0.3.1",
170170
"@gnosis.pm/safe-deployments": "^1.2.0",
171171
"@gnosis.pm/safe-react-components": "^0.9.0",
172-
"@gnosis.pm/safe-react-gateway-sdk": "^2.5.7",
172+
"@gnosis.pm/safe-react-gateway-sdk": "^2.5.8",
173173
"@ledgerhq/hw-transport-node-hid-singleton": "6.3.0",
174174
"@material-ui/core": "^4.12.3",
175175
"@material-ui/icons": "^4.11.0",

src/components/AppLayout/Sidebar/useSidebarItems.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useSelector } from 'react-redux'
33
import { useRouteMatch } from 'react-router-dom'
44
import { FEATURES } from '@gnosis.pm/safe-react-gateway-sdk'
55

6-
import { getShortName, isFeatureEnabled } from 'src/config'
6+
import { getShortName } from 'src/config'
77
import { ListItemType } from 'src/components/List'
88
import ListIcon from 'src/components/List/ListIcon'
99
import { currentSafeFeaturesEnabled, currentSafeWithNames } from 'src/logic/safe/store/selectors'
@@ -15,12 +15,13 @@ import {
1515
generatePrefixedAddressRoutes,
1616
} from 'src/routes/routes'
1717
import { IS_PRODUCTION } from 'src/utils/constants'
18+
import { hasFeature } from 'src/logic/safe/utils/safeVersion'
1819

1920
const useSidebarItems = (): ListItemType[] => {
2021
const featuresEnabled = useSelector(currentSafeFeaturesEnabled)
21-
const safeAppsEnabled = isFeatureEnabled(FEATURES.SAFE_APPS)
22-
const isCollectiblesEnabled = isFeatureEnabled(FEATURES.ERC721)
23-
const isSpendingLimitEnabled = isFeatureEnabled(FEATURES.SPENDING_LIMIT)
22+
const safeAppsEnabled = hasFeature(FEATURES.SAFE_APPS)
23+
const isCollectiblesEnabled = hasFeature(FEATURES.ERC721)
24+
const isSpendingLimitEnabled = hasFeature(FEATURES.SPENDING_LIMIT)
2425
const { needsUpdate } = useSelector(currentSafeWithNames)
2526
const safeAddress = extractSafeAddress()
2627
const granted = useSelector(grantedSelector)

src/components/forms/validator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import memoize from 'lodash/memoize'
22

33
import { sameAddress } from 'src/logic/wallets/ethAddresses'
44
import { getWeb3 } from 'src/logic/wallets/getWeb3'
5-
import { getShortName, isFeatureEnabled } from 'src/config'
5+
import { getShortName } from 'src/config'
66
import { isValidAddress } from 'src/utils/isValidAddress'
77
import { ADDRESS_BOOK_INVALID_NAMES, isValidAddressBookName } from 'src/logic/addressBook/utils'
88
import { FEATURES } from '@gnosis.pm/safe-react-gateway-sdk'
99
import { isValidPrefix, parsePrefixedAddress } from 'src/utils/prefixedAddress'
10+
import { hasFeature } from 'src/logic/safe/utils/safeVersion'
1011

1112
type ValidatorReturnType = string | undefined
1213
export type GenericValidatorType = (...args: unknown[]) => ValidatorReturnType
@@ -101,7 +102,7 @@ export const mustBeEthereumAddress = (fullAddress: string): ValidatorReturnType
101102
if (prefixError) return prefixError
102103

103104
const result = mustBeAddressHash(address)
104-
if (result !== undefined && isFeatureEnabled(FEATURES.DOMAIN_LOOKUP)) {
105+
if (result !== undefined && hasFeature(FEATURES.DOMAIN_LOOKUP)) {
105106
return errorMessage
106107
}
107108
return result

src/config/cache/chains.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const emptyChainInfo: ChainInfo = {
2323
l2: false,
2424
description: '',
2525
rpcUri: { authentication: '' as RPC_AUTHENTICATION, value: '' },
26-
safeAppsRpcUri: { authentication: '' as RPC_AUTHENTICATION, value: '' },
2726
publicRpcUri: { authentication: '' as RPC_AUTHENTICATION, value: '' },
27+
safeAppsRpcUri: { authentication: '' as RPC_AUTHENTICATION, value: '' },
2828
blockExplorerUriTemplate: {
2929
address: '',
3030
txHash: '',

src/config/chain-workarounds.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/config/chain.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,3 @@ export enum WALLETS {
4444
LATTICE = 'lattice',
4545
KEYSTONE = 'keystone',
4646
}
47-
48-
// This is unrelated to the chains and will be removed when retrieved from core SDK
49-
export enum SAFE_FEATURES {
50-
SAFE_TX_GAS_OPTIONAL = 'SAFE_TX_GAS_OPTIONAL',
51-
}

src/config/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
ChainInfo,
33
GasPriceOracle,
44
GAS_PRICE_TYPE,
5-
FEATURES,
65
RPC_AUTHENTICATION,
76
RpcUri,
87
} from '@gnosis.pm/safe-react-gateway-sdk'
@@ -16,7 +15,7 @@ import {
1615
SAFE_APPS_RPC_TOKEN,
1716
TX_SERVICE_VERSION,
1817
} from 'src/utils/constants'
19-
import { ChainId, ChainName, SAFE_FEATURES, ShortName } from './chain.d'
18+
import { ChainId, ChainName, ShortName } from './chain.d'
2019
import { emptyChainInfo, getChains } from './cache/chains'
2120
import { evalTemplate } from './utils'
2221

@@ -123,11 +122,8 @@ export const getExplorerUrl = (): string => {
123122

124123
export const getHashedExplorerUrl = (hash: string): string => {
125124
const isTx = hash.length > 42
126-
127125
const param = isTx ? 'txHash' : 'address'
128126
const uri = getExplorerUriTemplate()[param]
129-
const params = { [param]: hash }
130-
131127
return evalTemplate(uri, { [param]: hash })
132128
}
133129

@@ -140,13 +136,6 @@ export const getExplorerInfo = (hash: string): (() => { url: string; alt: string
140136
return () => ({ url, alt })
141137
}
142138

143-
export const isFeatureEnabled = (feature: FEATURES | SAFE_FEATURES) => {
144-
return (
145-
getChainInfo().features.includes(feature as FEATURES) ||
146-
Object.values(SAFE_FEATURES).includes(feature as SAFE_FEATURES)
147-
)
148-
}
149-
150139
const getExplorerApiKey = (apiUrl: string): string | undefined => {
151140
return apiUrl.includes('etherscan') && ETHERSCAN_API_KEY ? ETHERSCAN_API_KEY : undefined
152141
}

src/logic/safe/store/actions/__tests__/fetchSafe.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,16 @@ describe('fetchSafe', () => {
127127
nonce: 492,
128128
currentVersion: '1.3.0',
129129
needsUpdate: false,
130-
featuresEnabled: ['ERC721', 'ERC1155', 'SAFE_APPS', 'CONTRACT_INTERACTION', 'SAFE_TX_GAS_OPTIONAL'],
130+
featuresEnabled: [
131+
'CONTRACT_INTERACTION',
132+
'DOMAIN_LOOKUP',
133+
'EIP1559',
134+
'ERC1155',
135+
'ERC721',
136+
'SAFE_APPS',
137+
'SAFE_TX_GAS_OPTIONAL',
138+
'SPENDING_LIMIT',
139+
],
131140
},
132141
},
133142
]

src/logic/safe/store/actions/__tests__/utils.test.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FEATURES } from '@gnosis.pm/safe-react-gateway-sdk'
22
import { TransactionStatus } from '@gnosis.pm/safe-react-gateway-sdk'
33

4-
import { ChainId, SAFE_FEATURES } from 'src/config/chain.d'
4+
import { ChainId } from 'src/config/chain.d'
55
import {
66
buildSafeOwners,
77
extractRemoteSafeInfo,
@@ -149,12 +149,15 @@ describe('extractRemoteSafeInfo', () => {
149149
needsUpdate: false,
150150
guard: undefined,
151151
featuresEnabled: [
152-
FEATURES.ERC721,
153-
FEATURES.ERC1155,
154-
FEATURES.SAFE_APPS,
155-
FEATURES.CONTRACT_INTERACTION,
156-
SAFE_FEATURES.SAFE_TX_GAS_OPTIONAL,
157-
],
152+
'CONTRACT_INTERACTION',
153+
'DOMAIN_LOOKUP',
154+
'EIP1559',
155+
'ERC1155',
156+
'ERC721',
157+
'SAFE_APPS',
158+
'SAFE_TX_GAS_OPTIONAL',
159+
'SPENDING_LIMIT',
160+
] as FEATURES[],
158161
}
159162

160163
const remoteSafeInfo = await extractRemoteSafeInfo(remoteSafeInfoWithoutModules as any)
@@ -179,12 +182,15 @@ describe('extractRemoteSafeInfo', () => {
179182
needsUpdate: false,
180183
guard: '0x4f8a82d73729A33E0165aDeF3450A7F85f007528',
181184
featuresEnabled: [
182-
FEATURES.ERC721,
183-
FEATURES.ERC1155,
184-
FEATURES.SAFE_APPS,
185-
FEATURES.CONTRACT_INTERACTION,
186-
SAFE_FEATURES.SAFE_TX_GAS_OPTIONAL,
187-
],
185+
'CONTRACT_INTERACTION',
186+
'DOMAIN_LOOKUP',
187+
'EIP1559',
188+
'ERC1155',
189+
'ERC721',
190+
'SAFE_APPS',
191+
'SAFE_TX_GAS_OPTIONAL',
192+
'SPENDING_LIMIT',
193+
] as FEATURES[],
188194
}
189195

190196
const remoteSafeInfo = await extractRemoteSafeInfo(remoteSafeInfoWithModules as any)

src/logic/safe/store/models/safe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FEATURES } from '@gnosis.pm/safe-react-gateway-sdk'
22
import { Record, RecordOf } from 'immutable'
3-
import { ChainId, SAFE_FEATURES } from 'src/config/chain.d'
3+
import { ChainId } from 'src/config/chain.d'
44

55
import { BalanceRecord } from 'src/logic/tokens/store/actions/fetchSafeTokens'
66

@@ -37,7 +37,7 @@ export type SafeRecordProps = {
3737
recurringUser?: boolean
3838
currentVersion: string
3939
needsUpdate: boolean
40-
featuresEnabled: Array<FEATURES | SAFE_FEATURES>
40+
featuresEnabled: FEATURES[]
4141
loadedViaUrl: boolean
4242
guard: string
4343
collectiblesTag: string

0 commit comments

Comments
 (0)