Take private key from browser localstorage instead of accounts context #16

Merged
prathamesh merged 2 commits from sk-fix-export-pk-rc into main 2026-02-20 11:09:05 +00:00
2 changed files with 19 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "web-wallet",
"version": "0.1.7-zenith-0.2.4",
"version": "0.1.7-zenith-0.2.5",
"private": true,
"dependencies": {
"@laconic-network/cosmjs-util": "^0.1.0",

View File

@ -1,12 +1,10 @@
import { useEffect } from 'react';
import { useAccounts } from '../context/AccountsContext';
import { retrieveNetworksData, retrieveAccounts } from '../utils/accounts';
import { getPathKey, sendMessage } from '../utils/misc';
import { ACCOUNT_PK_RESPONSE, REQUEST_ACCOUNT_PK } from '../utils/constants';
const useExportPKEmbed = () => {
const { accounts } = useAccounts();
useEffect(() => {
const handleMessage = async (event: MessageEvent) => {
const { type, chainId, address } = event.data;
@ -14,9 +12,23 @@ const useExportPKEmbed = () => {
if (type !== REQUEST_ACCOUNT_PK) return;
try {
const selectedAccount = accounts.find(account => account.address === address);
// Look up the network and accounts directly from storage
// rather than relying on the accounts context, which can be
// overwritten by HomeScreen's fetchAccounts for a different network.
const networksData = await retrieveNetworksData();
const targetNetwork = networksData.find(
net => `${net.namespace}:${net.chainId}` === chainId,
);
if (!targetNetwork) {
throw new Error("Network not found");
}
const networkAccounts = await retrieveAccounts(targetNetwork);
const selectedAccount = networkAccounts?.find(account => account.address === address);
if (!selectedAccount) {
throw new Error("Account not found")
throw new Error("Account not found");
}
const pathKey = await getPathKey(chainId, selectedAccount.index);
@ -37,7 +49,7 @@ const useExportPKEmbed = () => {
return () => {
window.removeEventListener('message', handleMessage);
};
}, [accounts]);
}, []);
};
export default useExportPKEmbed;