Merge pull request #6495 from BlueWallet/quicka

FIX: DeviceQuickActions getEnabled
This commit is contained in:
GLaDOS 2024-04-30 02:01:23 +00:00 committed by GitHub
commit 58620f98e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 55 additions and 56 deletions

22
App.js
View File

@ -24,7 +24,6 @@ import InitRoot from './Navigation';
import BlueClipboard from './blue_modules/clipboard';
import { BlueStorageContext } from './blue_modules/storage-context';
import WatchConnectivity from './WatchConnectivity';
import DeviceQuickActions from './class/quick-actions';
import Notifications from './blue_modules/notifications';
import Biometric from './class/biometrics';
import WidgetCommunication from './components/WidgetCommunication';
@ -35,6 +34,7 @@ import { updateExchangeRate } from './blue_modules/currency';
import { NavigationProvider } from './components/NavigationProvider';
import A from './blue_modules/analytics';
import HandOffComponentListener from './components/HandOffComponentListener';
import DeviceQuickActions from './components/DeviceQuickActions';
const eventEmitter = Platform.OS === 'ios' ? new NativeEventEmitter(NativeModules.EventEmitter) : undefined;
const { SplashScreen } = NativeModules;
@ -266,22 +266,22 @@ const App = () => {
}, []);
return (
<SafeAreaProvider>
<View style={styles.root}>
<NavigationContainer ref={navigationRef} theme={colorScheme === 'dark' ? BlueDarkTheme : BlueDefaultTheme}>
<NavigationProvider>
<NavigationContainer ref={navigationRef} theme={colorScheme === 'dark' ? BlueDarkTheme : BlueDefaultTheme}>
<NavigationProvider>
<SafeAreaProvider>
<View style={styles.root}>
<InitRoot />
<Notifications onProcessNotifications={processPushNotifications} />
<MenuElements />
<DeviceQuickActions />
<Biometric />
<HandOffComponentListener />
</NavigationProvider>
</NavigationContainer>
</View>
<WatchConnectivity />
<WidgetCommunication />
</SafeAreaProvider>
</View>
<WatchConnectivity />
<WidgetCommunication />
</SafeAreaProvider>
</NavigationProvider>
</NavigationContainer>
);
};

View File

@ -10,7 +10,7 @@ import { isBalanceDisplayAllowed, setBalanceDisplayAllowed } from '../WidgetComm
import { clearUseURv1, isURv1Enabled, setUseURv1 } from '../../blue_modules/ur';
import BlueClipboard from '../../blue_modules/clipboard';
import { getIsHandOffUseEnabled, setIsHandOffUseEnabled } from '../HandOffComponent';
import DeviceQuickActions from '../../class/quick-actions';
import { getEnabled as getIsDeviceQuickActionsEnabled, setEnabled as setIsDeviceQuickActionsEnabled } from '..//DeviceQuickActions';
interface SettingsContextType {
preferredFiatCurrency: TFiatUnit;
@ -111,8 +111,7 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
console.debug('SettingsContext isClipboardGetContentEnabled:', isClipboardGetContentEnabledStorage);
setIsClipboardGetContentEnabledStorage(isClipboardGetContentEnabledStorage);
// @ts-ignore: Fix later
const isQuickActionsEnabledStorage = await DeviceQuickActions.getEnabled();
const isQuickActionsEnabledStorage = await getIsDeviceQuickActionsEnabled();
console.debug('SettingsContext isQuickActionsEnabled:', isQuickActionsEnabledStorage);
setIsQuickActionsEnabledStorage(isQuickActionsEnabledStorage);
};
@ -180,8 +179,7 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
}, []);
const setIsQuickActionsEnabledStorage = useCallback(async (value: boolean) => {
// @ts-ignore: Fix later
await DeviceQuickActions.setEnabled(value);
await setIsDeviceQuickActionsEnabled(value);
setIsQuickActionsEnabled(value);
}, []);

View File

@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react';
import { useContext, useEffect } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { CommonActions } from '@react-navigation/native';
import { DeviceEventEmitter, Linking, Platform } from 'react-native';
@ -6,16 +6,33 @@ import QuickActions from 'react-native-quick-actions';
import * as NavigationService from '../NavigationService';
import { BlueStorageContext } from '../blue_modules/storage-context';
import { formatBalance } from '../loc';
import DeeplinkSchemaMatch from './deeplink-schema-match';
import { TWallet } from './wallets/types';
import DeeplinkSchemaMatch from '../class/deeplink-schema-match';
import { TWallet } from '../class/wallets/types';
import useOnAppLaunch from '../hooks/useOnAppLaunch';
import { useSettings } from '../components/Context/SettingsContext';
const DeviceQuickActionsStorageKey = 'DeviceQuickActionsEnabled';
function DeviceQuickActions(): JSX.Element | null {
export async function setEnabled(enabled: boolean = true): Promise<void> {
await AsyncStorage.setItem(DeviceQuickActionsStorageKey, JSON.stringify(enabled));
}
export async function getEnabled(): Promise<boolean> {
try {
const isEnabled = await AsyncStorage.getItem(DeviceQuickActionsStorageKey);
if (isEnabled === null) {
await setEnabled(true);
return true;
}
return !!JSON.parse(isEnabled);
} catch {
return true;
}
}
function DeviceQuickActions() {
const { wallets, walletsInitialized, isStorageEncrypted, addWallet, saveToDisk, setSharedCosigner } = useContext(BlueStorageContext);
const { preferredFiatCurrency } = useSettings();
const { preferredFiatCurrency, isQuickActionsEnabled } = useSettings();
const { isViewAllWalletsEnabled, getSelectedDefaultWallet } = useOnAppLaunch();
@ -43,36 +60,22 @@ function DeviceQuickActions(): JSX.Element | null {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletsInitialized]);
// @ts-ignore: Fix later
DeviceQuickActions.setEnabled = async (enabled: boolean = true): Promise<void> => {
await AsyncStorage.setItem(DeviceQuickActionsStorageKey, JSON.stringify(enabled));
if (!enabled) {
removeShortcuts();
} else {
setQuickActions();
useEffect(() => {
if (walletsInitialized) {
if (isQuickActionsEnabled) {
setQuickActions();
} else {
removeShortcuts();
}
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isQuickActionsEnabled, walletsInitialized]);
const popInitialShortcutAction = async (): Promise<any> => {
const data = await QuickActions.popInitialAction();
return data;
};
// @ts-ignore: Fix later
DeviceQuickActions.getEnabled = async (): Promise<boolean> => {
try {
const isEnabled = await AsyncStorage.getItem(DeviceQuickActionsStorageKey);
if (isEnabled === null) {
// @ts-ignore: Fix later
await DeviceQuickActions.setEnabled(true);
return true;
}
return !!JSON.parse(isEnabled);
} catch {
return true;
}
};
const popInitialAction = async (data: any): Promise<void> => {
if (data) {
const wallet = wallets.find((w: { getID: () => any }) => w.getID() === data.userInfo.url.split('wallet/')[1]);
@ -147,8 +150,7 @@ function DeviceQuickActions(): JSX.Element | null {
};
const setQuickActions = async (): Promise<void> => {
// @ts-ignore: Fix later
if (await DeviceQuickActions.getEnabled()) {
if (await getEnabled()) {
QuickActions.isSupported((error: null, _supported: any) => {
if (error === null) {
const shortcutItems = [];
@ -175,7 +177,7 @@ function DeviceQuickActions(): JSX.Element | null {
}
};
return <></>;
return null;
}
export default DeviceQuickActions;

View File

@ -3,21 +3,19 @@ import React from 'react';
export const DeviceQuickActionsStorageKey = 'DeviceQuickActionsEnabled';
interface DeviceQuickActionsFunctions {
setEnabled: () => void;
getEnabled: () => Promise<boolean>;
popInitialAction: () => void;
}
export const setEnabled = (): void => {};
export const getEnabled = async (): Promise<boolean> => {
return false;
};
const DeviceQuickActions: React.FC & DeviceQuickActionsFunctions = () => {
return null;
};
DeviceQuickActions.setEnabled = (): void => {};
DeviceQuickActions.getEnabled = async (): Promise<boolean> => {
return false;
};
DeviceQuickActions.popInitialAction = (): void => {};
export default DeviceQuickActions;

View File

@ -107,7 +107,8 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
if (onManageFundsPressed) {
if (actionKeyID) {
onManageFundsPressed(actionKeyID);
}}
}
}
};
const handleOnPaymentCodeButtonPressed = () => {