Skip to content

Commit

Permalink
swipe nav & backups v2
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-schrammel committed Jan 6, 2025
1 parent 910eb9e commit 53f7784
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 55 deletions.
10 changes: 10 additions & 0 deletions src/navigation/AddWalletNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export const AddWalletNavigator = () => {
},
}}
/>
<Swipe.Screen
component={ChooseWalletGroup}
initialParams={{ isFirstWallet }}
name={Routes.CHOOSE_WALLET_GROUP}
listeners={{
focus: () => {
setScrollEnabled(true);
},
}}
/>
<Swipe.Screen
component={ImportOrWatchWalletSheet}
initialParams={{ type }}
Expand Down
84 changes: 32 additions & 52 deletions src/navigation/ChooseWalletGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from 'react';
import { Separator, Text, useBackgroundColor, useForegroundColor } from '@/design-system';
import { Separator, Text, useForegroundColor } from '@/design-system';
import { View, Text as NativeText } from 'react-native';
import chroma from 'chroma-js';
import { useInitializeWallet, useWallets } from '@/hooks';
import { PROFILES, useExperimentalFlag } from '@/config';
import { useDispatch } from 'react-redux';
import Routes from '@/navigation/routesNames';
import { useNavigation } from './Navigation';
import WalletBackupTypes from '@/helpers/walletBackupTypes';
import WalletTypes from '@/helpers/walletTypes';
import { backupUserDataIntoCloud } from '@/handlers/cloudBackup';
import { logger, RainbowError } from '@/logger';
import { createAccountForWallet, walletsLoadState } from '@/redux/wallets';
import { createWallet, RainbowAccount, RainbowWallet } from '@/model/wallet';
Expand All @@ -23,13 +20,11 @@ import * as i18n from '@/languages';
import showWalletErrorAlert from '@/helpers/support';
import { ScrollView } from 'react-native-gesture-handler';
import CreateNewWalletGroupIcon from '@/assets/CreateNewWalletGroup.png';
import { SlackSheet } from '@/components/sheet';

function NewWalletGroup({ numWalletGroups }: { numWalletGroups: number }) {
const blue = useForegroundColor('blue');

const { navigate } = useNavigation();
const profilesEnabled = useExperimentalFlag(PROFILES);
const dispatch = useDispatch();
const initializeWallet = useInitializeWallet();

Expand All @@ -42,7 +37,7 @@ function NewWalletGroup({ numWalletGroups }: { numWalletGroups: number }) {
try {
const { name, color } = args;
await createWallet({ color, name });
await dispatch(walletsLoadState(profilesEnabled));
await dispatch(walletsLoadState());
// @ts-ignore
await initializeWallet();
navigate(Routes.WALLET_SCREEN, {}, true);
Expand Down Expand Up @@ -127,24 +122,12 @@ function WalletGroup({ wallet }: { wallet: RainbowWallet }) {
try {
const { name, color } = args;
if (wallet.damaged) throw new Error('Wallet is damaged');
const newWallets = await dispatch(createAccountForWallet(wallet.id, color, name));
// @ts-ignore
await dispatch(createAccountForWallet(wallet.id, color, name));
// @ts-expect-error - needs refactor to object params
await initializeWallet();
// If this wallet was previously backed up to the cloud
// We need to update userData backup so it can be restored too
if (wallet.backedUp && wallet.backupType === WalletBackupTypes.cloud) {
try {
await backupUserDataIntoCloud({ wallets: newWallets });
} catch (error) {
logger.error(new RainbowError('[AddWalletSheet]: Updating wallet userdata failed after new account creation'), { error });
throw error;
}
}
navigate(Routes.WALLET_SCREEN, {}, true);
} catch (e) {
logger.error(new RainbowError('[AddWalletSheet]: Error while trying to add account'), {
error: e,
});
logger.error(new RainbowError('[AddWalletSheet]: Error while trying to add account'), { error: e });
showWalletErrorAlert();
}
},
Expand Down Expand Up @@ -196,7 +179,6 @@ function WalletGroup({ wallet }: { wallet: RainbowWallet }) {
export function ChooseWalletGroup() {
const { goBack } = useNavigation();
const { wallets } = useWallets();
const surfaceSecondary = useBackgroundColor('surfaceSecondary');

if (!wallets) {
showWalletErrorAlert();
Expand All @@ -206,35 +188,33 @@ export function ChooseWalletGroup() {
const groups = Object.values(wallets).filter(wallet => wallet.type === WalletTypes.mnemonic);

return (
<SlackSheet removeTopPadding additionalTopPadding={false} backgroundColor={surfaceSecondary} onDismiss={goBack}>
<View style={{ width: '100%', paddingHorizontal: 24, gap: 20, alignItems: 'center', paddingBottom: 64 }}>
<View style={{ paddingTop: 24, paddingBottom: 12, width: '100%' }}>
<ButtonPressAnimation scaleTo={0.9} onPress={goBack} hitSlop={64} style={{ width: 20, height: 20 }}>
<Text color="blue" size="22pt" weight="bold">
􀆉
</Text>
</ButtonPressAnimation>
</View>
<Text color="label" size="22pt" weight="heavy">
{i18n.t(i18n.l.wallet.new.choose_wallet_group.title)}
</Text>
<Text color="labelQuaternary" size="15pt" weight="semibold" align="center">
{i18n.t(i18n.l.wallet.new.choose_wallet_group.description)}
</Text>

<View style={{ width: '100%' }}>
<Separator color={'separatorTertiary'} />
</View>

<NewWalletGroup numWalletGroups={groups.length} />
{groups.length > 0 && (
<ScrollView style={{ width: '100%' }} contentContainerStyle={{ gap: 16, paddingHorizontal: 12 }}>
{groups.map(wallet => (
<WalletGroup key={wallet.id} wallet={wallet} />
))}
</ScrollView>
)}
<View style={{ width: '100%', paddingHorizontal: 24, gap: 20, alignItems: 'center', paddingBottom: 64 }}>
<View style={{ paddingTop: 24, paddingBottom: 12, width: '100%' }}>
<ButtonPressAnimation scaleTo={0.9} onPress={goBack} hitSlop={64} style={{ width: 20, height: 20 }}>
<Text color="blue" size="22pt" weight="bold">
􀆉
</Text>
</ButtonPressAnimation>
</View>
<Text color="label" size="22pt" weight="heavy">
{i18n.t(i18n.l.wallet.new.choose_wallet_group.title)}
</Text>
<Text color="labelQuaternary" size="15pt" weight="semibold" align="center">
{i18n.t(i18n.l.wallet.new.choose_wallet_group.description)}
</Text>

<View style={{ width: '100%' }}>
<Separator color={'separatorTertiary'} />
</View>
</SlackSheet>

<NewWalletGroup numWalletGroups={groups.length} />
{groups.length > 0 && (
<ScrollView style={{ width: '100%' }} contentContainerStyle={{ gap: 16, paddingHorizontal: 12 }}>
{groups.map(wallet => (
<WalletGroup key={wallet.id} wallet={wallet} />
))}
</ScrollView>
)}
</View>
);
}
2 changes: 0 additions & 2 deletions src/navigation/Routes.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ import { RootStackParamList } from './types';
import WalletLoadingListener from '@/components/WalletLoadingListener';
import { Portal as CMPortal } from '@/react-native-cool-modals/Portal';
import { NetworkSelector } from '@/components/NetworkSwitcher';
import { ChooseWalletGroup } from './ChooseWalletGroup';

const Stack = createStackNavigator();
const OuterStack = createStackNavigator();
Expand Down Expand Up @@ -163,7 +162,6 @@ function BSNavigator() {
<BSStack.Screen component={MintSheet} name={Routes.MINT_SHEET} />
<BSStack.Screen component={QRScannerScreen} name={Routes.QR_SCANNER_SCREEN} />
<BSStack.Screen component={AddWalletNavigator} name={Routes.ADD_WALLET_NAVIGATOR} options={addWalletNavigatorPreset} />
<BSStack.Screen component={ChooseWalletGroup} name={Routes.CHOOSE_WALLET_GROUP} options={{ ...bottomSheetPreset }} />
<BSStack.Screen
component={PairHardwareWalletNavigator}
name={Routes.PAIR_HARDWARE_WALLET_NAVIGATOR}
Expand Down
1 change: 0 additions & 1 deletion src/navigation/Routes.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ function NativeStackNavigator() {
{...hardwareWalletTxNavigatorConfig}
/>
<NativeStack.Screen component={AddWalletNavigator} name={Routes.ADD_WALLET_NAVIGATOR} {...addWalletNavigatorConfig} />
<NativeStack.Screen component={ChooseWalletGroup} name={Routes.CHOOSE_WALLET_GROUP} {...panelConfig} />
<NativeStack.Screen component={Portal} name={Routes.PORTAL} {...portalSheetConfig} />
{profilesEnabled && (
<>
Expand Down

0 comments on commit 53f7784

Please sign in to comment.