From 0a5897b5feddc8c72c5bf1db805643878d5e639d Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Mon, 29 Apr 2024 18:54:19 -0400 Subject: [PATCH 1/2] FIX: DeviceQuickActions getEnabled --- App.js | 22 +++---- components/Context/SettingsContext.tsx | 8 +-- .../DeviceQuickActions.tsx | 65 ++++++++++--------- .../DeviceQuickActions.windows.tsx | 14 ++-- components/TransactionsNavigationHeader.tsx | 3 +- 5 files changed, 56 insertions(+), 56 deletions(-) rename class/quick-actions.tsx => components/DeviceQuickActions.tsx (83%) rename class/quick-actions.windows.tsx => components/DeviceQuickActions.windows.tsx (68%) diff --git a/App.js b/App.js index 1389fb6d6..9c5d01506 100644 --- a/App.js +++ b/App.js @@ -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 ( - - - - + + + + - - - - - - + + + + + + ); }; diff --git a/components/Context/SettingsContext.tsx b/components/Context/SettingsContext.tsx index 143cb218f..bd2788d37 100644 --- a/components/Context/SettingsContext.tsx +++ b/components/Context/SettingsContext.tsx @@ -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); }, []); diff --git a/class/quick-actions.tsx b/components/DeviceQuickActions.tsx similarity index 83% rename from class/quick-actions.tsx rename to components/DeviceQuickActions.tsx index f6222d14d..e5f3262a4 100644 --- a/class/quick-actions.tsx +++ b/components/DeviceQuickActions.tsx @@ -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,34 @@ 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 { + await AsyncStorage.setItem(DeviceQuickActionsStorageKey, JSON.stringify(enabled)); +} + +export async function getEnabled(): Promise { + console.warn('getEnabled22'); + 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 +61,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 => { - 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 => { const data = await QuickActions.popInitialAction(); return data; }; - // @ts-ignore: Fix later - DeviceQuickActions.getEnabled = async (): Promise => { - 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 => { if (data) { const wallet = wallets.find((w: { getID: () => any }) => w.getID() === data.userInfo.url.split('wallet/')[1]); @@ -147,8 +151,7 @@ function DeviceQuickActions(): JSX.Element | null { }; const setQuickActions = async (): Promise => { - // @ts-ignore: Fix later - if (await DeviceQuickActions.getEnabled()) { + if (await getEnabled()) { QuickActions.isSupported((error: null, _supported: any) => { if (error === null) { const shortcutItems = []; @@ -175,7 +178,7 @@ function DeviceQuickActions(): JSX.Element | null { } }; - return <>; + return null; } export default DeviceQuickActions; diff --git a/class/quick-actions.windows.tsx b/components/DeviceQuickActions.windows.tsx similarity index 68% rename from class/quick-actions.windows.tsx rename to components/DeviceQuickActions.windows.tsx index 85343a011..1c5057bac 100644 --- a/class/quick-actions.windows.tsx +++ b/components/DeviceQuickActions.windows.tsx @@ -3,21 +3,19 @@ import React from 'react'; export const DeviceQuickActionsStorageKey = 'DeviceQuickActionsEnabled'; interface DeviceQuickActionsFunctions { - setEnabled: () => void; - getEnabled: () => Promise; popInitialAction: () => void; } +export const setEnabled = (): void => {}; + +export const getEnabled = async (): Promise => { + return false; +}; + const DeviceQuickActions: React.FC & DeviceQuickActionsFunctions = () => { return null; }; -DeviceQuickActions.setEnabled = (): void => {}; - -DeviceQuickActions.getEnabled = async (): Promise => { - return false; -}; - DeviceQuickActions.popInitialAction = (): void => {}; export default DeviceQuickActions; diff --git a/components/TransactionsNavigationHeader.tsx b/components/TransactionsNavigationHeader.tsx index 2d69e0e3e..b7ca91ecb 100644 --- a/components/TransactionsNavigationHeader.tsx +++ b/components/TransactionsNavigationHeader.tsx @@ -107,7 +107,8 @@ const TransactionsNavigationHeader: React.FC if (onManageFundsPressed) { if (actionKeyID) { onManageFundsPressed(actionKeyID); - }} + } + } }; const handleOnPaymentCodeButtonPressed = () => { From 9a27a2ab7d3abc041ed610af0cd4f801bb9a23c4 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Mon, 29 Apr 2024 19:12:08 -0400 Subject: [PATCH 2/2] Update DeviceQuickActions.tsx --- components/DeviceQuickActions.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/components/DeviceQuickActions.tsx b/components/DeviceQuickActions.tsx index e5f3262a4..471407867 100644 --- a/components/DeviceQuickActions.tsx +++ b/components/DeviceQuickActions.tsx @@ -18,7 +18,6 @@ export async function setEnabled(enabled: boolean = true): Promise { } export async function getEnabled(): Promise { - console.warn('getEnabled22'); try { const isEnabled = await AsyncStorage.getItem(DeviceQuickActionsStorageKey); if (isEnabled === null) {