Use accounts state for getting pk

This commit is contained in:
Shreerang Kale 2025-04-25 15:48:45 +05:30
parent 555b971236
commit 5f434406ee

View File

@ -3,16 +3,21 @@ import { useAccounts } from '../context/AccountsContext';
import { getPathKey, sendMessage } from '../utils/misc';
const useExportPKEmbed = () => {
const { currentIndex } = useAccounts();
const { accounts } = useAccounts();
useEffect(() => {
const handleMessage = async (event: MessageEvent) => {
const { type, chainId } = event.data;
const { type, chainId, address } = event.data;
if (type !== 'REQUEST_ACCOUNT_PK') return;
try {
const pathKey = await getPathKey(chainId, currentIndex);
const selectedAccount = accounts.find(account => account.address === address);
if (!selectedAccount) {
throw new Error("Account not found")
}
const pathKey = await getPathKey(chainId, selectedAccount.index);
const privateKey = pathKey.privKey;
sendMessage(
@ -30,7 +35,7 @@ const useExportPKEmbed = () => {
return () => {
window.removeEventListener('message', handleMessage);
};
}, [currentIndex]);
}, [accounts]);
};
export default useExportPKEmbed;