Skip to content

Commit

Permalink
Backups V2 Follow-up Fixes / Improvements (#6213)
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat authored Dec 20, 2024
1 parent d90e32a commit 572edec
Show file tree
Hide file tree
Showing 63 changed files with 2,152 additions and 2,517 deletions.
32 changes: 21 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@/languages';
import * as Sentry from '@sentry/react-native';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState, memo } from 'react';
import { AppRegistry, Dimensions, LogBox, StyleSheet, View } from 'react-native';
import { Toaster } from 'sonner-native';
import { MobileWalletProtocolProvider } from '@coinbase/mobile-wallet-protocol-host';
Expand All @@ -9,9 +9,8 @@ import { useApplicationSetup } from '@/hooks/useApplicationSetup';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
import { enableScreens } from 'react-native-screens';
import { connect, Provider as ReduxProvider } from 'react-redux';
import { connect, Provider as ReduxProvider, shallowEqual } from 'react-redux';
import { RecoilRoot } from 'recoil';
import PortalConsumer from '@/components/PortalConsumer';
import ErrorBoundary from '@/components/error-boundary/ErrorBoundary';
import { OfflineToast } from '@/components/toasts';
import { designSystemPlaygroundEnabled, reactNativeDisableYellowBox, showNetworkRequests, showNetworkResponses } from '@/config/debug';
Expand All @@ -24,7 +23,6 @@ import store, { AppDispatch, type AppState } from '@/redux/store';
import { MainThemeProvider } from '@/theme/ThemeContext';
import { SharedValuesProvider } from '@/helpers/SharedValuesContext';
import { InitialRouteContext } from '@/navigation/initialRoute';
import { Portal } from '@/react-native-cool-modals/Portal';
import { NotificationsHandler } from '@/notifications/NotificationsHandler';
import { analyticsV2 } from '@/analytics';
import { getOrCreateDeviceId } from '@/analytics/utils';
Expand All @@ -39,6 +37,7 @@ import { RootStackParamList } from '@/navigation/types';
import { IS_ANDROID, IS_DEV } from '@/env';
import { prefetchDefaultFavorites } from '@/resources/favorites';
import Routes from '@/navigation/Routes';
import { BackupsSync } from '@/state/sync/BackupsSync';
import { BackendNetworks } from '@/components/BackendNetworks';
import { AbsolutePortalRoot } from './components/AbsolutePortal';

Expand Down Expand Up @@ -68,28 +67,39 @@ function App({ walletReady }: AppProps) {
}, []);

return (
<Portal>
<>
<View style={[sx.container, { paddingBottom: IS_ANDROID ? bottom : 0 }]}>
{initialRoute && (
<InitialRouteContext.Provider value={initialRoute}>
<Routes ref={handleNavigatorRef} />
<PortalConsumer />
<AbsolutePortalRoot />
</InitialRouteContext.Provider>
)}
<OfflineToast />
<Toaster />
</View>
<NotificationsHandler walletReady={walletReady} />
<DeeplinkHandler initialRoute={initialRoute} walletReady={walletReady} />
<BackupsSync />
<BackendNetworks />
</Portal>
<AbsolutePortalRoot />
</>
);
}

const AppWithRedux = connect<AppProps, AppDispatch, AppProps, AppState>(state => ({
walletReady: state.appState.walletReady,
}))(App);
const AppWithRedux = connect<AppProps, AppDispatch, AppProps, AppState>(
state => ({
walletReady: state.appState.walletReady,
}),
null,
null,
{
areStatesEqual: (next, prev) => {
// Only update if walletReady actually changed
return next.appState.walletReady === prev.appState.walletReady;
},
areOwnPropsEqual: shallowEqual,
}
)(memo(App));

function Root() {
const [initializing, setInitializing] = useState(true);
Expand Down
6 changes: 3 additions & 3 deletions src/components/AbsolutePortal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PropsWithChildren, ReactNode, useEffect, useState } from 'react';
import { View } from 'react-native';
import { StyleProp, ViewStyle, View } from 'react-native';

const absolutePortal = {
nodes: [] as ReactNode[],
Expand All @@ -24,15 +24,15 @@ const absolutePortal = {
},
};

export const AbsolutePortalRoot = () => {
export const AbsolutePortalRoot = ({ style }: { style?: StyleProp<ViewStyle> }) => {
const [nodes, setNodes] = useState(absolutePortal.nodes);

useEffect(() => {
const unsubscribe = absolutePortal.subscribe(setNodes);
return () => unsubscribe();
}, []);

return <View style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, pointerEvents: 'box-none' }}>{nodes}</View>;
return <View style={[style, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, pointerEvents: 'box-none' }]}>{nodes}</View>;
};

export const AbsolutePortal = ({ children }: PropsWithChildren) => {
Expand Down
5 changes: 1 addition & 4 deletions src/components/ExchangeTokenRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import isEqual from 'react-fast-compare';
import { Box, Column, Columns, Inline, Stack, Text } from '@/design-system';
import { isNativeAsset } from '@/handlers/assets';
import { useAsset, useDimensions } from '@/hooks';
import { useAsset } from '@/hooks';
import { ButtonPressAnimation } from '@/components/animations';
import { FloatingEmojis } from '@/components/floating-emojis';
import { IS_IOS } from '@/env';
Expand Down Expand Up @@ -34,7 +34,6 @@ export default React.memo(function ExchangeTokenRow({
disabled,
},
}: ExchangeTokenRowProps) {
const { width: deviceWidth } = useDimensions();
const item = useAsset({
address,
chainId,
Expand Down Expand Up @@ -101,10 +100,8 @@ export default React.memo(function ExchangeTokenRow({
{isInfoButtonVisible && <Info contextMenuProps={contextMenuProps} showFavoriteButton={showFavoriteButton} theme={theme} />}
{showFavoriteButton &&
(IS_IOS ? (
// @ts-ignore
<FloatingEmojis
centerVertically
deviceWidth={deviceWidth}
disableHorizontalMovement
disableVerticalMovement
distance={70}
Expand Down
18 changes: 0 additions & 18 deletions src/components/PortalConsumer.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/components/WalletLoadingListener.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { useEffect } from 'react';
import { LoadingOverlay } from './modal';
import { sheetVerticalOffset } from '@/navigation/effects';
import { walletLoadingStore } from '@/state/walletLoading/walletLoading';

export default function WalletLoadingListener() {
const loadingState = walletLoadingStore(state => state.loadingState);

useEffect(() => {
if (loadingState) {
walletLoadingStore.getState().setComponent(<LoadingOverlay paddingTop={sheetVerticalOffset} title={loadingState} />);
}
return walletLoadingStore.getState().hide;
}, [loadingState]);

return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ export default React.memo(function FastCurrencySelectionRow({
{showFavoriteButton &&
chainId === ChainId.mainnet &&
(ios ? (
// @ts-ignore
<FloatingEmojis
centerVertically
deviceWidth={deviceWidth}
disableHorizontalMovement
disableVerticalMovement
distance={70}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function ProfileActionButtonsRow() {
</Column>
<Column>
<Animated.View style={[expandStyle]}>
<MoreButton />
<CopyButton />
</Animated.View>
</Column>
</Columns>
Expand Down Expand Up @@ -216,21 +216,25 @@ function SendButton() {
);
}

export function MoreButton() {
// ////////////////////////////////////////////////////
// Handlers

export function CopyButton() {
const [isToastActive, setToastActive] = useRecoilState(addressCopiedToastAtom);
const { accountAddress } = useAccountProfile();
const { isDamaged } = useWallets();

const handlePressCopy = React.useCallback(() => {
if (isDamaged) {
showWalletErrorAlert();
return;
}

if (!isToastActive) {
setToastActive(true);
setTimeout(() => {
setToastActive(false);
}, 2000);
}
Clipboard.setString(accountAddress);
}, [accountAddress, isToastActive, setToastActive]);
}, [accountAddress, isDamaged, isToastActive, setToastActive]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export function ProfileNameRow({
scaleTo={0}
size={50}
wiggleFactor={0}
// @ts-expect-error – JS component
setOnNewEmoji={newOnNewEmoji => (onNewEmoji.current = newOnNewEmoji)}
/>
</Box>
Expand Down
123 changes: 0 additions & 123 deletions src/components/backup/AddWalletToCloudBackupStep.tsx

This file was deleted.

Loading

0 comments on commit 572edec

Please sign in to comment.