diff --git a/src/context/MoralisContext/MoralisContext.ts b/src/context/MoralisContext/MoralisContext.ts index bdac111..8fc79c1 100644 --- a/src/context/MoralisContext/MoralisContext.ts +++ b/src/context/MoralisContext/MoralisContext.ts @@ -25,7 +25,9 @@ export interface MoralisContextValue { isInitializing: boolean; initialize: (options?: { serverUrl?: string; appId?: string }) => void; - authenticate: (options?: AuthenticateOptions) => Promise; + authenticate: ( + options?: AuthenticateOptions, + ) => Promise; logout: () => Promise; signup: Signup; login: Login; @@ -39,14 +41,16 @@ export interface MoralisContextValue { isLoggingOut: boolean; isAuthUndefined: boolean; - setUserData: (data: SetUserData) => Promise; + setUserData: (data: SetUserData) => Promise; user: MoralisType.User | null; _setUser: (user: MoralisType.User) => void; userError: null | Error; isUserUpdating: boolean; - refetchUserData: () => Promise; + refetchUserData: () => Promise; - enableWeb3: (options?: Web3EnableOptions) => void; + enableWeb3: ( + options?: Web3EnableOptions, + ) => Promise; deactivateWeb3: () => Promise; web3: MoralisType.MoralisWeb3Provider | null; isWeb3Enabled: boolean; diff --git a/src/hooks/core/useMoralis/_useMoralisAuth.ts b/src/hooks/core/useMoralis/_useMoralisAuth.ts index 87176a5..feba59b 100644 --- a/src/hooks/core/useMoralis/_useMoralisAuth.ts +++ b/src/hooks/core/useMoralis/_useMoralisAuth.ts @@ -82,7 +82,7 @@ export type Login = ( username: string, password: string, options?: LoginOptions, -) => Promise; +) => Promise | undefined>; export type Signup = ( username: string, @@ -90,7 +90,7 @@ export type Signup = ( email?: string, otherFields?: SetUserData, options?: SignupOptions, -) => Promise; +) => Promise | undefined>; export type OnAccountChanged = (account: string) => void; @@ -172,6 +172,7 @@ export const _useMoralisAuth = (options: UseMoralisAuthOptions) => { if (onSuccess) { onSuccess(user); } + return user; } catch (error) { setAuth({ state: AuthenticationState.ERROR, error }); setUser(null); @@ -231,6 +232,7 @@ export const _useMoralisAuth = (options: UseMoralisAuthOptions) => { if (onSuccess) { onSuccess(user); } + return user; } catch (error) { setAuth({ state: AuthenticationState.ERROR, error }); if (throwOnError) { @@ -274,6 +276,7 @@ export const _useMoralisAuth = (options: UseMoralisAuthOptions) => { if (onSuccess) { onSuccess(user); } + return user; } catch (error) { setAuth({ state: AuthenticationState.ERROR, error }); if (throwOnError) { diff --git a/src/hooks/core/useMoralis/_useMoralisUser.ts b/src/hooks/core/useMoralis/_useMoralisUser.ts index a0176c5..87fd76f 100644 --- a/src/hooks/core/useMoralis/_useMoralisUser.ts +++ b/src/hooks/core/useMoralis/_useMoralisUser.ts @@ -63,6 +63,7 @@ export const _useMoralisUser = (Moralis: MoralisType) => { if (onSuccess) { onSuccess(user); } + return user; } catch (error) { if (userHasLocallyUpdated) { user.revert(); @@ -116,6 +117,7 @@ export const _useMoralisUser = (Moralis: MoralisType) => { if (onSuccess) { onSuccess(newUserData); } + return newUserData; } catch (error) { setError(error); if (throwOnError) { diff --git a/src/hooks/core/useMoralis/_useMoralisWeb3.ts b/src/hooks/core/useMoralis/_useMoralisWeb3.ts index 4b50325..5d17525 100644 --- a/src/hooks/core/useMoralis/_useMoralisWeb3.ts +++ b/src/hooks/core/useMoralis/_useMoralisWeb3.ts @@ -12,13 +12,17 @@ export interface Web3EnableOptions { anyNetwork?: boolean; } +type EnableWeb3 = ( + options?: Web3EnableOptions | undefined, +) => Promise; + /** * Handles enabling of web3 and providing it, as soon as the user is authenticated */ export const _useMoralisWeb3 = ( Moralis: MoralisType, ): { - enableWeb3: (options?: Web3EnableOptions) => Promise; + enableWeb3: EnableWeb3; web3: null | MoralisType.MoralisWeb3Provider; isWeb3Enabled: boolean; web3EnableError: Error | null; @@ -99,7 +103,7 @@ export const _useMoralisWeb3 = ( /** * Enable web3 with the browsers web3Provider (only available when a user has been authenticated) */ - const enableWeb3 = useCallback( + const enableWeb3 = useCallback( async ({ throwOnError, onComplete, @@ -113,13 +117,16 @@ export const _useMoralisWeb3 = ( try { // TODO: fix typechecking when passing ...rest // @ts-ignore - const currentWeb3 = await Moralis.enableWeb3(rest); + const currentWeb3: MoralisType.Web3Provider = await Moralis.enableWeb3( + rest, + ); _setIsWeb3Enabled(true); if (onSuccess) { onSuccess(currentWeb3); } + return currentWeb3; } catch (error) { setEnableWeb3Error(error); if (throwOnError) { diff --git a/src/hooks/internal/_useResolveAsyncCall/_useResolveAsyncCall.ts b/src/hooks/internal/_useResolveAsyncCall/_useResolveAsyncCall.ts index 5cc3341..5ed02d4 100644 --- a/src/hooks/internal/_useResolveAsyncCall/_useResolveAsyncCall.ts +++ b/src/hooks/internal/_useResolveAsyncCall/_useResolveAsyncCall.ts @@ -75,6 +75,7 @@ export const _useResolveCall = ( if (onSuccess) { onSuccess(results); } + return results; } catch (error) { setData(initialData); setError(error);