Update iframe modal for auto signin
This commit is contained in:
parent
b5b52df06f
commit
bf2123cfbc
@ -1,15 +1,12 @@
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
import { Box, Modal } from '@mui/material';
|
||||
|
||||
import {
|
||||
BASE_URL,
|
||||
VITE_WALLET_IFRAME_URL,
|
||||
} from 'utils/constants';
|
||||
import { generateNonce, SiweMessage } from 'siwe';
|
||||
import axios from 'axios';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { Box, Modal } from '@mui/material';
|
||||
|
||||
import { BASE_URL, VITE_WALLET_IFRAME_URL } from 'utils/constants';
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
headers: {
|
||||
@ -19,23 +16,12 @@ const axiosInstance = axios.create({
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
const AutoSignInIFrameModal = (
|
||||
// {
|
||||
// setAccounts,
|
||||
// setIsDataReceived,
|
||||
// isVisible,
|
||||
// }: {
|
||||
// setAccounts: (accounts: string[]) => void;
|
||||
// setIsDataReceived: (isReceived: boolean) => void;
|
||||
// isVisible: boolean;
|
||||
// }
|
||||
) => {
|
||||
const AutoSignInIFrameModal = () => {
|
||||
const navigate = useNavigate();
|
||||
useEffect(() => {
|
||||
const handleMessage = async (event: MessageEvent) => {
|
||||
if (event.origin !== VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
// setIsDataReceived(true);
|
||||
if (event.data.type === 'SIGN_IN_RESPONSE') {
|
||||
try {
|
||||
const { success } = (
|
||||
@ -45,14 +31,13 @@ const AutoSignInIFrameModal = (
|
||||
})
|
||||
).data;
|
||||
|
||||
if(success) {
|
||||
navigate("/")
|
||||
if (success) {
|
||||
navigate('/');
|
||||
}
|
||||
return success;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
// setAccounts(event.data.data);
|
||||
} else if (event.data.type === 'ERROR') {
|
||||
console.error('Error from wallet:', event.data.message);
|
||||
}
|
||||
@ -70,7 +55,9 @@ const AutoSignInIFrameModal = (
|
||||
if (event.origin !== VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
if (event.data.type === 'ACCOUNT_ADDRESS_RESPONSE') {
|
||||
const iframe = document.getElementById('autoSignInFrame') as HTMLIFrameElement;
|
||||
const iframe = document.getElementById(
|
||||
'autoSignInFrame',
|
||||
) as HTMLIFrameElement;
|
||||
|
||||
if (!iframe.contentWindow) {
|
||||
console.error('Iframe not found or not loaded');
|
||||
@ -86,7 +73,7 @@ const AutoSignInIFrameModal = (
|
||||
nonce: generateNonce(),
|
||||
// Human-readable ASCII assertion that the user will sign, and it must not contain `\n`.
|
||||
statement: 'Sign in With Ethereum.',
|
||||
}).prepareMessage()
|
||||
}).prepareMessage();
|
||||
|
||||
iframe.contentWindow.postMessage(
|
||||
{
|
||||
@ -96,8 +83,6 @@ const AutoSignInIFrameModal = (
|
||||
},
|
||||
VITE_WALLET_IFRAME_URL,
|
||||
);
|
||||
|
||||
// setAccounts(event.data.data);
|
||||
} else if (event.data.type === 'ERROR') {
|
||||
console.error('Error from wallet:', event.data.message);
|
||||
}
|
||||
@ -110,9 +95,10 @@ const AutoSignInIFrameModal = (
|
||||
};
|
||||
}, []);
|
||||
|
||||
// /////////////////////////////////////////////////
|
||||
const getAddressFromWallet = useCallback(() => {
|
||||
const iframe = document.getElementById('autoSignInFrame') as HTMLIFrameElement;
|
||||
const iframe = document.getElementById(
|
||||
'autoSignInFrame',
|
||||
) as HTMLIFrameElement;
|
||||
|
||||
if (!iframe.contentWindow) {
|
||||
console.error('Iframe not found or not loaded');
|
||||
|
Loading…
Reference in New Issue
Block a user