Pass address for specific chainId in message

This commit is contained in:
Isha 2024-11-07 10:48:27 +05:30
parent c1fdbf6db3
commit 6664a47886

View File

@ -23,20 +23,36 @@ window.addEventListener('message', (event: MessageEvent) => {
if (event.data.type === 'REQUEST_WALLET_ACCOUNTS') { if (event.data.type === 'REQUEST_WALLET_ACCOUNTS') {
try { try {
const accountsData = localStorage.getItem('accounts/cosmos:laconic-testnet-2/0'); let accountsData = '';
const indices = localStorage.getItem(`addAccountCounter/cosmos:${event.data.chainId}`);
for (let i = 0; i < Number(indices); i++) {
const account = localStorage.getItem(`accounts/cosmos:${event.data.chainId}/${i}`);
if (account) {
accountsData += `${account},`;
}
}
// Remove trailing comma
accountsData = accountsData.slice(0, -1);
if (!accountsData) { if (!accountsData) {
event.source?.postMessage({ event.source?.postMessage({
type: 'ERROR', type: 'ERROR',
message: 'Wallet accounts not found in local storage' message: 'Wallet accounts not found in local storage',
}); });
return; return;
} }
(event.source as Window)?.postMessage({ const elements = accountsData.split(',');
type: 'WALLET_ACCOUNTS_DATA', const addresses = elements.filter((_, index) => (index + 1) % 4 === 0);
data: accountsData
}, 'http://localhost:3000'); (event.source as Window)?.postMessage(
{
type: 'WALLET_ACCOUNTS_DATA',
data: addresses,
},
'http://localhost:3000'
);
} catch (error) { } catch (error) {
(event.source as Window)?.postMessage({ (event.source as Window)?.postMessage({