From 3f6a8ee3f8033070690ad50693825af5eb4b8f75 Mon Sep 17 00:00:00 2001 From: Agustin Pane Date: Wed, 18 Nov 2020 14:42:00 -0300 Subject: [PATCH] (Feature) - EWC/Volta ENS support on web3 patch (#1596) * Adds patch-package and postinstall * Creates a patch to add EWC and Volta in web3-eth and web3-eth-ens * Adds support for ewc in isValidEnsName * Update web3 ewc patch * Enables ens lookup for ewc and volta * Fix eslint * Update patch Fix patch-package script in package.json Co-authored-by: Fernando Co-authored-by: nicolas Co-authored-by: Daniel Sanchez --- package.json | 6 ++-- patches/web3-eth+1.2.11.patch | 19 ++++++++++ patches/web3-eth-ens+1.2.11.patch | 15 ++++++++ src/config/networks/energy_web_chain.ts | 7 ++-- src/config/networks/volta.ts | 5 +-- src/logic/wallets/ethAddresses.ts | 2 +- yarn.lock | 47 +++++++++++++++++++++++-- 7 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 patches/web3-eth+1.2.11.patch create mode 100644 patches/web3-eth-ens+1.2.11.patch diff --git a/package.json b/package.json index aa2f6dc2..ca479460 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "email": "safe@gnosis.io" }, "main": "public/electron.js", - "postinstall": "electron-builder install-app-deps", + "postinstall": "patch-package electron-builder install-app-deps", "scripts": { "analyze": "source-map-explorer 'build/static/js/*.js'", "build-desktop": "cross-env REACT_APP_BUILD_FOR_DESKTOP=true REACT_APP_ENV=production yarn build-mainnet", @@ -30,7 +30,7 @@ "generate-types:contracts": "cross-env typechain --target=web3-v1 --outDir './src/types/contracts' './node_modules/@gnosis.pm/safe-contracts/build/contracts/*.json'", "lint:check": "eslint './src/**/*.{js,jsx,ts,tsx}'", "lint:fix": "yarn lint:check --fix", - "postinstall": "electron-builder install-app-deps && yarn generate-types", + "postinstall": "patch-package && electron-builder install-app-deps && yarn generate-types", "preelectron-pack": "yarn build", "prettier:check": "yarn prettier --check", "prettier:fix": "yarn prettier --write", @@ -272,6 +272,8 @@ "husky": "^4.3.0", "lint-staged": "^10.5.1", "node-sass": "^4.14.1", + "patch-package": "^6.2.2", + "postinstall-postinstall": "^2.1.0", "prettier": "2.1.2", "react-app-rewired": "^2.1.6", "react-docgen-typescript-loader": "^3.7.2", diff --git a/patches/web3-eth+1.2.11.patch b/patches/web3-eth+1.2.11.patch new file mode 100644 index 00000000..9de3c1ca --- /dev/null +++ b/patches/web3-eth+1.2.11.patch @@ -0,0 +1,19 @@ +diff --git a/node_modules/web3-eth/src/getNetworkType.js b/node_modules/web3-eth/src/getNetworkType.js +index 3be3a20..88edbd9 100644 +--- a/node_modules/web3-eth/src/getNetworkType.js ++++ b/node_modules/web3-eth/src/getNetworkType.js +@@ -63,6 +63,14 @@ var getNetworkType = function (callback) { + id === 42) { + returnValue = 'kovan'; + } ++ if (genesis.hash === '0x0b6d3e680af2fc525392c720666cce58e3d8e6fe75ba4b48cb36bcc69039229b' && ++ id === 246) { ++ returnValue = 'energyWebChain'; ++ } ++ if (genesis.hash === '0xebd8b413ca7b7f84a8dd20d17519ce2b01954c74d94a0a739a3e416abe0e43e5' && ++ id === 73799) { ++ returnValue = 'volta'; ++ } + + if (_.isFunction(callback)) { + callback(null, returnValue); diff --git a/patches/web3-eth-ens+1.2.11.patch b/patches/web3-eth-ens+1.2.11.patch new file mode 100644 index 00000000..ea9249fb --- /dev/null +++ b/patches/web3-eth-ens+1.2.11.patch @@ -0,0 +1,15 @@ +diff --git a/node_modules/web3-eth-ens/src/config.js b/node_modules/web3-eth-ens/src/config.js +index b12e5f5..e0abf2d 100644 +--- a/node_modules/web3-eth-ens/src/config.js ++++ b/node_modules/web3-eth-ens/src/config.js +@@ -30,7 +30,9 @@ var config = { + main: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", + ropsten: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", + rinkeby: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", +- goerli: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e" ++ goerli: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", ++ energyWebChain: "0x0A6d64413c07E10E890220BBE1c49170080C6Ca0", ++ volta: "0xd7CeF70Ba7efc2035256d828d5287e2D285CD1ac", + }, + // These ids obtained at ensdomains docs: + // https://docs.ens.domains/contract-developer-guide/writing-a-resolver diff --git a/src/config/networks/energy_web_chain.ts b/src/config/networks/energy_web_chain.ts index ececc4bf..7253be5b 100644 --- a/src/config/networks/energy_web_chain.ts +++ b/src/config/networks/energy_web_chain.ts @@ -1,5 +1,5 @@ import EwcLogo from 'src/config/assets/token_ewc.svg' -import { EnvironmentSettings, ETHEREUM_NETWORK, FEATURES, NetworkConfig, WALLETS } from 'src/config/networks/network.d' +import { EnvironmentSettings, ETHEREUM_NETWORK, NetworkConfig, WALLETS } from 'src/config/networks/network.d' // @todo (agustin) we need to use fixed gasPrice because the oracle is not working right now and it's returning 0 // once the oracle is fixed we need to remove the fixed value @@ -60,10 +60,7 @@ const mainnet: NetworkConfig = { WALLETS.WALLET_LINK, WALLETS.AUTHEREUM, WALLETS.LATTICE, - ], - disabledFeatures: [ - FEATURES.ENS_LOOKUP, - ], + ] } export default mainnet diff --git a/src/config/networks/volta.ts b/src/config/networks/volta.ts index 350ad99a..3d96e6f8 100644 --- a/src/config/networks/volta.ts +++ b/src/config/networks/volta.ts @@ -1,5 +1,5 @@ import EwcLogo from 'src/config/assets/token_ewc.svg' -import { EnvironmentSettings, ETHEREUM_NETWORK, FEATURES, NetworkConfig, WALLETS } from 'src/config/networks/network.d' +import { EnvironmentSettings, ETHEREUM_NETWORK, NetworkConfig, WALLETS } from 'src/config/networks/network.d' const baseConfig: EnvironmentSettings = { txServiceUrl: 'https://safe-transaction.volta.gnosis.io/api/v1', @@ -58,9 +58,6 @@ const mainnet: NetworkConfig = { WALLETS.AUTHEREUM, WALLETS.LATTICE, ], - disabledFeatures: [ - FEATURES.ENS_LOOKUP, - ], } export default mainnet diff --git a/src/logic/wallets/ethAddresses.ts b/src/logic/wallets/ethAddresses.ts index d45d0fea..834e6654 100644 --- a/src/logic/wallets/ethAddresses.ts +++ b/src/logic/wallets/ethAddresses.ts @@ -40,4 +40,4 @@ export const isUserAnOwner = (safe: SafeRecord, userAccount: string): boolean => export const isUserAnOwnerOfAnySafe = (safes: List | SafeRecord[], userAccount: string): boolean => safes.some((safe: SafeRecord) => isUserAnOwner(safe, userAccount)) -export const isValidEnsName = (name: string): boolean => /^([\w-]+\.)+(eth|test|xyz|luxe)$/.test(name) +export const isValidEnsName = (name: string): boolean => /^([\w-]+\.)+(eth|test|xyz|luxe|ewc)$/.test(name) diff --git a/yarn.lock b/yarn.lock index cc3f7533..baafc177 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3893,6 +3893,11 @@ resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== +"@yarnpkg/lockfile@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" + integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== + abab@^2.0.0: version "2.0.5" resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a" @@ -9749,6 +9754,14 @@ find-versions@^3.2.0: dependencies: semver-regex "^2.0.0" +find-yarn-workspace-root@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db" + integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q== + dependencies: + fs-extra "^4.0.3" + micromatch "^3.1.4" + flat-cache@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" @@ -9931,7 +9944,7 @@ fs-extra@^0.30.0: path-is-absolute "^1.0.0" rimraf "^2.2.8" -fs-extra@^4.0.2: +fs-extra@^4.0.2, fs-extra@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94" integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg== @@ -9940,7 +9953,7 @@ fs-extra@^4.0.2: jsonfile "^4.0.0" universalify "^0.1.0" -fs-extra@^7.0.0: +fs-extra@^7.0.0, fs-extra@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== @@ -12607,6 +12620,13 @@ kind-of@^6.0.0, kind-of@^6.0.2: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + klaw@^1.0.0: version "1.3.1" resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439" @@ -14619,6 +14639,24 @@ pascalcase@^0.1.1: resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= +patch-package@^6.2.2: + version "6.2.2" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.2.2.tgz#71d170d650c65c26556f0d0fbbb48d92b6cc5f39" + integrity sha512-YqScVYkVcClUY0v8fF0kWOjDYopzIM8e3bj/RU1DPeEF14+dCGm6UeOYm4jvCyxqIEQ5/eJzmbWfDWnUleFNMg== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^2.4.2" + cross-spawn "^6.0.5" + find-yarn-workspace-root "^1.2.1" + fs-extra "^7.0.1" + is-ci "^2.0.0" + klaw-sync "^6.0.0" + minimist "^1.2.0" + rimraf "^2.6.3" + semver "^5.6.0" + slash "^2.0.0" + tmp "^0.0.33" + path-browserify@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" @@ -15573,6 +15611,11 @@ postcss@^7, postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.17, po source-map "^0.6.1" supports-color "^6.1.0" +postinstall-postinstall@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/postinstall-postinstall/-/postinstall-postinstall-2.1.0.tgz#4f7f77441ef539d1512c40bd04c71b06a4704ca3" + integrity sha512-7hQX6ZlZXIoRiWNrbMQaLzUUfH+sSx39u8EJ9HYuDc1kLo9IXKWjM5RSquZN1ad5GnH8CGFM78fsAAQi3OKEEQ== + preact@10.4.1: version "10.4.1" resolved "https://registry.yarnpkg.com/preact/-/preact-10.4.1.tgz#9b3ba020547673a231c6cf16f0fbaef0e8863431"