Skip to content

Commit

Permalink
fix: typescript fixes support for Moralis v.1.0.6 (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW authored Jan 20, 2022
1 parent 398ed1e commit 9e3f574
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 61 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/core/useChain/useChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/core/useMoralis/_useMoralisAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface AuthenticateOptions {
onComplete?: () => void;
throwOnError?: boolean;
type?: AuthType;
provider?: MoralisType.Web3ProviderType;
connector?: MoralisType.Connector;
chainId?: number;
signingMessage?: string;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions src/hooks/core/useMoralis/_useMoralisWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Web3EnableOptions {
onSuccess?: (web3: unknown) => void;
onComplete?: () => void;
throwOnError?: boolean;
provider?: MoralisType.Web3ProviderType;
connector?: MoralisType.Connector;
chainId?: number;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useWeb3ExecuteFunction = (
};

//@ts-ignore
return await Moralis.Web3.executeFunction(allParams);
return await Moralis.executeFunction(allParams);
},
[],
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/core/useWeb3Transfer/useWeb3Transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const useWeb3Transfer = (
};

//@ts-ignore
return await Moralis.Web3.transfer(allParams);
return await Moralis.transfer(allParams);
}, []);

return _useResolveCall<Web3TransferResult, Web3TransferParameters>(
Expand Down
96 changes: 50 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -915,15 +915,22 @@
"@babel/helper-validator-option" "^7.16.7"
"@babel/plugin-transform-typescript" "^7.16.7"

"@babel/[email protected].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/[email protected].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/[email protected]", "@babel/runtime@^7.8.4":
"@babel/[email protected]":
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==
Expand Down Expand Up @@ -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/[email protected].0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.5.0.tgz#babec47cab892c51f8dd652ce7f2e3e14283981a"
integrity sha512-KWfP3xOnJeF89Uf/FCJdV1a2aDJe5XTN2N52p4fcQ34QhDqQFkgQKZ39VGtiqUgHcLI8DfT0l9azC3KFTunqtA==
"@ethersproject/[email protected].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"

Expand All @@ -1410,10 +1417,10 @@
dependencies:
"@ethersproject/logger" "^5.5.0"

"@ethersproject/[email protected].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/[email protected].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"
Expand All @@ -1435,7 +1442,15 @@
bech32 "1.1.4"
ws "7.4.6"

"@ethersproject/[email protected]", "@ethersproject/random@^5.5.0":
"@ethersproject/[email protected]":
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==
Expand Down Expand Up @@ -1538,18 +1553,7 @@
"@ethersproject/transactions" "^5.5.0"
"@ethersproject/wordlists" "^5.5.0"

"@ethersproject/[email protected]":
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/[email protected]", "@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==
Expand Down Expand Up @@ -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==

[email protected]:
version "1.0.2"
Expand Down Expand Up @@ -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==

[email protected].1:
version "5.5.1"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.5.1.tgz#d3259a95a42557844aa543906c537106c0406fbf"
integrity sha512-RodEvUFZI+EmFcE6bwkuJqpCYHazdzeR1nMzg+YWQSmQEsNtfl1KHGfp/FWZYl48bI/g7cgBeP2IlPthjiVngw==
[email protected].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"
Expand All @@ -4319,11 +4323,11 @@ [email protected]:
"@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"
Expand All @@ -4332,7 +4336,7 @@ [email protected]:
"@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:
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 9e3f574

Please sign in to comment.