Take private key from browser localstorage instead of accounts context #16
@ -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",
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user