Some checks are pending
Build Release and Upload to TestFlight (iOS) / build (push) Waiting to run
Build Release and Upload to TestFlight (iOS) / testflight-upload (push) Blocked by required conditions
BuildReleaseApk / buildReleaseApk (push) Waiting to run
BuildReleaseApk / browserstack (push) Blocked by required conditions
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import React from 'react';
|
|
import DefaultPreference from 'react-native-default-preference';
|
|
// @ts-ignore: Handoff is not typed
|
|
import Handoff from 'react-native-handoff';
|
|
import { useSettings } from '../hooks/context/useSettings';
|
|
import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency';
|
|
import { BlueApp } from '../class/blue-app';
|
|
import { HandOffComponentProps } from './types';
|
|
|
|
const HandOffComponent: React.FC<HandOffComponentProps> = props => {
|
|
const { isHandOffUseEnabled } = useSettings();
|
|
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;
|
|
};
|
|
|
|
const MemoizedHandOffComponent = React.memo(HandOffComponent);
|
|
|
|
export const setIsHandOffUseEnabled = async (value: boolean) => {
|
|
try {
|
|
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
|
|
await DefaultPreference.set(BlueApp.HANDOFF_STORAGE_KEY, value.toString());
|
|
console.debug('setIsHandOffUseEnabled', value);
|
|
} catch (error) {
|
|
console.error('Error setting handoff enabled status:', error);
|
|
throw error; // Propagate error to caller
|
|
}
|
|
};
|
|
|
|
export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
|
|
try {
|
|
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
|
|
const isEnabledValue = await DefaultPreference.get(BlueApp.HANDOFF_STORAGE_KEY);
|
|
const result = isEnabledValue === 'true';
|
|
console.debug('getIsHandOffUseEnabled', result);
|
|
return result;
|
|
} catch (error) {
|
|
console.error('Error getting handoff enabled status:', error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
export default MemoizedHandOffComponent;
|