Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to manage mfa with web3auth #2037

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading