diff --git a/src/screens/WalletEmbed.tsx b/src/screens/WalletEmbed.tsx index 0ca16d9..dd0a47f 100644 --- a/src/screens/WalletEmbed.tsx +++ b/src/screens/WalletEmbed.tsx @@ -46,27 +46,22 @@ export const WalletEmbed = () => { const { networksData } = useNetworks(); - const getAccountsData = useCallback(async (chainId: string) => { + const getAccountsData = useCallback(async (chainId: string): Promise => { const targetNetwork = networksData.find(network => network.chainId === chainId); if (!targetNetwork) { - return ''; + return []; } const accounts = await retrieveAccounts(targetNetwork); if (!accounts || accounts.length === 0) { - return ''; + return []; } - const accountsData = accounts.map(account => account.address).join(','); - return accountsData; + return accounts.map(account => account.address); }, [networksData]); - - const getAddressesFromData = (accountsData: string): string[] => - accountsData?.split(',') || []; - const sendMessage = ( source: Window | null, type: string, @@ -88,13 +83,13 @@ export const WalletEmbed = () => { if (event.data.type !== 'REQUEST_WALLET_ACCOUNTS') return; const accountsData = await getAccountsData(event.data.chainId); - if (!accountsData) { + + if (accountsData.length === 0) { sendMessage(event.source as Window, 'ERROR', 'Wallet accounts not found', event.origin); return; } - const addresses = getAddressesFromData(accountsData); - sendMessage(event.source as Window, 'WALLET_ACCOUNTS_DATA', addresses, event.origin); + sendMessage(event.source as Window, 'WALLET_ACCOUNTS_DATA', accountsData, event.origin); }; window.addEventListener('message', handleGetAccounts); @@ -110,7 +105,7 @@ export const WalletEmbed = () => { let accountsData = await getAccountsData(event.data.chainId); - if (!accountsData) { + if (accountsData.length === 0) { console.log("Accounts not found, creating wallet..."); await createWallet(networksData); @@ -118,8 +113,7 @@ export const WalletEmbed = () => { accountsData = await getAccountsData(event.data.chainId); } - const addresses = getAddressesFromData(accountsData); - sendMessage(event.source as Window, 'WALLET_ACCOUNTS_DATA', addresses, event.origin); + sendMessage(event.source as Window, 'WALLET_ACCOUNTS_DATA', accountsData, event.origin); }; window.addEventListener('message', handleCreateAccounts); @@ -348,7 +342,7 @@ export const WalletEmbed = () => { ) : ( - Loading... + )}