Compare commits

..

No commits in common. "main" and "v0.1.7-zenith-0.2.4" have entirely different histories.

2 changed files with 7 additions and 19 deletions

View File

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

View File

@ -1,10 +1,12 @@
import { useEffect } from 'react';
import { retrieveNetworksData, retrieveAccounts } from '../utils/accounts';
import { useAccounts } from '../context/AccountsContext';
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;
@ -12,23 +14,9 @@ const useExportPKEmbed = () => {
if (type !== REQUEST_ACCOUNT_PK) return;
try {
// 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);
const selectedAccount = accounts.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);
@ -49,7 +37,7 @@ const useExportPKEmbed = () => {
return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
}, [accounts]);
};
export default useExportPKEmbed;