BlueWallet/components/HandOffComponent.ios.tsx

43 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-17 21:05:48 -04:00
import React from 'react';
2024-05-20 10:54:13 +01:00
import DefaultPreference from 'react-native-default-preference';
2024-11-14 20:42:56 -04:00
// @ts-ignore: Handoff is not typed
import Handoff from 'react-native-handoff';
2024-06-04 15:02:12 -04:00
import { useSettings } from '../hooks/context/useSettings';
import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency';
import { BlueApp } from '../class';
2024-06-04 15:02:12 -04:00
import { HandOffComponentProps } from './types';
2024-06-04 15:02:12 -04:00
const HandOffComponent: React.FC<HandOffComponentProps> = props => {
const { isHandOffUseEnabled } = useSettings();
2024-11-14 20:42:56 -04:00
console.debug('HandOffComponent is rendering.');
return isHandOffUseEnabled ? <Handoff {...props} /> : null;
2024-06-04 15:02:12 -04:00
};
const MemoizedHandOffComponent = React.memo(HandOffComponent);
export const setIsHandOffUseEnabled = async (value: boolean) => {
2024-11-14 20:42:56 -04:00
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
2024-11-14 20:42:56 -04:00
}
};
export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
2024-05-21 17:57:09 -04:00
try {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
2024-11-14 20:42:56 -04:00
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);
2024-10-31 22:25:47 -04:00
return false;
2024-05-21 17:57:09 -04:00
}
};
2024-06-04 15:02:12 -04:00
export default MemoizedHandOffComponent;