FIx: onapp launch was not working

navigation changes broke it
This commit is contained in:
Marcos Rodriguez 2025-05-12 23:14:28 -04:00
parent daac0d6034
commit ae2dc78827
5 changed files with 19 additions and 36 deletions

View File

@ -27,7 +27,7 @@ import useWatchConnectivity from './useWatchConnectivity';
import useDeviceQuickActions from './useDeviceQuickActions';
import useHandoffListener from './useHandoffListener';
import useMenuElements from './useMenuElements';
import { useExtendedNavigation } from './useExtendedNavigation';
const ClipboardContentType = Object.freeze({
BITCOIN: 'BITCOIN',
@ -49,6 +49,7 @@ const useCompanionListeners = (skipIfNotInitialized = true) => {
} = useStorage();
const appState = useRef<AppStateStatus>(AppState.currentState);
const clipboardContent = useRef<undefined | string>();
const navigation = useExtendedNavigation();
// We need to call hooks unconditionally before any conditional logic
// We'll use this check inside the effects to conditionally run logic
@ -102,28 +103,15 @@ const useCompanionListeners = (skipIfNotInitialized = true) => {
fetchAndSaveWalletTransactions(walletID);
if (wasTapped) {
if (payload.type !== 3 || wallet.chain === Chain.OFFCHAIN) {
navigationRef.dispatch(
CommonActions.navigate({
name: 'WalletTransactions',
params: {
walletID,
walletType: wallet.type,
},
}),
);
navigation.navigate('WalletTransactions', {
walletID,
walletType: wallet.type,
});
} else {
navigationRef.dispatch(
CommonActions.navigate({
name: 'ReceiveDetails',
params: {
walletID,
address: payload.address,
},
}),
);
navigation.navigate('ReceiveDetails', {
walletID,
address: payload.address,
});
}
return true;
@ -191,7 +179,7 @@ const useCompanionListeners = (skipIfNotInitialized = true) => {
console.error('Failed to process push notifications:', error);
}
return false;
}, [fetchAndSaveWalletTransactions, refreshAllWalletTransactions, wallets, shouldActivateListeners]);
}, [shouldActivateListeners, wallets, fetchAndSaveWalletTransactions, navigation, refreshAllWalletTransactions]);
useEffect(() => {
if (!shouldActivateListeners) return;

View File

@ -10,7 +10,8 @@ const useOnAppLaunch = () => {
const getSelectedDefaultWallet = useCallback(async (): Promise<string | undefined> => {
let selectedWallet: TWallet | undefined;
try {
const selectedWalletID = JSON.parse((await AsyncStorage.getItem(STORAGE_KEY)) || 'null');
const selectedWalletID = await AsyncStorage.getItem(STORAGE_KEY);
console.log('Selected wallet ID:', selectedWalletID);
if (selectedWalletID !== null) {
selectedWallet = wallets.find((wallet: TWallet) => wallet.getID() === selectedWalletID);
if (!selectedWallet) {
@ -24,12 +25,11 @@ const useOnAppLaunch = () => {
return undefined;
}
return selectedWallet.getID();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [STORAGE_KEY]);
}, [STORAGE_KEY, wallets]);
const setSelectedDefaultWallet = useCallback(
async (value: string): Promise<void> => {
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(value));
await AsyncStorage.setItem(STORAGE_KEY, value);
},
[STORAGE_KEY],
); // No external dependencies
@ -55,8 +55,7 @@ const useOnAppLaunch = () => {
await AsyncStorage.setItem(STORAGE_KEY, '');
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[STORAGE_KEY, getSelectedDefaultWallet, setSelectedDefaultWallet],
[STORAGE_KEY, getSelectedDefaultWallet, setSelectedDefaultWallet, wallets],
);
return {

View File

@ -5,6 +5,7 @@ import { useSizeClass, SizeClass } from '../blue_modules/sizeClass';
import DrawerList from '../screen/wallets/DrawerList';
import DetailViewStackScreensStack from './DetailViewScreensStack';
import { DrawerParamList } from './DrawerParamList';
import useCompanionListeners from '../hooks/useCompanionListeners';
const Drawer = createDrawerNavigator<DrawerParamList>();
@ -33,6 +34,7 @@ const getAnimationConfig = (isDrawerTransitionConfigured: boolean) => {
const DrawerRoot = () => {
const { sizeClass, isLargeScreen } = useSizeClass();
useCompanionListeners();
const getDrawerWidth = useMemo(() => {
switch (sizeClass) {

View File

@ -1,13 +1,8 @@
import React from 'react';
import DevMenu from '../components/DevMenu';
import MainRoot from './index';
import useCompanionListeners from '../hooks/useCompanionListeners';
const MasterView = () => {
// Initialize companion listeners only when wallets are initialized
// The hook checks walletsInitialized internally, so it won't run until ready
useCompanionListeners();
return (
<>
<MainRoot />

View File

@ -61,8 +61,7 @@ const DefaultView: React.FC = () => {
dispatch({ type: ActionType.SetDefaultWalletLabel, payload: newDefaultWalletLabel });
dispatch({ type: ActionType.SetViewAllWalletsSwitch, payload: newViewAllWalletsEnabled });
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [wallets, getSelectedDefaultWallet, isViewAllWalletsEnabled]);
const onViewAllWalletsSwitchValueChanged = async (value: boolean) => {
await setViewAllWalletsEnabled(value);