Update hooks/useMenuElements.ios.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Marcos Rodriguez Vélez 2024-11-07 23:30:37 -04:00 committed by GitHub
parent f069800895
commit f3e41c146d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,21 +50,32 @@ const useMenuElements = () => {
);
useEffect(() => {
if (__DEV__) {
console.debug('useEffect: walletsInitialized =', walletsInitialized);
}
if (walletsInitialized && eventEmitter) {
if (__DEV__) {
console.debug('Adding event listeners for menu actions');
eventEmitter.addListener('openSettings', eventActions.openSettings);
eventEmitter.addListener('addWalletMenuAction', eventActions.addWallet);
eventEmitter.addListener('importWalletMenuAction', eventActions.importWallet);
eventEmitter.addListener('reloadTransactionsMenuAction', eventActions.reloadTransactions);
}
try {
const listeners = [
eventEmitter.addListener('openSettings', eventActions.openSettings),
eventEmitter.addListener('addWalletMenuAction', eventActions.addWallet),
eventEmitter.addListener('importWalletMenuAction', eventActions.importWallet),
eventEmitter.addListener('reloadTransactionsMenuAction', eventActions.reloadTransactions),
];
return () => {
if (__DEV__) {
console.debug('Removing event listeners for menu actions');
eventEmitter.removeAllListeners('openSettings');
eventEmitter.removeAllListeners('addWalletMenuAction');
eventEmitter.removeAllListeners('importWalletMenuAction');
eventEmitter.removeAllListeners('reloadTransactionsMenuAction');
}
listeners.forEach(listener => listener.remove());
};
} catch (error) {
console.error('Failed to set up menu event listeners:', error);
}
}
}, [walletsInitialized, eventActions]);