From 9e3f574f4a15b27547089ba0de96aa7b74399890 Mon Sep 17 00:00:00 2001 From: Erno Wever Date: Thu, 20 Jan 2022 22:29:56 +0000 Subject: [PATCH] fix: typescript fixes support for Moralis v.1.0.6 (#174) --- package.json | 4 +- src/hooks/core/useChain/useChain.ts | 4 +- src/hooks/core/useMoralis/_useMoralisAuth.ts | 5 +- src/hooks/core/useMoralis/_useMoralisWeb3.ts | 15 +-- .../useWeb3ExecuteFunction.ts | 2 +- .../core/useWeb3Transfer/useWeb3Transfer.ts | 2 +- yarn.lock | 96 ++++++++++--------- 7 files changed, 67 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index e4bb9c8..771f0bc 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "husky": "^7.0.4", "jest": "^27.4.5", "lint-staged": "^12.1.2", - "moralis": "^1.0.2", + "moralis": "^1.0.6", "prettier": "^2.5.1", "rollup": "^2.61.1", "rollup-plugin-cleaner": "^1.0.0", @@ -77,7 +77,7 @@ "typescript": "^4.5.4" }, "peerDependencies": { - "moralis": ">=1.0.2", + "moralis": ">=1.0.6", "react": ">=17.0.0", "react-dom": ">=17.0.0" }, diff --git a/src/hooks/core/useChain/useChain.ts b/src/hooks/core/useChain/useChain.ts index b3582a6..a665d1b 100644 --- a/src/hooks/core/useChain/useChain.ts +++ b/src/hooks/core/useChain/useChain.ts @@ -15,7 +15,7 @@ export const useChain = () => { const switchNetwork = async (providedChainId: string) => { try { - await Moralis.Web3.switchNetwork(providedChainId); + await Moralis.switchNetwork(providedChainId); } catch (error) { if (error.code === 4902) { const chainData = getChain(providedChainId); @@ -28,7 +28,7 @@ export const useChain = () => { const { chainId, name, nativeCurrency, rpc, blockExplorerUrl } = chainData; - await Moralis.Web3.addNetwork( + await Moralis.addNetwork( chainId, name, nativeCurrency.name, diff --git a/src/hooks/core/useMoralis/_useMoralisAuth.ts b/src/hooks/core/useMoralis/_useMoralisAuth.ts index fa89545..039669e 100644 --- a/src/hooks/core/useMoralis/_useMoralisAuth.ts +++ b/src/hooks/core/useMoralis/_useMoralisAuth.ts @@ -52,6 +52,7 @@ export interface AuthenticateOptions { onComplete?: () => void; throwOnError?: boolean; type?: AuthType; + provider?: MoralisType.Web3ProviderType; connector?: MoralisType.Connector; chainId?: number; signingMessage?: string; @@ -134,7 +135,7 @@ export const _useMoralisAuth = (options: UseMoralisAuthOptions) => { useState(false); /** - * Authenticates the user by calling the Moralis.Web3.authenticate function + * Authenticates the user by calling the Moralis.authenticate function * The auth state will update upon successful/error * For direct feedback, a callback can be provided */ @@ -157,7 +158,7 @@ export const _useMoralisAuth = (options: UseMoralisAuthOptions) => { try { // TODO: fix typechecking when passing ...rest - const user = await Moralis.Web3.authenticate(rest); + const user = await Moralis.authenticate(rest); setUser(user); if (_setIsWeb3Enabled) { diff --git a/src/hooks/core/useMoralis/_useMoralisWeb3.ts b/src/hooks/core/useMoralis/_useMoralisWeb3.ts index 68f2af1..cc6b4d5 100644 --- a/src/hooks/core/useMoralis/_useMoralisWeb3.ts +++ b/src/hooks/core/useMoralis/_useMoralisWeb3.ts @@ -6,6 +6,7 @@ export interface Web3EnableOptions { onSuccess?: (web3: unknown) => void; onComplete?: () => void; throwOnError?: boolean; + provider?: MoralisType.Web3ProviderType; connector?: MoralisType.Connector; chainId?: number; } @@ -57,11 +58,11 @@ export const _useMoralisWeb3 = (Moralis: MoralisType) => { setProvider(null); }; - const unsubChainChanged = Moralis.Web3.onChainChanged(setChainId); - const unsubAccountChanged = Moralis.Web3.onAccountChanged(setAccount); - const unsubEnable = Moralis.Web3.onWeb3Enabled(handleConnect); - const unsubDeactivate = Moralis.Web3.onWeb3Deactivated(handleDisconnect); - const unsubDisconnect = Moralis.Web3.onDisconnect(handleDisconnect); + const unsubChainChanged = Moralis.onChainChanged(setChainId); + const unsubAccountChanged = Moralis.onAccountChanged(setAccount); + const unsubEnable = Moralis.onWeb3Enabled(handleConnect); + const unsubDeactivate = Moralis.onWeb3Deactivated(handleDisconnect); + const unsubDisconnect = Moralis.onDisconnect(handleDisconnect); return () => { unsubChainChanged(); @@ -89,7 +90,7 @@ export const _useMoralisWeb3 = (Moralis: MoralisType) => { try { // TODO: fix typechecking when passing ...rest // @ts-ignore - const currentWeb3 = await Moralis.Web3.enableWeb3(rest); + const currentWeb3 = await Moralis.enableWeb3(rest); _setIsWeb3Enabled(true); @@ -116,7 +117,7 @@ export const _useMoralisWeb3 = (Moralis: MoralisType) => { // TODO: resolver errors/loading state const deactivateWeb3 = useCallback(async () => { - await Moralis.Web3.deactivateWeb3(); + await Moralis.deactivateWeb3(); }, []); const network = useMemo(() => connector?.network ?? null, [connector]); diff --git a/src/hooks/core/useWeb3ExecuteFunction/useWeb3ExecuteFunction.ts b/src/hooks/core/useWeb3ExecuteFunction/useWeb3ExecuteFunction.ts index f6ce680..1e9738f 100644 --- a/src/hooks/core/useWeb3ExecuteFunction/useWeb3ExecuteFunction.ts +++ b/src/hooks/core/useWeb3ExecuteFunction/useWeb3ExecuteFunction.ts @@ -39,7 +39,7 @@ export const useWeb3ExecuteFunction = ( }; //@ts-ignore - return await Moralis.Web3.executeFunction(allParams); + return await Moralis.executeFunction(allParams); }, [], ); diff --git a/src/hooks/core/useWeb3Transfer/useWeb3Transfer.ts b/src/hooks/core/useWeb3Transfer/useWeb3Transfer.ts index ab075df..28334d6 100644 --- a/src/hooks/core/useWeb3Transfer/useWeb3Transfer.ts +++ b/src/hooks/core/useWeb3Transfer/useWeb3Transfer.ts @@ -45,7 +45,7 @@ export const useWeb3Transfer = ( }; //@ts-ignore - return await Moralis.Web3.transfer(allParams); + return await Moralis.transfer(allParams); }, []); return _useResolveCall( diff --git a/yarn.lock b/yarn.lock index c8954f6..741887d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -915,15 +915,22 @@ "@babel/helper-validator-option" "^7.16.7" "@babel/plugin-transform-typescript" "^7.16.7" -"@babel/runtime-corejs3@7.16.5": - version "7.16.5" - resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.16.5.tgz#9057d879720c136193f0440bc400088212a74894" - integrity sha512-F1pMwvTiUNSAM8mc45kccMQxj31x3y3P+tA/X8hKNWp3/hUsxdGxZ3D3H8JIkxtfA8qGkaBTKvcmvStaYseAFw== +"@babel/runtime-corejs3@7.16.8": + version "7.16.8" + resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.16.8.tgz#ea533d96eda6fdc76b1812248e9fbd0c11d4a1a7" + integrity sha512-3fKhuICS1lMz0plI5ktOE/yEtBRMVxplzRkdn6mJQ197XiY0JnrzYV0+Mxozq3JZ8SBV9Ecurmw1XsGbwOf+Sg== dependencies: - core-js-pure "^3.19.0" + core-js-pure "^3.20.2" regenerator-runtime "^0.13.4" -"@babel/runtime@7.16.5", "@babel/runtime@^7.8.4": +"@babel/runtime@7.16.7": + version "7.16.7" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.7.tgz#03ff99f64106588c9c403c6ecb8c3bafbbdff1fa" + integrity sha512-9E9FJowqAsytyOY6LG+1KuueckRL+aQW+mKvXRXnuFGyRAyepJPmEo9vgMfXUA6O9u3IeEdv9MAkppFcaQwogQ== + dependencies: + regenerator-runtime "^0.13.4" + +"@babel/runtime@^7.8.4": version "7.16.5" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.5.tgz#7f3e34bf8bdbbadf03fbb7b1ea0d929569c9487a" integrity sha512-TXWihFIS3Pyv5hzR7j6ihmeLkZfrXGxAr5UfSl8CHf+6q/wpiYDkUau0czckpYG8QmnCIuPpdLtuA9VmuGGyMA== @@ -1381,10 +1388,10 @@ resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.5.0.tgz#0c2caebeff98e10aefa5aef27d7441c7fd18cf5d" integrity sha512-rIY/6WPm7T8n3qS2vuHTUBPdXHl+rGxWxW5okDfo9J4Z0+gRRZT0msvUdIJkE4/HS29GUMziwGaaKO2bWONBrg== -"@ethersproject/networks@5.5.0": - version "5.5.0" - resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.5.0.tgz#babec47cab892c51f8dd652ce7f2e3e14283981a" - integrity sha512-KWfP3xOnJeF89Uf/FCJdV1a2aDJe5XTN2N52p4fcQ34QhDqQFkgQKZ39VGtiqUgHcLI8DfT0l9azC3KFTunqtA== +"@ethersproject/networks@5.5.2": + version "5.5.2" + resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.5.2.tgz#784c8b1283cd2a931114ab428dae1bd00c07630b" + integrity sha512-NEqPxbGBfy6O3x4ZTISb90SjEDkWYDUbEeIFhJly0F7sZjoQMnj5KYzMSkMkLKZ+1fGpx00EDpHQCy6PrDupkQ== dependencies: "@ethersproject/logger" "^5.5.0" @@ -1410,10 +1417,10 @@ dependencies: "@ethersproject/logger" "^5.5.0" -"@ethersproject/providers@5.5.0": - version "5.5.0" - resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.5.0.tgz#bc2876a8fe5e0053ed9828b1f3767ae46e43758b" - integrity sha512-xqMbDnS/FPy+J/9mBLKddzyLLAQFjrVff5g00efqxPzcAwXiR+SiCGVy6eJ5iAIirBOATjx7QLhDNPGV+AEQsw== +"@ethersproject/providers@5.5.2": + version "5.5.2" + resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.5.2.tgz#131ccf52dc17afd0ab69ed444b8c0e3a27297d99" + integrity sha512-hkbx7x/MKcRjyrO4StKXCzCpWer6s97xnm34xkfPiarhtEUVAN4TBBpamM+z66WcTt7H5B53YwbRj1n7i8pZoQ== dependencies: "@ethersproject/abstract-provider" "^5.5.0" "@ethersproject/abstract-signer" "^5.5.0" @@ -1435,7 +1442,15 @@ bech32 "1.1.4" ws "7.4.6" -"@ethersproject/random@5.5.0", "@ethersproject/random@^5.5.0": +"@ethersproject/random@5.5.1": + version "5.5.1" + resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.5.1.tgz#7cdf38ea93dc0b1ed1d8e480ccdaf3535c555415" + integrity sha512-YaU2dQ7DuhL5Au7KbcQLHxcRHfgyNgvFV4sQOo0HrtW3Zkrc9ctWNz8wXQ4uCSfSDsqX2vcjhroxU5RQRV0nqA== + dependencies: + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + +"@ethersproject/random@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.5.0.tgz#305ed9e033ca537735365ac12eed88580b0f81f9" integrity sha512-egGYZwZ/YIFKMHcoBUo8t3a8Hb/TKYX8BCBoLjudVCZh892welR3jOxgOmb48xznc9bTcMm7Tpwc1gHC1PFNFQ== @@ -1538,18 +1553,7 @@ "@ethersproject/transactions" "^5.5.0" "@ethersproject/wordlists" "^5.5.0" -"@ethersproject/web@5.5.0": - version "5.5.0" - resolved "https://registry.yarnpkg.com/@ethersproject/web/-/web-5.5.0.tgz#0e5bb21a2b58fb4960a705bfc6522a6acf461e28" - integrity sha512-BEgY0eL5oH4mAo37TNYVrFeHsIXLRxggCRG/ksRIxI2X5uj5IsjGmcNiRN/VirQOlBxcUhCgHhaDLG4m6XAVoA== - dependencies: - "@ethersproject/base64" "^5.5.0" - "@ethersproject/bytes" "^5.5.0" - "@ethersproject/logger" "^5.5.0" - "@ethersproject/properties" "^5.5.0" - "@ethersproject/strings" "^5.5.0" - -"@ethersproject/web@^5.5.0": +"@ethersproject/web@5.5.1", "@ethersproject/web@^5.5.0": version "5.5.1" resolved "https://registry.yarnpkg.com/@ethersproject/web/-/web-5.5.1.tgz#cfcc4a074a6936c657878ac58917a61341681316" integrity sha512-olvLvc1CB12sREc1ROPSHTdFCdvMh0J5GSJYiQg2D0hdD4QmJDy8QYDb1CvoqD/bF1c++aeKv2sR5uduuG9dQg== @@ -3646,10 +3650,10 @@ core-js-compat@^3.20.0, core-js-compat@^3.20.2: browserslist "^4.19.1" semver "7.0.0" -core-js-pure@^3.19.0: - version "3.20.0" - resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.20.0.tgz#7253feccf8bb05b72c153ddccdbe391ddbffbe03" - integrity sha512-qsrbIwWSEEYOM7z616jAVgwhuDDtPLwZSpUsU3vyUkHYqKTf/uwOJBZg2V7lMurYWkpVlaVOxBrfX0Q3ppvjfg== +core-js-pure@^3.20.2: + version "3.20.3" + resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.20.3.tgz#6cc4f36da06c61d95254efc54024fe4797fd5d02" + integrity sha512-Q2H6tQ5MtPtcC7f3HxJ48i4Q7T9ybPKgvWyuH7JXIoNa2pm0KuBnycsET/qw1SLLZYfbsbrZQNMeIOClb+6WIA== core-util-is@1.0.2: version "1.0.2" @@ -4299,10 +4303,10 @@ esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== -ethers@5.5.1: - version "5.5.1" - resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.5.1.tgz#d3259a95a42557844aa543906c537106c0406fbf" - integrity sha512-RodEvUFZI+EmFcE6bwkuJqpCYHazdzeR1nMzg+YWQSmQEsNtfl1KHGfp/FWZYl48bI/g7cgBeP2IlPthjiVngw== +ethers@5.5.3: + version "5.5.3" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.5.3.tgz#1e361516711c0c3244b6210e7e3ecabf0c75fca0" + integrity sha512-fTT4WT8/hTe/BLwRUtl7I5zlpF3XC3P/Xwqxc5AIP2HGlH15qpmjs0Ou78az93b1rLITzXLFxoNX63B8ZbUd7g== dependencies: "@ethersproject/abi" "5.5.0" "@ethersproject/abstract-provider" "5.5.1" @@ -4319,11 +4323,11 @@ ethers@5.5.1: "@ethersproject/json-wallets" "5.5.0" "@ethersproject/keccak256" "5.5.0" "@ethersproject/logger" "5.5.0" - "@ethersproject/networks" "5.5.0" + "@ethersproject/networks" "5.5.2" "@ethersproject/pbkdf2" "5.5.0" "@ethersproject/properties" "5.5.0" - "@ethersproject/providers" "5.5.0" - "@ethersproject/random" "5.5.0" + "@ethersproject/providers" "5.5.2" + "@ethersproject/random" "5.5.1" "@ethersproject/rlp" "5.5.0" "@ethersproject/sha2" "5.5.0" "@ethersproject/signing-key" "5.5.0" @@ -4332,7 +4336,7 @@ ethers@5.5.1: "@ethersproject/transactions" "5.5.0" "@ethersproject/units" "5.5.0" "@ethersproject/wallet" "5.5.0" - "@ethersproject/web" "5.5.0" + "@ethersproject/web" "5.5.1" "@ethersproject/wordlists" "5.5.0" execa@^5.0.0, execa@^5.1.1: @@ -7007,16 +7011,16 @@ modify-values@^1.0.0: resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== -moralis@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/moralis/-/moralis-1.0.2.tgz#46d0088d569bfa27ab8e0d0c5024f6b1cb3c7e16" - integrity sha512-90kJ7L6TrHQUf++pl+ygb6rATv9oV9VVNln9BvQ97lzRPKS7Ic0veac3NREnJ7FiOY/covc828mtKtfKGbt3xQ== +moralis@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/moralis/-/moralis-1.0.6.tgz#039b67d7a3b0a301f2b6e964eb3b74467670a7af" + integrity sha512-+ebcHuppfKvlID70U4Nga4kUgakc5/zeuyczNvcnj7U6ZCpRl9LN+bKm8InOFSx1BjdxdsMxJqXOc0TH2qq0Qw== dependencies: - "@babel/runtime" "7.16.5" - "@babel/runtime-corejs3" "7.16.5" + "@babel/runtime" "7.16.7" + "@babel/runtime-corejs3" "7.16.8" "@metamask/detect-provider" "^1.2.0" axios "0.24.0" - ethers "5.5.1" + ethers "5.5.3" react-native-crypto-js "1.0.0" uuid "^8.3.2" ws "^8.3.0"