Skip to content

Commit

Permalink
chore: remove node-libs-react-native and obsolete polyfills (#5913)
Browse files Browse the repository at this point in the history
### Description

Now that `@celo/contractkit` is gone, we can remove
`node-libs-react-native` and other obsolete polyfills.

### Test plan

- Tests pass

### Related issues

- Part of RET-1192

### Backwards compatibility

Yes

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)

---------

Co-authored-by: Joe Bergeron <[email protected]>
  • Loading branch information
jeanregisser and jophish authored Sep 5, 2024
1 parent 459434c commit 1877c8b
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 434 deletions.
8 changes: 0 additions & 8 deletions __mocks__/react-native-geth.ts

This file was deleted.

5 changes: 0 additions & 5 deletions __mocks__/react-native-randombytes.ts

This file was deleted.

68 changes: 0 additions & 68 deletions __mocks__/web3.js

This file was deleted.

1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Order is important, please don't change it unless you know what you're doing :D
import 'node-libs-react-native/globals'
import 'src/missingGlobals'
import 'src/forceCommunityAsyncStorage'
import 'src/setupE2eEnv' // This is only for E2E tests and has no effects when not running E2E tests
Expand Down
12 changes: 0 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,6 @@ PODS:
- React-Core
- react-native-flipper (0.212.0):
- React-Core
- react-native-get-random-values (1.11.0):
- React-Core
- react-native-in-app-review (4.3.3):
- React-Core
- react-native-launch-arguments (4.0.2):
Expand All @@ -601,8 +599,6 @@ PODS:
- RCT-Folly (= 2021.07.22.00)
- React
- React-Core
- react-native-randombytes (3.6.1):
- React-Core
- react-native-restart (0.0.27):
- React-Core
- react-native-safe-area-context (4.10.9):
Expand Down Expand Up @@ -904,13 +900,11 @@ DEPENDENCIES:
- react-native-contacts (from `../node_modules/react-native-contacts`)
- "react-native-cookies (from `../node_modules/@react-native-cookies/cookies`)"
- react-native-flipper (from `../node_modules/react-native-flipper`)
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
- react-native-in-app-review (from `../node_modules/react-native-in-app-review`)
- react-native-launch-arguments (from `../node_modules/react-native-launch-arguments`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-pager-view (from `../node_modules/react-native-pager-view`)
- react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`)
- react-native-randombytes (from `../node_modules/react-native-randombytes`)
- react-native-restart (from `../node_modules/react-native-restart`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-shake (from `../node_modules/react-native-shake`)
Expand Down Expand Up @@ -1083,8 +1077,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-cookies/cookies"
react-native-flipper:
:path: "../node_modules/react-native-flipper"
react-native-get-random-values:
:path: "../node_modules/react-native-get-random-values"
react-native-in-app-review:
:path: "../node_modules/react-native-in-app-review"
react-native-launch-arguments:
Expand All @@ -1095,8 +1087,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-pager-view"
react-native-quick-crypto:
:path: "../node_modules/react-native-quick-crypto"
react-native-randombytes:
:path: "../node_modules/react-native-randombytes"
react-native-restart:
:path: "../node_modules/react-native-restart"
react-native-safe-area-context:
Expand Down Expand Up @@ -1279,13 +1269,11 @@ SPEC CHECKSUMS:
react-native-contacts: fd1614c74777089ebb6b0a0e3847dd78130ef9f4
react-native-cookies: 672b2431ca44da2e2942af086d0c83aae42b989a
react-native-flipper: 9c1957af24b76493ba74f46d000a5c1d485e7731
react-native-get-random-values: 21325b2244dfa6b58878f51f9aa42821e7ba3d06
react-native-in-app-review: db8bb167a5f238e7ceca5c242d6b36ce8c4404a4
react-native-launch-arguments: 5f41e0abf88a15e3c5309b8875d6fd5ac43df49d
react-native-netinfo: 076df4f9b07f6670acf4ce9a75aac8d34c2e2ccc
react-native-pager-view: e79d6c876ab1896e17ff61af6aff22a914b8e435
react-native-quick-crypto: 303523bf21ad1aed8757dde262da12668b4c75d0
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
react-native-restart: 7595693413fe3ca15893702f2c8306c62a708162
react-native-safe-area-context: ab8f4a3d8180913bd78ae75dd599c94cce3d5e9a
react-native-shake: 0c36371dd63019afa68890ccc65a442ee21b4dde
Expand Down
4 changes: 0 additions & 4 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const config: KnipConfig = {
],
project: ['src/**/*.ts!', 'src/**/*.tsx!', 'src/**/*.js!'],
ignoreDependencies: [
'Base64',
'@actions/github',
'@babel/runtime', // enforce specific version for react-native
'@babel/plugin-transform-private-methods', // used in babel.config.js to build. not imported, so knip doesn't understand it is used
Expand All @@ -31,11 +30,8 @@ const config: KnipConfig = {
'typescript-json-schema', // helps manage redux state migrations
'@segment/sovran-react-native', // required for react-native-segment
'react-native-adjust', // required for @segment/analytics-react-native-plugin-adjust
'@types/isomorphic-fetch',
'@types/jest',
'husky',
'react-native-randombytes', // not sure we need this; only referenced in iOS Podfile.lock
'@celo/contractkit', // Temporary until we remove the dependency
],
ignore: ['src/utils/inputValidation.ts', 'src/utils/country.json'],
}
Expand Down
8 changes: 0 additions & 8 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
const path = require('path')
const nodeLibs = require('node-libs-react-native')
const exclusionList = require('metro-config/src/defaults/exclusionList')
const escapeStringRegexp = require('escape-string-regexp')
const isE2E = process.env.CELO_TEST_CONFIG === 'e2e'
Expand Down Expand Up @@ -33,17 +32,10 @@ const config = {
isE2E ? blist : blist.concat([RegExp(`${escapedRoot}\/e2e\/mocks/.*`)])
),
extraNodeModules: {
...nodeLibs,
// This is the crypto module we want to use moving forward (unless something better comes up).
// It is implemented natively using OpenSSL.
crypto: require.resolve('react-native-quick-crypto'),
fs: require.resolve('react-native-fs'),
'isomorphic-fetch': require.resolve('cross-fetch'),
// We don't need the `net` module for now.
// This doesn't actually provide any implementation,
// but avoids an error when require('net') is used (in ContractKit for instance).
net: require.resolve('node-libs-react-native/mock/net'),
vm: require.resolve('vm-browserify'),
},
sourceExts: isE2E ? ['e2e.ts', 'e2e.js'].concat(defaultSourceExts) : defaultSourceExts,
},
Expand Down
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
"@walletconnect/react-native-compat": "^2.15.2",
"@walletconnect/utils": "^2.15.2",
"@walletconnect/web3wallet": "^1.14.2",
"Base64": "^1.3.0",
"bignumber.js": "^9.1.2",
"clevertap-react-native": "^2.2.1",
"country-data": "^0.0.31",
Expand All @@ -132,7 +131,6 @@
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"lottie-react-native": "^5.1.6",
"node-libs-react-native": "^1.2.1",
"react": "18.3.1",
"react-async-hook": "^4.0.0",
"react-i18next": "^14.1.3",
Expand All @@ -148,7 +146,6 @@
"react-native-fast-image": "^8.6.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.19.0",
"react-native-get-random-values": "^1.11.0",
"react-native-haptic-feedback": "^2.3.1",
"react-native-in-app-review": "^4.3.3",
"react-native-keychain": "^8.1.3",
Expand All @@ -163,7 +160,6 @@
"react-native-platform-touchable": "^1.1.1",
"react-native-qrcode-svg": "^6.3.2",
"react-native-quick-crypto": "^0.7.3",
"react-native-randombytes": "^3.6.1",
"react-native-reanimated": "^3.15.1",
"react-native-restart": "^0.0.27",
"react-native-safe-area-context": "^4.10.9",
Expand Down Expand Up @@ -193,7 +189,6 @@
"uuid": "^9.0.1",
"victory-native": "^36.9.2",
"viem": "^2.21.1",
"vm-browserify": "^1.1.2",
"web3-utils": "^4.3.1"
},
"devDependencies": {
Expand All @@ -216,7 +211,6 @@
"@types/fs-extra": "^9.0.13",
"@types/google-libphonenumber": "^7.4.30",
"@types/hoist-non-react-statics": "^3.3.5",
"@types/isomorphic-fetch": "^0.0.35",
"@types/jest": "^29.5.3",
"@types/lodash": "^4.14.136",
"@types/react": "^18.0.24",
Expand Down Expand Up @@ -304,7 +298,6 @@
"elliptic": "^6.5.7",
"dot-prop": "^8.0.2",
"bl": "^6.0.14",
"node-libs-react-native": "^1.2.1",
"node-forge": "^1.3.1",
"underscore": "^1.13.7",
"y18n": "5.0.8",
Expand Down
4 changes: 0 additions & 4 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ const ignoreWarnings = [
'cancelTouches', // rn-screens warning on iOS
'Setting a timer', // warns about long setTimeouts which are actually saga timeouts
'Require cycle', // TODO: fix require cycles and remove this ;)
// These are caused by node-libs-react-native's stream-http capability checks and are harmless to ignore
// See https://github.com/jhiesey/stream-http/blob/cd697901d132cc20ea698079ac400b7cc11a7999/lib/capability.js#L48-L49
"The provided value 'moz-chunked-arraybuffer' is not a valid 'responseType'",
"The provided value 'ms-stream' is not a valid 'responseType'",
]
if (isE2EEnv) {
ignoreWarnings.push('Overriding previous layout')
Expand Down
1 change: 0 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ declare module '*.png'
declare module '*.jpg'

declare module 'dot-prop-immutable'
declare module 'react-native-crypto'
declare module 'svgs'
declare module 'react-native-languages'
declare module 'react-native-version-check'
Expand Down
3 changes: 0 additions & 3 deletions src/missingGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { install } from 'react-native-quick-crypto'
import 'react-native-url-polyfill/auto'

export interface Global {
btoa: any
URL: any
self: any
}
Expand All @@ -14,7 +13,5 @@ declare var global: Global
if (typeof global.self === 'undefined') {
global.self = global
}
global.btoa = require('Base64').btoa
require('crypto')

install()
4 changes: 2 additions & 2 deletions src/positions/saga.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isIP from 'is-ip'
import path from 'path'
import { Alert, Platform } from 'react-native'
import Toast from 'react-native-simple-toast'
import { showError } from 'src/alert/actions'
Expand Down Expand Up @@ -44,6 +43,7 @@ import Logger from 'src/utils/Logger'
import { ensureError } from 'src/utils/ensureError'
import { fetchWithTimeout } from 'src/utils/fetchWithTimeout'
import { safely } from 'src/utils/safely'
import { appendPath } from 'src/utils/string'
import { sendPreparedTransactions } from 'src/viem/saga'
import { walletAddressSelector } from 'src/web3/selectors'
import { call, put, select, spawn, takeEvery, takeLeading } from 'typed-redux-saga'
Expand All @@ -57,7 +57,7 @@ function getHooksApiFunctionUrl(
functionName: 'getPositions' | 'getEarnPositions' | 'v2/getShortcuts' | 'triggerShortcut'
) {
const url = new URL(hooksApiUrl)
url.pathname = path.join(url.pathname, functionName)
url.pathname = appendPath(url.pathname, functionName)
return url
}

Expand Down
Loading

0 comments on commit 1877c8b

Please sign in to comment.