Skip to content

Commit 8151ffa

Browse files
Fix iOS sheet handling, clean up Navigation types (#6807)
* Add object type helpers * Clean up `Navigation.tsx`, simplify types * Make cool-modals work with react-navigation navigators (`onWillDismiss` was not being called) * Update `useRoute` usages * Align navigation types * Hook up charts prefetching * Improve `deepFreeze` types * Minor charts cleanup * Add missing `createBlankPicture` export * Update navigation ref setter, remove unnecessary wrapper object in `useApplicationSetup` * Fix remaining type errors * Ensure active route is updated when swiping between tabs * Fix merge conflicts * Enforce exact token types consistently * Remove unnecessary state spread * Fix navigation after wallet group creation * Use navigate instead of replace for wallet group navigation * Fix remaining navigation issues Removes the `replace` functionality from `navigate` as `replace` already exists as a standalone function * Fix `buildMenuItems` cache * Fix issue with the stack not being replace * Clean up conditional `replace` usage * Clean up conditional `replace` in `useImportingWallet` --------- Co-authored-by: EQuimper <[email protected]>
1 parent dc11ce9 commit 8151ffa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+761
-715
lines changed

β€Žsrc/App.tsxβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { designSystemPlaygroundEnabled, reactNativeDisableYellowBox, showNetwork
1717
import monitorNetwork from '@/debugging/network';
1818
import { Playground } from '@/design-system/playground/Playground';
1919
import RainbowContextWrapper from '@/helpers/RainbowContext';
20-
import { Navigation } from '@/navigation';
20+
import { setNavigationRef } from '@/navigation/Navigation';
2121
import { PersistQueryClientProvider, persistOptions, queryClient } from '@/react-query';
2222
import store from '@/redux/store';
2323
import { MainThemeProvider } from '@/theme/ThemeContext';
@@ -31,8 +31,6 @@ import { migrate } from '@/migrations';
3131
import { initializeReservoirClient } from '@/resources/reservoir/client';
3232
import { initializeRemoteConfig } from '@/model/remoteConfig';
3333
import { loadSettingsData } from '@/state/settings/loadSettingsData';
34-
import { NavigationContainerRef } from '@react-navigation/native';
35-
import { RootStackParamList } from '@/navigation/types';
3634
import { IS_DEV, IS_PROD, IS_TEST } from '@/env';
3735
import Routes from '@/navigation/Routes';
3836
import { BackupsSync } from '@/state/sync/BackupsSync';
@@ -57,11 +55,7 @@ const sx = StyleSheet.create({
5755
});
5856

5957
function AppComponent() {
60-
const { initialRoute } = useApplicationSetup();
61-
62-
const handleNavigatorRef = useCallback((ref: NavigationContainerRef<RootStackParamList>) => {
63-
Navigation.setTopLevelNavigator(ref);
64-
}, []);
58+
const initialRoute = useApplicationSetup();
6559

6660
const onNavigationReady = useCallback(() => {
6761
PerformanceTracking.logReportSegmentRelative(PerformanceReports.appStartup, PerformanceReportSegments.appStartup.mountNavigation);
@@ -76,7 +70,7 @@ function AppComponent() {
7670
<View style={sx.container}>
7771
{initialRoute && (
7872
<InitialRouteContext.Provider value={initialRoute}>
79-
<Routes onReady={onNavigationReady} ref={handleNavigatorRef} />
73+
<Routes onReady={onNavigationReady} ref={setNavigationRef} />
8074
</InitialRouteContext.Provider>
8175
)}
8276
<OfflineToast />

β€Žsrc/__swaps__/screens/Swap/navigateToSwaps.tsβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export type NavigateToSwapsParams<
3939
} & InputAmountRequest
4040
>;
4141

42-
export function navigateToSwaps(params: NavigateToSwapsParams = {}) {
42+
export function navigateToSwaps(params: NavigateToSwapsParams = {}): void {
4343
if (!enableActionsOnReadOnlyWallet && getIsReadOnlyWallet()) return watchingAlert();
4444

4545
const chainId = params.inputAsset?.chainId || params.outputAsset?.chainId || store.getState().settings.chainId;
@@ -101,8 +101,8 @@ export type SwapsParams = InputAmountsToSet & {
101101
};
102102

103103
export function getSwapsNavigationParams(): SwapsParams {
104-
let params = Navigation.getActiveRoute<typeof Routes.SWAP>()?.params;
105-
if (!params) params = getFallbackParams();
104+
const params = Navigation.getActiveRoute<typeof Routes.SWAP>()?.params;
105+
if (!params || !('inputAmount' in params)) return getFallbackParams();
106106
return params;
107107
}
108108

β€Žsrc/components/TestDeeplinkHandler.tsxβ€Ž

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ export function TestDeeplinkHandler() {
2626
name: query.name,
2727
userPin: '1111',
2828
});
29-
Navigation.handleAction(
30-
Routes.SWIPE_LAYOUT,
31-
{
32-
screen: Routes.WALLET_SCREEN,
33-
params: { initialized: true },
34-
},
35-
true
36-
);
29+
Navigation.replace(Routes.SWIPE_LAYOUT, {
30+
screen: Routes.WALLET_SCREEN,
31+
params: { initialized: true },
32+
});
3733
break;
3834
default:
3935
logger.debug(`[TestDeeplinkHandler]: unknown path`, { url });

β€Žsrc/components/asset-list/RecyclerAssetList2/core/RawRecyclerList.tsxβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { BaseCellType, CellTypes, RecyclerListViewRef } from './ViewTypes';
2323
import getLayoutProvider from './getLayoutProvider';
2424
import useLayoutItemAnimator from './useLayoutItemAnimator';
2525
import { useAccountAddress } from '../../../../state/wallets/walletsStore';
26-
import { NavigateFunction } from '@/navigation/Navigation';
2726

2827
const dimensions = {
2928
height: deviceUtils.dimensions.height,

β€Žsrc/components/asset-list/RecyclerAssetList2/index.tsxβ€Ž

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { useShowKingOfTheHill } from '@/components/king-of-the-hill/useShowKingO
2525

2626
export type AssetListType = 'wallet' | 'ens-profile' | 'select-nft';
2727

28+
type MenuItemRoute = typeof Routes.SETTINGS_SHEET | typeof Routes.RECEIVE_MODAL | typeof Routes.CONNECTED_DAPPS;
29+
2830
export interface RecyclerAssetList2Props {
2931
accentColor?: string;
3032
disablePullDownToRefresh?: boolean;
@@ -90,7 +92,7 @@ function handlePressQRScanner(): void {
9092
Navigation.handleAction(Routes.QR_SCANNER_SCREEN);
9193
}
9294

93-
function handlePressMenuItem(route: (typeof Routes)[keyof typeof Routes]): void {
95+
function handlePressMenuItem(route: MenuItemRoute): void {
9496
if (route === Routes.RECEIVE_MODAL) {
9597
analytics.track(analytics.event.navigationMyQrCode, { category: 'home screen' });
9698
}
@@ -103,32 +105,12 @@ function handleNavigateToActivity(): void {
103105

104106
const NavbarOverlay = React.memo(function NavbarOverlay({ accentColor, position }: { accentColor?: string; position: RNAnimated.Value }) {
105107
const { colors, isDarkMode } = useTheme();
106-
const { language } = useAccountSettings();
107108
const insets = useSafeAreaInsets();
108109
const showKingOfTheHillTab = useShowKingOfTheHill();
109110
const [isHeaderInteractive, setIsHeaderInteractive] = useState(false);
110111

111-
const menuItems = useMemo(
112-
() =>
113-
[
114-
{
115-
actionKey: Routes.SETTINGS_SHEET,
116-
actionTitle: i18n.t(i18n.l.settings.label),
117-
icon: { iconType: 'SYSTEM', iconValue: 'gear' },
118-
},
119-
{
120-
actionKey: Routes.RECEIVE_MODAL,
121-
actionTitle: i18n.t(i18n.l.button.my_qr_code),
122-
icon: { iconType: 'SYSTEM', iconValue: 'qrcode' },
123-
},
124-
{
125-
actionKey: Routes.CONNECTED_DAPPS,
126-
actionTitle: i18n.t(i18n.l.wallet.connected_apps),
127-
icon: { iconType: 'SYSTEM', iconValue: 'app.badge.checkmark' },
128-
},
129-
] as MenuItem<(typeof Routes)[keyof typeof Routes]>[],
130-
[language]
131-
);
112+
const { language } = useAccountSettings();
113+
const menuItems = buildMenuItems(language);
132114

133115
const yOffset = IS_ANDROID ? navbarHeight : insets.top;
134116

@@ -315,3 +297,31 @@ const ActivityIcon = memo(function ActivityIcon() {
315297
<Navbar.TextIcon color={accentColor as string} icon="􀐫" />
316298
);
317299
});
300+
301+
let cachedMenuItems: MenuItem<MenuItemRoute>[] | undefined;
302+
let lastLanguage: i18n.Language | undefined;
303+
304+
function buildMenuItems(language: i18n.Language): MenuItem<MenuItemRoute>[] {
305+
if (!cachedMenuItems || language !== lastLanguage) {
306+
cachedMenuItems = [
307+
{
308+
actionKey: Routes.SETTINGS_SHEET,
309+
actionTitle: i18n.t(i18n.l.settings.label),
310+
icon: { iconType: 'SYSTEM', iconValue: 'gear' },
311+
},
312+
{
313+
actionKey: Routes.RECEIVE_MODAL,
314+
actionTitle: i18n.t(i18n.l.button.my_qr_code),
315+
icon: { iconType: 'SYSTEM', iconValue: 'qrcode' },
316+
},
317+
{
318+
actionKey: Routes.CONNECTED_DAPPS,
319+
actionTitle: i18n.t(i18n.l.wallet.connected_apps),
320+
icon: { iconType: 'SYSTEM', iconValue: 'app.badge.checkmark' },
321+
},
322+
];
323+
lastLanguage = language;
324+
}
325+
326+
return cachedMenuItems;
327+
}

β€Žsrc/components/backup/RestoreCloudStep.tsxβ€Ž

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,9 @@ export default function RestoreCloudStep() {
156156
onRestoreSuccess();
157157
backupsStore.getState().setPassword('');
158158
if (isEmpty(prevWalletsState)) {
159-
Navigation.handleAction(
160-
Routes.SWIPE_LAYOUT,
161-
{
162-
screen: Routes.WALLET_SCREEN,
163-
},
164-
true
165-
);
159+
Navigation.handleAction(Routes.SWIPE_LAYOUT, {
160+
screen: Routes.WALLET_SCREEN,
161+
});
166162
} else {
167163
Navigation.handleAction(Routes.WALLET_SCREEN);
168164
}

β€Žsrc/components/ens-profile/ActionButtons/EditButton.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useNavigation } from '@react-navigation/native';
21
import * as i18n from '@/languages';
32
import React, { useCallback } from 'react';
43
import ActionButton from './ActionButton';
54
import { REGISTRATION_MODES } from '@/helpers/ens';
65
import { useENSRegistration } from '@/hooks';
6+
import { useNavigation } from '@/navigation/Navigation';
77
import Routes from '@/navigation/routesNames';
88

99
export default function WatchButton({ ensName }: { ensName?: string }) {

β€Žsrc/components/ens-profile/ActionButtons/SendButton.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback } from 'react';
22
import ActionButton from './ActionButton';
3-
import { useNavigation } from '@react-navigation/native';
3+
import { useNavigation } from '@/navigation/Navigation';
44
import Routes from '@/navigation/routesNames';
55
import { IS_IOS } from '@/env';
66

β€Žsrc/components/ens-profile/RecordHyperlink/RecordHyperlink.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useNavigation } from '@react-navigation/native';
1+
import { useNavigation } from '@/navigation/Navigation';
22
import React, { useCallback } from 'react';
33
import ButtonPressAnimation from '../../animations/ButtonPressAnimation';
44
import { Text } from '@/design-system';

β€Žsrc/components/expanded-state/ens/ConfigurationSection.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useNavigation } from '@react-navigation/native';
1+
import { useNavigation } from '@/navigation/Navigation';
22
import * as i18n from '@/languages';
33
import React from 'react';
44
import { ENSConfirmUpdateSheetHeight } from '../../../screens/ENSConfirmRegisterSheet';

0 commit comments

Comments
Β (0)