BlueWallet/components/HandOffComponent.ios.tsx
2024-04-24 21:32:37 -04:00

58 lines
1.9 KiB
TypeScript

import React from 'react';
// @ts-ignore: react-native-handoff is not in the type definition
import Handoff from 'react-native-handoff';
import { useSettings } from './Context/SettingsContext';
import DefaultPreference from 'react-native-default-preference';
import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency';
import { BlueApp } from '../class';
interface HandOffComponentProps {
url?: string;
title?: string;
type: (typeof HandOffComponent.activityTypes)[keyof typeof HandOffComponent.activityTypes];
userInfo?: object;
}
interface HandOffComponentWithActivityTypes extends React.FC<HandOffComponentProps> {
activityTypes: {
ReceiveOnchain: string;
Xpub: string;
ViewInBlockExplorer: string;
};
}
export const setIsHandOffUseEnabled = async (value: boolean) => {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
await DefaultPreference.set(BlueApp.HANDOFF_STORAGE_KEY, value.toString());
console.log('setIsHandOffUseEnabledAsyncStorage', value);
};
export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
const isEnabledValue = await DefaultPreference.get(BlueApp.HANDOFF_STORAGE_KEY);
console.log('getIsHandOffUseEnabledV', isEnabledValue);
return isEnabledValue === 'true';
};
const HandOffComponent: HandOffComponentWithActivityTypes = props => {
const { isHandOffUseEnabled } = useSettings();
if (process.env.NODE_ENV === 'development') {
console.log('HandOffComponent: props', props);
}
if (isHandOffUseEnabled) {
return <Handoff {...props} />;
}
return null;
};
const activityTypes = {
ReceiveOnchain: 'io.bluewallet.bluewallet.receiveonchain',
Xpub: 'io.bluewallet.bluewallet.xpub',
ViewInBlockExplorer: 'io.bluewallet.bluewallet.blockexplorer',
};
HandOffComponent.activityTypes = activityTypes;
export default HandOffComponent;