Keep method to post message in utils
This commit is contained in:
parent
a0977f910d
commit
5ab06ed460
@ -5,6 +5,7 @@ import { useNetworks } from '../context/NetworksContext';
|
|||||||
import { Account } from '../types';
|
import { Account } from '../types';
|
||||||
import { signMessage } from '../utils/sign-message';
|
import { signMessage } from '../utils/sign-message';
|
||||||
import { EIP155 } from '../utils/constants';
|
import { EIP155 } from '../utils/constants';
|
||||||
|
import { sendMessage } from '../utils/misc';
|
||||||
|
|
||||||
export const AutoSignIn = () => {
|
export const AutoSignIn = () => {
|
||||||
const { networksData } = useNetworks();
|
const { networksData } = useNetworks();
|
||||||
@ -25,15 +26,6 @@ export const AutoSignIn = () => {
|
|||||||
return accounts
|
return accounts
|
||||||
}, [networksData]);
|
}, [networksData]);
|
||||||
|
|
||||||
const sendMessage = (
|
|
||||||
source: Window | null,
|
|
||||||
type: string,
|
|
||||||
data: any,
|
|
||||||
origin: string
|
|
||||||
): void => {
|
|
||||||
source?.postMessage({ type, data }, origin);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleSignIn = async (event: MessageEvent) => {
|
const handleSignIn = async (event: MessageEvent) => {
|
||||||
if (event.data.type !== 'AUTO_SIGN_IN') return;
|
if (event.data.type !== 'AUTO_SIGN_IN') return;
|
||||||
@ -60,7 +52,6 @@ export const AutoSignIn = () => {
|
|||||||
const getAccountAddress = async (event: MessageEvent) => {
|
const getAccountAddress = async (event: MessageEvent) => {
|
||||||
if (event.data.type !== 'GET_ACCOUNT_ADDRESS') return;
|
if (event.data.type !== 'GET_ACCOUNT_ADDRESS') return;
|
||||||
|
|
||||||
|
|
||||||
if (event.data.secret !== process.env.REACT_APP_AUTH_SECRET) {
|
if (event.data.secret !== process.env.REACT_APP_AUTH_SECRET) {
|
||||||
console.log('Unauthorized app.');
|
console.log('Unauthorized app.');
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -169,7 +169,6 @@ export const WalletEmbed = () => {
|
|||||||
|
|
||||||
if (!checkSufficientFunds(amount, balance.amount)) {
|
if (!checkSufficientFunds(amount, balance.amount)) {
|
||||||
console.log("Insufficient funds detected");
|
console.log("Insufficient funds detected");
|
||||||
sendMessage(event.source as Window, 'INSUFFICIENT_FUNDS', null, event.origin);
|
|
||||||
throw new Error('Insufficient funds');
|
throw new Error('Insufficient funds');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user