mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
wip
This commit is contained in:
parent
7926ea6218
commit
1c8b0908b2
@ -2,7 +2,7 @@ import 'react-native-gesture-handler'; // should be on top
|
|||||||
|
|
||||||
import { CommonActions } from '@react-navigation/native';
|
import { CommonActions } from '@react-navigation/native';
|
||||||
import React, { lazy, Suspense, useCallback, useEffect, useRef } from 'react';
|
import React, { lazy, Suspense, useCallback, useEffect, useRef } from 'react';
|
||||||
import { AppState, AppStateStatus, Linking, NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
import { AppState, AppStateStatus, Linking } from 'react-native';
|
||||||
import A from '../blue_modules/analytics';
|
import A from '../blue_modules/analytics';
|
||||||
import BlueClipboard from '../blue_modules/clipboard';
|
import BlueClipboard from '../blue_modules/clipboard';
|
||||||
import { updateExchangeRate } from '../blue_modules/currency';
|
import { updateExchangeRate } from '../blue_modules/currency';
|
||||||
@ -24,9 +24,6 @@ const HandOffComponentListener = lazy(() => import('../components/HandOffCompone
|
|||||||
const WidgetCommunication = lazy(() => import('../components/WidgetCommunication'));
|
const WidgetCommunication = lazy(() => import('../components/WidgetCommunication'));
|
||||||
const WatchConnectivity = lazy(() => import('./WatchConnectivity'));
|
const WatchConnectivity = lazy(() => import('./WatchConnectivity'));
|
||||||
|
|
||||||
// @ts-ignore: NativeModules.EventEmitter is not typed
|
|
||||||
const eventEmitter = Platform.OS === 'ios' ? new NativeEventEmitter(NativeModules.EventEmitter) : undefined;
|
|
||||||
|
|
||||||
const ClipboardContentType = Object.freeze({
|
const ClipboardContentType = Object.freeze({
|
||||||
BITCOIN: 'BITCOIN',
|
BITCOIN: 'BITCOIN',
|
||||||
LIGHTNING: 'LIGHTNING',
|
LIGHTNING: 'LIGHTNING',
|
||||||
@ -224,32 +221,15 @@ const CompanionDelegates = () => {
|
|||||||
[processPushNotifications, showClipboardAlert, wallets],
|
[processPushNotifications, showClipboardAlert, wallets],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onNotificationReceived = useCallback(
|
|
||||||
async (notification: { data: { data: any } }) => {
|
|
||||||
const payload = Object.assign({}, notification, notification.data);
|
|
||||||
if (notification.data && notification.data.data) Object.assign(payload, notification.data.data);
|
|
||||||
// @ts-ignore: Notifications type is not defined
|
|
||||||
payload.foreground = true;
|
|
||||||
|
|
||||||
// @ts-ignore: Notifications type is not defined
|
|
||||||
await Notifications.addNotification(payload);
|
|
||||||
// @ts-ignore: Notifications type is not defined
|
|
||||||
if (payload.foreground) await processPushNotifications();
|
|
||||||
},
|
|
||||||
[processPushNotifications],
|
|
||||||
);
|
|
||||||
|
|
||||||
const addListeners = useCallback(() => {
|
const addListeners = useCallback(() => {
|
||||||
const urlSubscription = Linking.addEventListener('url', handleOpenURL);
|
const urlSubscription = Linking.addEventListener('url', handleOpenURL);
|
||||||
const appStateSubscription = AppState.addEventListener('change', handleAppStateChange);
|
const appStateSubscription = AppState.addEventListener('change', handleAppStateChange);
|
||||||
const notificationSubscription = eventEmitter?.addListener('onNotificationReceived', onNotificationReceived);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urlSubscription,
|
urlSubscription,
|
||||||
appStateSubscription,
|
appStateSubscription,
|
||||||
notificationSubscription,
|
|
||||||
};
|
};
|
||||||
}, [handleOpenURL, handleAppStateChange, onNotificationReceived]);
|
}, [handleOpenURL, handleAppStateChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const subscriptions = addListeners();
|
const subscriptions = addListeners();
|
||||||
@ -257,7 +237,6 @@ const CompanionDelegates = () => {
|
|||||||
return () => {
|
return () => {
|
||||||
subscriptions.urlSubscription?.remove();
|
subscriptions.urlSubscription?.remove();
|
||||||
subscriptions.appStateSubscription?.remove();
|
subscriptions.appStateSubscription?.remove();
|
||||||
subscriptions.notificationSubscription?.remove();
|
|
||||||
};
|
};
|
||||||
}, [addListeners]);
|
}, [addListeners]);
|
||||||
|
|
||||||
|
@ -10,24 +10,20 @@ Uses MenuElementsEmitter for event handling.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const { MenuElementsEmitter } = NativeModules;
|
const { MenuElementsEmitter } = NativeModules;
|
||||||
const eventEmitter = Platform.OS === 'ios' || Platform.OS === 'macos' ? new NativeEventEmitter(MenuElementsEmitter) : undefined;
|
const eventEmitter =
|
||||||
|
(Platform.OS === 'ios' || Platform.OS === 'macos') && MenuElementsEmitter ? new NativeEventEmitter(MenuElementsEmitter) : null;
|
||||||
|
|
||||||
const useMenuElements = () => {
|
const useMenuElements = () => {
|
||||||
const { walletsInitialized } = useStorage();
|
const { walletsInitialized } = useStorage();
|
||||||
|
|
||||||
const reloadTransactionsMenuActionRef = useRef<() => void>(() => {});
|
const reloadTransactionsMenuActionRef = useRef<() => void>(() => {});
|
||||||
|
|
||||||
const setReloadTransactionsMenuActionFunction = (newFunction: () => void) => {
|
const setReloadTransactionsMenuActionFunction = useCallback((newFunction: () => void) => {
|
||||||
console.debug('Setting reloadTransactionsMenuActionFunction.');
|
console.debug('Setting reloadTransactionsMenuActionFunction.');
|
||||||
reloadTransactionsMenuActionRef.current = newFunction;
|
reloadTransactionsMenuActionRef.current = newFunction;
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const dispatchNavigate = useCallback((routeName: string, screen?: string) => {
|
const dispatchNavigate = useCallback((routeName: string, screen?: string) => {
|
||||||
const action = CommonActions.navigate({
|
NavigationService.dispatch(CommonActions.navigate({ name: routeName, params: screen ? { screen } : undefined }));
|
||||||
name: routeName,
|
|
||||||
params: screen ? { screen } : undefined,
|
|
||||||
});
|
|
||||||
NavigationService.dispatch(action);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const eventActions = useMemo(
|
const eventActions = useMemo(
|
||||||
@ -36,47 +32,29 @@ const useMenuElements = () => {
|
|||||||
addWallet: () => dispatchNavigate('AddWalletRoot'),
|
addWallet: () => dispatchNavigate('AddWalletRoot'),
|
||||||
importWallet: () => dispatchNavigate('AddWalletRoot', 'ImportWallet'),
|
importWallet: () => dispatchNavigate('AddWalletRoot', 'ImportWallet'),
|
||||||
reloadTransactions: () => {
|
reloadTransactions: () => {
|
||||||
if (__DEV__) {
|
console.debug('Calling reloadTransactionsMenuActionFunction');
|
||||||
console.debug('Calling reloadTransactionsMenuActionFunction');
|
reloadTransactionsMenuActionRef.current?.();
|
||||||
}
|
|
||||||
if (reloadTransactionsMenuActionRef.current) {
|
|
||||||
reloadTransactionsMenuActionRef.current();
|
|
||||||
} else {
|
|
||||||
console.warn('No reload function set for reloadTransactions menu action');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[dispatchNavigate],
|
[dispatchNavigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (__DEV__) {
|
if (!walletsInitialized || !eventEmitter) return;
|
||||||
console.debug('useEffect: walletsInitialized =', walletsInitialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (walletsInitialized && eventEmitter) {
|
|
||||||
if (__DEV__) {
|
|
||||||
console.debug('Adding event listeners for menu actions');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const listeners = [
|
|
||||||
eventEmitter.addListener('openSettings', eventActions.openSettings),
|
|
||||||
eventEmitter.addListener('addWalletMenuAction', eventActions.addWallet),
|
|
||||||
eventEmitter.addListener('importWalletMenuAction', eventActions.importWallet),
|
|
||||||
eventEmitter.addListener('reloadTransactionsMenuAction', eventActions.reloadTransactions),
|
|
||||||
];
|
|
||||||
|
|
||||||
return () => {
|
console.debug('Setting up menu event listeners');
|
||||||
if (__DEV__) {
|
|
||||||
console.debug('Removing event listeners for menu actions');
|
const listeners = [
|
||||||
}
|
eventEmitter.addListener('openSettings', eventActions.openSettings),
|
||||||
listeners.forEach(listener => listener.remove());
|
eventEmitter.addListener('addWalletMenuAction', eventActions.addWallet),
|
||||||
};
|
eventEmitter.addListener('importWalletMenuAction', eventActions.importWallet),
|
||||||
} catch (error) {
|
eventEmitter.addListener('reloadTransactionsMenuAction', eventActions.reloadTransactions),
|
||||||
console.error('Failed to set up menu event listeners:', error);
|
];
|
||||||
}
|
|
||||||
}
|
return () => {
|
||||||
|
console.debug('Removing menu event listeners');
|
||||||
|
listeners.forEach(listener => listener.remove());
|
||||||
|
};
|
||||||
}, [walletsInitialized, eventActions]);
|
}, [walletsInitialized, eventActions]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -84,4 +62,4 @@ const useMenuElements = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useMenuElements;
|
export default useMenuElements;
|
||||||
|
@ -185,7 +185,6 @@
|
|||||||
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
|
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
|
||||||
{
|
{
|
||||||
NSDictionary *userInfo = notification.request.content.userInfo;
|
NSDictionary *userInfo = notification.request.content.userInfo;
|
||||||
[EventEmitter.sharedInstance sendNotification:userInfo];
|
|
||||||
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
|
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
@interface EventEmitter : RCTEventEmitter <RCTBridgeModule>
|
@interface EventEmitter : RCTEventEmitter <RCTBridgeModule>
|
||||||
|
|
||||||
+ (EventEmitter *)sharedInstance;
|
+ (EventEmitter *)sharedInstance;
|
||||||
- (void)sendNotification:(NSDictionary *)userInfo;
|
|
||||||
- (void)sendUserActivity:(NSDictionary *)userInfo;
|
- (void)sendUserActivity:(NSDictionary *)userInfo;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -36,12 +36,7 @@ RCT_EXPORT_MODULE();
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray<NSString *> *)supportedEvents {
|
- (NSArray<NSString *> *)supportedEvents {
|
||||||
return @[@"onNotificationReceived",@"onUserActivityOpen"];
|
return @[@"onUserActivityOpen"];
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendNotification:(NSDictionary *)userInfo
|
|
||||||
{
|
|
||||||
[sharedInstance sendEventWithName:@"onNotificationReceived" body:userInfo];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendUserActivity:(NSDictionary *)userInfo
|
- (void)sendUserActivity:(NSDictionary *)userInfo
|
||||||
|
Loading…
Reference in New Issue
Block a user