diff --git a/src/hooks/useAddAccountEmbed.ts b/src/hooks/useAddAccountEmbed.ts index d226484..2514b1d 100644 --- a/src/hooks/useAddAccountEmbed.ts +++ b/src/hooks/useAddAccountEmbed.ts @@ -6,6 +6,7 @@ import useAccountsData from '../hooks/useAccountsData'; import { addAccount } from '../utils/accounts'; import { useAccounts } from '../context/AccountsContext'; import { Account, NetworksDataState } from '../types'; +import { ADD_ACCOUNT_RESPONSE, REQUEST_ADD_ACCOUNT } from '../utils/constants'; const REACT_APP_ALLOWED_URLS = process.env.REACT_APP_ALLOWED_URLS; @@ -24,7 +25,7 @@ const useAddAccountEmbed = () => { useEffect(() => { const handleAddAccount = async (event: MessageEvent) => { - if (event.data.type !== 'ADD_ACCOUNT') return; + if (event.data.type !== REQUEST_ADD_ACCOUNT) return; if (!REACT_APP_ALLOWED_URLS) { console.log('Unauthorized app origin:', event.origin); @@ -44,7 +45,7 @@ const useAddAccountEmbed = () => { const updatedAccounts = await getAccountsData(event.data.chainId); const addresses = updatedAccounts.map((account: Account) => account.address); - sendMessage(event.source as Window, 'ADD_ACCOUNT_RESPONSE', addresses, event.origin); + sendMessage(event.source as Window, ADD_ACCOUNT_RESPONSE, addresses, event.origin); }; window.addEventListener('message', handleAddAccount); diff --git a/src/hooks/useExportPrivateKeyEmbed.ts b/src/hooks/useExportPrivateKeyEmbed.ts index f791ad3..ec0e1cb 100644 --- a/src/hooks/useExportPrivateKeyEmbed.ts +++ b/src/hooks/useExportPrivateKeyEmbed.ts @@ -2,7 +2,7 @@ import { useEffect } from 'react'; import { useAccounts } from '../context/AccountsContext'; import { getPathKey, sendMessage } from '../utils/misc'; -import { ACCOUNT_PK_DATA, REQUEST_ACCOUNT_PK } from '../utils/constants'; +import { ACCOUNT_PK_RESPONSE, REQUEST_ACCOUNT_PK } from '../utils/constants'; const useExportPKEmbed = () => { const { accounts } = useAccounts(); @@ -24,7 +24,7 @@ const useExportPKEmbed = () => { sendMessage( event.source as Window, - ACCOUNT_PK_DATA, + ACCOUNT_PK_RESPONSE, { privateKey }, event.origin, ); diff --git a/src/screens/SignRequestEmbed.tsx b/src/screens/SignRequestEmbed.tsx index a364a2e..b5ec810 100644 --- a/src/screens/SignRequestEmbed.tsx +++ b/src/screens/SignRequestEmbed.tsx @@ -14,7 +14,7 @@ import AccountDetails from '../components/AccountDetails'; import styles from '../styles/stylesheet'; import { getCosmosAccountByHDPath, retrieveSingleAccount } from '../utils/accounts'; import { getMnemonic, getPathKey, sendMessage } from '../utils/misc'; -import { COSMOS, SIGN_MESSAGE, SIGNED_MESSAGE } from '../utils/constants'; +import { COSMOS, REQUEST_SIGN_MESSAGE, SIGN_MESSAGE_RESPONSE } from '../utils/constants'; import { useNetworks } from '../context/NetworksContext'; const REACT_APP_ALLOWED_URLS = process.env.REACT_APP_ALLOWED_URLS; @@ -61,7 +61,7 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => { sendMessage( sourceWindow, - SIGNED_MESSAGE, + SIGN_MESSAGE_RESPONSE, { signature }, origin, ); @@ -71,7 +71,7 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => { console.error('Signing failed:', err); sendMessage( sourceWindow!, - SIGNED_MESSAGE, + SIGN_MESSAGE_RESPONSE, { error: err }, origin, ); @@ -84,7 +84,7 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => { if (sourceWindow && origin) { sendMessage( sourceWindow, - SIGNED_MESSAGE, + SIGN_MESSAGE_RESPONSE, { error: 'User rejected the request' }, origin, ); @@ -93,7 +93,7 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => { useEffect(() => { const handleCosmosSignMessage = async (event: MessageEvent) => { - if (event.data.type !== SIGN_MESSAGE) return; + if (event.data.type !== REQUEST_SIGN_MESSAGE) return; if (!REACT_APP_ALLOWED_URLS) { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index cdbfb5e..1e1a1e8 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -78,18 +78,20 @@ export const IS_IMPORT_WALLET_ENABLED = false; // iframe request types export const REQUEST_COSMOS_ACCOUNTS_DATA = 'REQUEST_COSMOS_ACCOUNTS_DATA'; export const REQUEST_SIGN_TX = 'REQUEST_SIGN_TX'; -export const SIGN_MESSAGE = 'SIGN_MESSAGE'; +export const REQUEST_SIGN_MESSAGE = 'REQUEST_SIGN_MESSAGE'; export const REQUEST_WALLET_ACCOUNTS = 'REQUEST_WALLET_ACCOUNTS'; export const REQUEST_CREATE_OR_GET_ACCOUNTS = 'REQUEST_CREATE_OR_GET_ACCOUNTS'; export const REQUEST_TX = 'REQUEST_TX'; export const AUTO_SIGN_IN = 'AUTO_SIGN_IN'; export const REQUEST_ACCOUNT_PK = 'REQUEST_ACCOUNT_PK'; +export const REQUEST_ADD_ACCOUNT = 'ADD_ACCOUNT'; // iframe response types export const COSMOS_ACCOUNTS_RESPONSE = 'COSMOS_ACCOUNTS_RESPONSE'; export const SIGN_TX_RESPONSE = 'SIGN_TX_RESPONSE'; -export const SIGNED_MESSAGE = 'SIGNED_MESSAGE'; -export const WALLET_ACCOUNTS_DATA = 'WALLET_ACCOUNTS_DATA'; +export const SIGN_MESSAGE_RESPONSE = 'SIGN_MESSAGE_RESPONSE'; export const TRANSACTION_RESPONSE = 'TRANSACTION_RESPONSE'; export const SIGN_IN_RESPONSE = 'SIGN_IN_RESPONSE'; -export const ACCOUNT_PK_DATA = 'ACCOUNT_PK_DATA'; +export const ACCOUNT_PK_RESPONSE = 'ACCOUNT_PK_RESPONSE'; +export const ADD_ACCOUNT_RESPONSE = 'ADD_ACCOUNT_RESPONSE'; +export const WALLET_ACCOUNTS_DATA = 'WALLET_ACCOUNTS_DATA';