mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 11:09:20 +01:00
Merge pull request #7555 from BlueWallet/hofffix
FIX: Handoff type wasnt being passed
This commit is contained in:
commit
632500b734
4 changed files with 46 additions and 13 deletions
|
@ -9,7 +9,12 @@ import { HandOffComponentProps } from './types';
|
|||
|
||||
const HandOffComponent: React.FC<HandOffComponentProps> = props => {
|
||||
const { isHandOffUseEnabled } = useSettings();
|
||||
console.debug('HandOffComponent is rendering.');
|
||||
if (!props || !props.type || !props.userInfo || Object.keys(props.userInfo).length === 0) {
|
||||
console.debug('HandOffComponent: Missing required type or userInfo data');
|
||||
return null;
|
||||
}
|
||||
const userInfo = JSON.stringify(props.userInfo);
|
||||
console.debug(`HandOffComponent is rendering. Type: ${props.type}, UserInfo: ${userInfo}...`);
|
||||
return isHandOffUseEnabled ? <Handoff {...props} /> : null;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,20 +23,25 @@ const useHandoffListener = () => {
|
|||
|
||||
const handleUserActivity = useCallback(
|
||||
(data: UserActivityData) => {
|
||||
if (!data || !data.activityType) {
|
||||
console.debug(`Invalid handoff data received: ${data ? JSON.stringify(data) : 'No data provided'}`);
|
||||
return;
|
||||
}
|
||||
const { activityType, userInfo } = data;
|
||||
const modifiedUserInfo = { ...(userInfo || {}), type: activityType };
|
||||
try {
|
||||
if (activityType === HandOffActivityType.ReceiveOnchain) {
|
||||
if (activityType === HandOffActivityType.ReceiveOnchain && modifiedUserInfo.address) {
|
||||
navigate('ReceiveDetailsRoot', {
|
||||
screen: 'ReceiveDetails',
|
||||
params: { address: userInfo.address },
|
||||
params: { address: modifiedUserInfo.address, type: activityType },
|
||||
});
|
||||
} else if (activityType === HandOffActivityType.Xpub) {
|
||||
} else if (activityType === HandOffActivityType.Xpub && modifiedUserInfo.xpub) {
|
||||
navigate('WalletXpubRoot', {
|
||||
screen: 'WalletXpub',
|
||||
params: { xpub: userInfo.xpub },
|
||||
params: { xpub: modifiedUserInfo.xpub, type: activityType },
|
||||
});
|
||||
} else {
|
||||
console.debug(`Unhandled activity type: ${activityType}`);
|
||||
console.debug(`Unhandled or incomplete activity type/data: ${activityType}`, modifiedUserInfo);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error handling user activity:', error);
|
||||
|
@ -52,7 +57,7 @@ const useHandoffListener = () => {
|
|||
|
||||
EventEmitter.getMostRecentUserActivity?.()
|
||||
.then(handleUserActivity)
|
||||
.catch(() => console.debug('No userActivity object sent'));
|
||||
.catch(() => console.debug('No valid user activity object received'));
|
||||
|
||||
return () => {
|
||||
activitySubscription?.remove();
|
||||
|
|
|
@ -154,27 +154,42 @@
|
|||
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
|
||||
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
|
||||
{
|
||||
NSDictionary *userActivityData = @{@"activityType": userActivity.activityType, @"userInfo": userActivity.userInfo};
|
||||
// Validate userActivity and its type
|
||||
if (!userActivity || !userActivity.activityType) {
|
||||
NSLog(@"[Handoff] Invalid or missing userActivity");
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSDictionary *userActivityData = @{@"activityType": userActivity.activityType ?: @"",
|
||||
@"userInfo": userActivity.userInfo ?: @{}};
|
||||
|
||||
// Save activity data to userDefaults for potential later use
|
||||
[self.userDefaultsGroup setValue:userActivityData forKey:@"onUserActivityOpen"];
|
||||
|
||||
// Check if the activity type matches the allowed types
|
||||
// Check if the activity type matches one of the allowed types
|
||||
if ([userActivity.activityType isEqualToString:@"io.bluewallet.bluewallet.receiveonchain"] ||
|
||||
[userActivity.activityType isEqualToString:@"io.bluewallet.bluewallet.xpub"] ||
|
||||
[userActivity.activityType isEqualToString:@"io.bluewallet.bluewallet.blockexplorer"]) {
|
||||
|
||||
[EventEmitter.sharedInstance sendUserActivity:userActivityData];
|
||||
if ([EventEmitter.sharedInstance respondsToSelector:@selector(sendUserActivity:)]) {
|
||||
[EventEmitter.sharedInstance sendUserActivity:userActivityData];
|
||||
} else {
|
||||
NSLog(@"[Handoff] EventEmitter does not implement sendUserActivity:");
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (userActivity.activityType == NSUserActivityTypeBrowsingWeb) {
|
||||
// Forward web browsing activities to LinkingManager
|
||||
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||
return [RCTLinkingManager application:application
|
||||
continueUserActivity:userActivity
|
||||
restorationHandler:restorationHandler];
|
||||
}
|
||||
|
||||
// If activity type does not match any of the specified types, do nothing
|
||||
NSLog(@"[Handoff] Unhandled user activity type: %@", userActivity.activityType);
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
||||
return [RCTLinkingManager application:app openURL:url options:options];
|
||||
}
|
||||
|
|
|
@ -41,7 +41,15 @@ RCT_EXPORT_MODULE();
|
|||
|
||||
- (void)sendUserActivity:(NSDictionary *)userInfo
|
||||
{
|
||||
[self sendEventWithName:@"onUserActivityOpen" body:userInfo];
|
||||
if (![userInfo isKindOfClass:[NSDictionary class]]) {
|
||||
NSLog(@"[EventEmitter] Invalid user activity data: %@", userInfo);
|
||||
return;
|
||||
}
|
||||
@try {
|
||||
[self sendEventWithName:@"onUserActivityOpen" body:userInfo];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"[EventEmitter] Exception while sending event: %@", exception);
|
||||
}
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getMostRecentUserActivity:(RCTPromiseResolveBlock)resolve
|
||||
|
|
Loading…
Add table
Reference in a new issue