Send only addresses in response
This commit is contained in:
parent
a1da25e513
commit
a3eb778ab6
@ -1,11 +1,10 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
|
||||
import { useNetworks } from '../context/NetworksContext';
|
||||
import { COSMOS } from '../utils/constants';
|
||||
import { sendMessage } from '../utils/misc';
|
||||
import useAccountsData from '../hooks/useAccountsData';
|
||||
import useGetOrCreateAccounts from '../hooks/useGetOrCreateAccounts';
|
||||
import { addAccount, retrieveSingleAccount } from '../utils/accounts';
|
||||
import { addAccount } from '../utils/accounts';
|
||||
import { useAccounts } from '../context/AccountsContext';
|
||||
import { Account, NetworksDataState } from '../types';
|
||||
|
||||
@ -15,13 +14,13 @@ export const AddAccountEmbed = () => {
|
||||
useAccounts();
|
||||
const { getAccountsData } = useAccountsData();
|
||||
|
||||
const addAccountHandler = async (network: NetworksDataState) => {
|
||||
const addAccountHandler = useCallback(async (network: NetworksDataState) => {
|
||||
const newAccount = await addAccount(network);
|
||||
if (newAccount) {
|
||||
setAccounts([...accounts, newAccount]);
|
||||
setCurrentIndex(newAccount.index);
|
||||
}
|
||||
};
|
||||
}, [accounts, setAccounts, setCurrentIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleAddAccount = async (event: MessageEvent) => {
|
||||
@ -35,12 +34,10 @@ export const AddAccountEmbed = () => {
|
||||
const network = networksData.find(network => network.chainId === event.data.chainId);
|
||||
|
||||
await addAccountHandler(network!);
|
||||
const accounts = await getAccountsData(event.data.chainId);
|
||||
const accountsData: string[] = accounts.map((account: Account) => account.address);
|
||||
|
||||
const accountsData = await getAccountsData(event.data.chainId);
|
||||
|
||||
console.log({accountsData})
|
||||
|
||||
sendMessage(event.source as Window, 'ADD_ACCOUNT_RESPONSE', { message: event.data.message, accountsData }, event.origin);
|
||||
sendMessage(event.source as Window, 'ADD_ACCOUNT_RESPONSE', accountsData, event.origin);
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleAddAccount);
|
||||
@ -48,12 +45,11 @@ export const AddAccountEmbed = () => {
|
||||
return () => {
|
||||
window.removeEventListener('message', handleAddAccount);
|
||||
};
|
||||
}, [networksData, getAccountsData]);
|
||||
}, [networksData, getAccountsData, addAccountHandler]);
|
||||
|
||||
// Custom hook for adding listener to get accounts data
|
||||
useGetOrCreateAccounts();
|
||||
|
||||
console.log('wallet')
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
|
Loading…
Reference in New Issue
Block a user