Skip to content

Commit

Permalink
Add better typings
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Apr 30, 2024
1 parent 38e509a commit 36b899e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/hooks/modal-react-hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { useWalletServicesPlugin } from "./useWalletServicesPlugin";
export { useWeb3Auth } from "./useWeb3auth";
export { Web3AuthProvider } from "./Web3AuthProvider";
export { type Web3AuthContextConfig, Web3AuthProvider } from "./Web3AuthProvider";
17 changes: 15 additions & 2 deletions packages/hooks/modal-react-hooks/src/useWeb3auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { ADAPTER_EVENTS, CustomChainConfig, type IPlugin, type IProvider, WalletInitializationError, WalletLoginError } from "@web3auth/base";
import {
ADAPTER_EVENTS,
ADAPTER_STATUS,
type ADAPTER_STATUS_TYPE,
CustomChainConfig,
type IPlugin,
type IProvider,
WalletInitializationError,
WalletLoginError,
} from "@web3auth/base";
import { type ModalConfig } from "@web3auth/modal";
import { type LoginParams, type OpenloginUserInfo } from "@web3auth/openlogin-adapter";
import { useCallback, useContext, useEffect, useState } from "react";
Expand All @@ -12,7 +21,8 @@ export const useWeb3Auth = () => {
const [provider, setProvider] = useState<IProvider | null>(null);
const [userInfo, setUserInfo] = useState<Partial<OpenloginUserInfo> | null>(null);
const [isMFAEnabled, setIsMFAEnabled] = useState<boolean>(false);
const [status, setStatus] = useState<string | null>(null);
const [isInitialized, setIsInitialized] = useState<boolean>(false);
const [status, setStatus] = useState<ADAPTER_STATUS_TYPE | null>(null);

useEffect(() => {
const addState = async () => {
Expand All @@ -37,6 +47,8 @@ export const useWeb3Auth = () => {
useEffect(() => {
if (web3auth?.status) {
setStatus(web3auth.status);
// we want initialized to be true in case of any status other than NOT_READY
setIsInitialized(web3auth.status !== ADAPTER_STATUS.NOT_READY);
}
}, [web3auth?.status]);

Expand Down Expand Up @@ -123,6 +135,7 @@ export const useWeb3Auth = () => {
return {
web3auth,
isConnected,
isInitialized,
provider,
userInfo,
isMFAEnabled,
Expand Down

0 comments on commit 36b899e

Please sign in to comment.