diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dcc6d2e..8974b2a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,12 @@ jobs: if: steps.npm-cache.outputs.cache-hit != 'true' run: npm ci --cache .npm + - name: Check types + run: npm run check:types + + - name: Lint check + run: npm run lint:check + - name: Install fdp-play run: npm install -g @fairdatasociety/fdp-play diff --git a/package-lock.json b/package-lock.json index 39e2001..4fcc8ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@emotion/react": "^11.10.4", "@emotion/styled": "^11.10.4", - "@fairdatasociety/fdp-contracts-js": "^3.6.1", + "@fairdatasociety/fdp-contracts-js": "^3.8.0", "@fairdatasociety/fdp-storage": "^0.10.0", "@mui/icons-material": "^5.10.6", "@mui/material": "^5.10.7", @@ -23,7 +23,6 @@ "@types/react-dom": "^18.0.6", "@web3modal/ethereum": "^2.0.0-beta.5", "@web3modal/react": "^2.0.0-beta.5", - "alchemy-sdk": "^2.6.0", "axios": "^0.27.2", "ethers": "^5.7.2", "react": "^18.2.0", @@ -3367,9 +3366,9 @@ } }, "node_modules/@fairdatasociety/fdp-contracts-js": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/@fairdatasociety/fdp-contracts-js/-/fdp-contracts-js-3.7.1.tgz", - "integrity": "sha512-G1TMIAJPIsfxEvubZh2qiiQb4XJx07jdmwUIvBNR2+PCdN2KnCNYQo1b4xkSFxk8BzY7hnXtricmIlNUmv3N0w==", + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@fairdatasociety/fdp-contracts-js/-/fdp-contracts-js-3.8.0.tgz", + "integrity": "sha512-Lfr/kxCBZ4IYWwAkeRa2fSi9suYd5DxTG5xunfuwMm32FeB99fL7tI19sb5tjPyRj6bphJPaRWmFCdPJ+yfZsg==", "peerDependencies": { "ethers": ">=5.6.4" } @@ -9084,35 +9083,6 @@ "ajv": "^6.9.1" } }, - "node_modules/alchemy-sdk": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/alchemy-sdk/-/alchemy-sdk-2.6.0.tgz", - "integrity": "sha512-5Oe0WCPPsPtIWMVPTlpLcamMHSBQyxpmAX/np+BmNMU0w5V8U+r8MweeqSuWDFPQ8sQiq+bG7xP/NwbBvif9vw==", - "dependencies": { - "@ethersproject/abi": "^5.7.0", - "@ethersproject/abstract-provider": "^5.7.0", - "@ethersproject/bignumber": "^5.7.0", - "@ethersproject/bytes": "^5.7.0", - "@ethersproject/contracts": "^5.7.0", - "@ethersproject/hash": "^5.7.0", - "@ethersproject/networks": "^5.7.0", - "@ethersproject/providers": "^5.7.0", - "@ethersproject/units": "^5.7.0", - "@ethersproject/wallet": "^5.7.0", - "@ethersproject/web": "^5.7.0", - "axios": "^0.26.1", - "sturdy-websocket": "^0.2.1", - "websocket": "^1.0.34" - } - }, - "node_modules/alchemy-sdk/node_modules/axios": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", - "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", - "dependencies": { - "follow-redirects": "^1.14.8" - } - }, "node_modules/anser": { "version": "1.4.10", "resolved": "https://registry.npmjs.org/anser/-/anser-1.4.10.tgz", @@ -10314,6 +10284,7 @@ "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.7.tgz", "integrity": "sha512-kukuqc39WOHtdxtw4UScxF/WVnMFVSQVKhtx3AjZJzhd0RGZZldcrfSEbVsWWe6KNH253574cq5F+wpv0G9pJw==", "hasInstallScript": true, + "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" }, @@ -11644,15 +11615,6 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, - "node_modules/d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "dependencies": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" - } - }, "node_modules/damerau-levenshtein": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", @@ -12418,30 +12380,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es5-ext": { - "version": "0.10.62", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", - "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", - "hasInstallScript": true, - "dependencies": { - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.3", - "next-tick": "^1.1.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", - "dependencies": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, "node_modules/es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", @@ -12455,15 +12393,6 @@ "es6-promise": "^4.0.3" } }, - "node_modules/es6-symbol": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", - "dependencies": { - "d": "^1.0.1", - "ext": "^1.1.2" - } - }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -13951,19 +13880,6 @@ } ] }, - "node_modules/ext": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", - "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", - "dependencies": { - "type": "^2.7.2" - } - }, - "node_modules/ext/node_modules/type": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", - "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" - }, "node_modules/extend-shallow": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", @@ -21490,11 +21406,6 @@ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" }, - "node_modules/next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" - }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -27580,11 +27491,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/sturdy-websocket": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/sturdy-websocket/-/sturdy-websocket-0.2.1.tgz", - "integrity": "sha512-NnzSOEKyv4I83qbuKw9ROtJrrT6Z/Xt7I0HiP/e6H6GnpeTDvzwGIGeJ8slai+VwODSHQDooW2CAilJwT9SpRg==" - }, "node_modules/style-loader": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-3.3.1.tgz", @@ -28395,11 +28301,6 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" }, - "node_modules/type": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -28768,6 +28669,7 @@ "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", "hasInstallScript": true, + "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" }, @@ -29297,22 +29199,6 @@ "node": ">=4.0" } }, - "node_modules/websocket": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.34.tgz", - "integrity": "sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==", - "dependencies": { - "bufferutil": "^4.0.1", - "debug": "^2.2.0", - "es5-ext": "^0.10.50", - "typedarray-to-buffer": "^3.1.5", - "utf-8-validate": "^5.0.2", - "yaeti": "^0.0.6" - }, - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/websocket-driver": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", @@ -29334,19 +29220,6 @@ "node": ">=0.8.0" } }, - "node_modules/websocket/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/websocket/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" - }, "node_modules/whatwg-encoding": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", @@ -29909,14 +29782,6 @@ "node": ">=10" } }, - "node_modules/yaeti": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", - "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==", - "engines": { - "node": ">=0.10.32" - } - }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -32147,9 +32012,9 @@ } }, "@fairdatasociety/fdp-contracts-js": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/@fairdatasociety/fdp-contracts-js/-/fdp-contracts-js-3.7.1.tgz", - "integrity": "sha512-G1TMIAJPIsfxEvubZh2qiiQb4XJx07jdmwUIvBNR2+PCdN2KnCNYQo1b4xkSFxk8BzY7hnXtricmIlNUmv3N0w==", + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@fairdatasociety/fdp-contracts-js/-/fdp-contracts-js-3.8.0.tgz", + "integrity": "sha512-Lfr/kxCBZ4IYWwAkeRa2fSi9suYd5DxTG5xunfuwMm32FeB99fL7tI19sb5tjPyRj6bphJPaRWmFCdPJ+yfZsg==", "requires": {} }, "@fairdatasociety/fdp-storage": { @@ -36489,37 +36354,6 @@ "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", "requires": {} }, - "alchemy-sdk": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/alchemy-sdk/-/alchemy-sdk-2.6.0.tgz", - "integrity": "sha512-5Oe0WCPPsPtIWMVPTlpLcamMHSBQyxpmAX/np+BmNMU0w5V8U+r8MweeqSuWDFPQ8sQiq+bG7xP/NwbBvif9vw==", - "requires": { - "@ethersproject/abi": "^5.7.0", - "@ethersproject/abstract-provider": "^5.7.0", - "@ethersproject/bignumber": "^5.7.0", - "@ethersproject/bytes": "^5.7.0", - "@ethersproject/contracts": "^5.7.0", - "@ethersproject/hash": "^5.7.0", - "@ethersproject/networks": "^5.7.0", - "@ethersproject/providers": "^5.7.0", - "@ethersproject/units": "^5.7.0", - "@ethersproject/wallet": "^5.7.0", - "@ethersproject/web": "^5.7.0", - "axios": "^0.26.1", - "sturdy-websocket": "^0.2.1", - "websocket": "^1.0.34" - }, - "dependencies": { - "axios": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", - "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", - "requires": { - "follow-redirects": "^1.14.8" - } - } - } - }, "anser": { "version": "1.4.10", "resolved": "https://registry.npmjs.org/anser/-/anser-1.4.10.tgz", @@ -37446,6 +37280,7 @@ "version": "4.0.7", "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.7.tgz", "integrity": "sha512-kukuqc39WOHtdxtw4UScxF/WVnMFVSQVKhtx3AjZJzhd0RGZZldcrfSEbVsWWe6KNH253574cq5F+wpv0G9pJw==", + "optional": true, "requires": { "node-gyp-build": "^4.3.0" } @@ -38431,15 +38266,6 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, - "d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "requires": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" - } - }, "damerau-levenshtein": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", @@ -39039,26 +38865,6 @@ "is-symbol": "^1.0.2" } }, - "es5-ext": { - "version": "0.10.62", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", - "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", - "requires": { - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.3", - "next-tick": "^1.1.0" - } - }, - "es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", - "requires": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, "es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", @@ -39072,15 +38878,6 @@ "es6-promise": "^4.0.3" } }, - "es6-symbol": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", - "requires": { - "d": "^1.0.1", - "ext": "^1.1.2" - } - }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -40216,21 +40013,6 @@ } } }, - "ext": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", - "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", - "requires": { - "type": "^2.7.2" - }, - "dependencies": { - "type": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", - "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" - } - } - }, "extend-shallow": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", @@ -45957,11 +45739,6 @@ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" }, - "next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" - }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -50310,11 +50087,6 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, - "sturdy-websocket": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/sturdy-websocket/-/sturdy-websocket-0.2.1.tgz", - "integrity": "sha512-NnzSOEKyv4I83qbuKw9ROtJrrT6Z/Xt7I0HiP/e6H6GnpeTDvzwGIGeJ8slai+VwODSHQDooW2CAilJwT9SpRg==" - }, "style-loader": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-3.3.1.tgz", @@ -50922,11 +50694,6 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" }, - "type": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" - }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -51190,6 +50957,7 @@ "version": "5.0.10", "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", + "optional": true, "requires": { "node-gyp-build": "^4.3.0" } @@ -51562,34 +51330,6 @@ "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==" }, - "websocket": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.34.tgz", - "integrity": "sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==", - "requires": { - "bufferutil": "^4.0.1", - "debug": "^2.2.0", - "es5-ext": "^0.10.50", - "typedarray-to-buffer": "^3.1.5", - "utf-8-validate": "^5.0.2", - "yaeti": "^0.0.6" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" - } - } - }, "websocket-driver": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", @@ -52067,11 +51807,6 @@ "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==" }, - "yaeti": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", - "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==" - }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/package.json b/package.json index 628082e..13c458d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "dependencies": { "@emotion/react": "^11.10.4", "@emotion/styled": "^11.10.4", - "@fairdatasociety/fdp-contracts-js": "^3.6.1", + "@fairdatasociety/fdp-contracts-js": "^3.8.0", "@fairdatasociety/fdp-storage": "^0.10.0", "@mui/icons-material": "^5.10.6", "@mui/material": "^5.10.7", @@ -18,7 +18,6 @@ "@types/react-dom": "^18.0.6", "@web3modal/ethereum": "^2.0.0-beta.5", "@web3modal/react": "^2.0.0-beta.5", - "alchemy-sdk": "^2.6.0", "axios": "^0.27.2", "ethers": "^5.7.2", "react": "^18.2.0", @@ -34,6 +33,8 @@ "scripts": { "start": "react-scripts start", "start:batch": "REACT_APP_BATCH_ID=$npm_config_batch react-scripts start", + "check:types": "tsc --project tsconfig.json", + "lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", "lint": "eslint .", "build": "react-scripts build", "test": "react-scripts test", diff --git a/src/context/account.context.tsx b/src/context/account.context.tsx index 94a2202..3f3b333 100644 --- a/src/context/account.context.tsx +++ b/src/context/account.context.tsx @@ -1,33 +1,11 @@ import React, { useMemo, useState } from "react"; import { createContext, useContext } from "react"; -import { BigNumber, providers, utils, Wallet } from "ethers"; +import { BigNumber, providers, Wallet } from "ethers"; import { ENS } from "@fairdatasociety/fdp-contracts-js"; -import { - Alchemy, - Network as AlchemyNetwork, - AlchemySettings, -} from "alchemy-sdk"; import { RegisterResponse } from "../model/internal-messages.model"; import { Account } from "../model/general.types"; import { useNetworks } from "./network.context"; import { FDS_DOMAIN } from "../constants/constants"; -import { Network } from "../model/network.model"; - -function getAlchemySettings(network: Network): AlchemySettings | null { - switch (network.label) { - case "Görli": - return { - apiKey: process.env.REACT_APP_ALCHEMY_API_KEY, - network: AlchemyNetwork.ETH_GOERLI, - }; - case "Sepolia": - return { - url: `https://eth-sepolia.g.alchemy.com/v2/${process.env.REACT_APP_ALCHEMY_API_KEY}`, - }; - default: - return null; - } -} export interface IAccountContext { inviteKey: string | null; @@ -38,12 +16,7 @@ export interface IAccountContext { account: Account, minBalance: BigNumber ) => Promise; - estimateGas: ( - username: string, - account: string, - publicKey: string, - defaultMinBalance: BigNumber - ) => Promise; + estimateGas: (defaultMinBalance: BigNumber) => Promise; } const AccountContext = createContext({ @@ -71,22 +44,10 @@ export const AccountProvider = ({ children }: AccountContextProps) => { ); const ens = useMemo( - () => - new ENS( - currentNetwork.label === "Sepolia" - ? { ...currentNetwork.config, rpcUrl: "http://rpc.sepolia.org" } - : currentNetwork.config, - provider, - FDS_DOMAIN - ), + () => new ENS(currentNetwork.config, provider, FDS_DOMAIN), [currentNetwork, provider] ); - const alchemy = useMemo(() => { - const alchemySettings = getAlchemySettings(currentNetwork); - return alchemySettings ? new Alchemy(alchemySettings) : null; - }, [currentNetwork]); - const generateWallet = async (): Promise => { try { const wallet = Wallet.createRandom(); @@ -116,29 +77,13 @@ export const AccountProvider = ({ children }: AccountContextProps) => { return balance.gte(minBalance); }; - const estimateGas = async ( - username: string, - account: string, - publicKey: string, - defaultMinBalance: BigNumber - ): Promise => { + const estimateGas = (defaultMinBalance: BigNumber): Promise => { try { - const [amount, price] = await Promise.all([ - ens.registerUsernameEstimateGas(username, account, publicKey), - alchemy - ? alchemy.core.getGasPrice() - : Promise.resolve(BigNumber.from(100000000000)), - ]); - - const gasPriceInEth = Number( - utils.formatEther(price.mul(BigNumber.from(amount))) - ); - - return utils.parseEther(String(Math.ceil(gasPriceInEth * 1000) / 1000)); + return ens.registerUsernameApproximatePrice() } catch (error) { console.error(error); - return defaultMinBalance; + return Promise.resolve(defaultMinBalance); } }; diff --git a/src/model/network.model.ts b/src/model/network.model.ts index cca93dd..da167fe 100644 --- a/src/model/network.model.ts +++ b/src/model/network.model.ts @@ -10,6 +10,7 @@ export interface Network { fdsRegistrar: string; publicResolver: string; }; + gasEstimation: number; performChecks: boolean; }; } diff --git a/src/pages/register/register.tsx b/src/pages/register/register.tsx index ac8092d..d0c8016 100644 --- a/src/pages/register/register.tsx +++ b/src/pages/register/register.tsx @@ -23,6 +23,7 @@ import { sendFunds } from "../../utils/account.utils"; import axios from "axios"; import { RegistrationRequest } from "@fairdatasociety/fdp-storage/dist/account/types"; import { useLocales } from "../../context/locales.context"; +import { MULTIPLY_ETH_RESULT_FACTOR, roundWeiToEther } from '../../utils/eth.utils' enum Steps { UsernamePassword, @@ -74,18 +75,9 @@ const Register = () => { const { intl } = useLocales(); const getMinBalance = async () => { - const wallet = fdpClient.account.wallet; - const account = wallet?.address as string; - const publicKey = fdpClient.account.publicKey as string; - - const price = await estimateGas( - data.username, - account, - publicKey, - minBalance - ); - - setMinBalance(price.mul(BigNumber.from(2))); + const price = await estimateGas(minBalance); + + setMinBalance(price.mul(BigNumber.from(MULTIPLY_ETH_RESULT_FACTOR))); }; const onUsernamePasswordSubmit = (registerData: RegisterData) => { @@ -233,15 +225,19 @@ const Register = () => { fdpClient.account.setAccountFromMnemonic(mnemonic); - setLoadingMessage("CHECKING_BALANCE"); + // if registration request is not set, check if user has enough balance + // otherwise it means that user continued registration process + if (!registrationRequest) { + setLoadingMessage("CHECKING_BALANCE"); - const canProceed = await checkMinBalance( - fdpClient.account.wallet?.address as string, - minBalance - ); + const canProceed = await checkMinBalance( + fdpClient.account.wallet?.address as string, + minBalance + ); - if (!canProceed) { - throw new Error("Insufficient funds"); + if (!canProceed) { + throw new Error("Insufficient funds"); + } } setLoadingMessage("REGISTERING_NEW_ACCOUNT"); @@ -321,7 +317,7 @@ const Register = () => { intl.get(message) + " " + intl.get("WAITING_FOR_PAYMENT_AMOUNT", { - price: utils.formatEther(minBalance), + price: roundWeiToEther(minBalance), }) ); } else if (step === Steps.Complete) { diff --git a/src/utils/eth.utils.ts b/src/utils/eth.utils.ts new file mode 100644 index 0000000..ccf32b8 --- /dev/null +++ b/src/utils/eth.utils.ts @@ -0,0 +1,33 @@ +import { BigNumber, ethers } from 'ethers' + +/** + * Multiply ETH result by this to get ETH amount with a margin + */ +export const MULTIPLY_ETH_RESULT_FACTOR = 2; + +/** + * Rounds wei value to ether with maxDecimals + * @param weiValue Wei value to round + * @param maxDecimals Max decimals to round to + */ +export function roundWeiToEther(weiValue: BigNumber, maxDecimals: number = 5): string { + const divider = ethers.BigNumber.from('10').pow(18 - maxDecimals); + const roundUpValue = ethers.BigNumber.from('10').pow(18 - maxDecimals - 1); + const smallestUnit = ethers.BigNumber.from('10').pow(18 - maxDecimals); + + let roundedValue = weiValue.div(divider).mul(divider); + + if (weiValue.isZero()) { + return '0'; + } + + if(weiValue.mod(divider).gte(roundUpValue)){ + roundedValue = roundedValue.add(divider); + } + + if (roundedValue.isZero()) { + roundedValue = smallestUnit; + } + + return ethers.utils.formatUnits(roundedValue, 18); +} diff --git a/test/utils.spec.ts b/test/utils.spec.ts new file mode 100644 index 0000000..4cef12d --- /dev/null +++ b/test/utils.spec.ts @@ -0,0 +1,22 @@ +import { utils } from 'ethers' +import { roundWeiToEther } from '../src/utils/eth.utils' + +describe("Utils", () => { + test("roundWeiToEther", async () => { + const roundTest = (input: string, expected: string) => { + expect(roundWeiToEther(utils.parseEther(input))).toEqual(expected); + } + + roundTest('0.000000012443523451', '0.00001'); + roundTest('0.0001244352345', '0.00013'); + roundTest('0.0001', '0.0001'); + roundTest('505', '505.0'); + roundTest('1', '1.0'); + roundTest('1.01', '1.01'); + roundTest('1.001', '1.001'); + roundTest('1.0001', '1.0001'); + roundTest('1.00001', '1.00001'); + roundTest('1.000011', '1.00002'); + roundTest('2342352352352352341.000011', '2342352352352352341.00002'); + }); +});