Use accounts state for getting pk
This commit is contained in:
parent
555b971236
commit
5f434406ee
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user