Skip to content

Commit

Permalink
add support to manage mfa with web3auth
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Dec 12, 2024
1 parent a5ed0d3 commit ad623c8
Show file tree
Hide file tree
Showing 40 changed files with 331 additions and 137 deletions.
4 changes: 4 additions & 0 deletions demo/vite-react-app/src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Main = () => {
switchChain,
showWalletConnectScanner,
enableMFA,
manageMFA,
} = useWeb3Auth();

const loggedInView = (
Expand All @@ -43,6 +44,9 @@ const Main = () => {
<button onClick={enableMFA} className={styles.card}>
Enable MFA
</button>
<button onClick={manageMFA} className={styles.card}>
Manage MFA
</button>
{web3Auth?.connectedAdapterName === WALLET_ADAPTERS.AUTH && (
<button onClick={signTransaction} className={styles.card}>
Sign Transaction
Expand Down
12 changes: 12 additions & 0 deletions demo/vite-react-app/src/services/web3auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IWeb3AuthContext {
showWalletConnectScanner: () => Promise<void>;
showWalletUi: () => Promise<void>;
enableMFA: () => Promise<void>;
manageMFA: () => Promise<void>;
}

export const Web3AuthContext = createContext<IWeb3AuthContext>({
Expand All @@ -47,6 +48,7 @@ export const Web3AuthContext = createContext<IWeb3AuthContext>({
showWalletConnectScanner: async () => {},
showWalletUi: async () => {},
enableMFA: async () => {},
manageMFA: async () => {},
});

export function useWeb3Auth(): IWeb3AuthContext {
Expand Down Expand Up @@ -226,6 +228,15 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
await web3Auth.enableMFA();
};

const manageMFA = async () => {
if (!web3Auth) {
console.log("web3auth not initialized yet");
uiConsole("web3auth not initialized yet");
return;
}
await web3Auth.manageMFA();
};

const addChain = async () => {
if (!provider) {
uiConsole("provider not initialized yet");
Expand Down Expand Up @@ -343,6 +354,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
switchChain,
showWalletConnectScanner,
enableMFA,
manageMFA,
showWalletUi,
};
return <Web3AuthContext.Provider value={contextProvider}>{children}</Web3AuthContext.Provider>;
Expand Down
Loading

0 comments on commit ad623c8

Please sign in to comment.