Skip to content

Commit

Permalink
Skip navigating to create account screen when onboarding if user has …
Browse files Browse the repository at this point in the history
…an existing account
  • Loading branch information
hbriese committed Sep 13, 2023
1 parent 10412d0 commit 19136d3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/src/screens/biometrics/BiometricsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const BiometricsScreen = withSuspense(
// Enable on 'open' (if supported) when this screen is first opened
useEffect(() => {
if (settings.open === null) updateSettings((s) => ({ ...s, open: hasSupport }));
}, [settings.open]);
}, [hasSupport, settings.open, updateSettings]);

return (
<Screen>
Expand Down
24 changes: 2 additions & 22 deletions app/src/screens/create-account/CreateAccountScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { gql } from '@api/generated';
import { useApproverAddress } from '@network/useApprover';
import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { StyleSheet, View } from 'react-native';
import { useMutation } from 'urql';
Expand All @@ -11,19 +10,9 @@ import { Actions } from '~/components/layout/Actions';
import { Screen } from '~/components/layout/Screen';
import { ScreenSkeleton } from '~/components/skeleton/ScreenSkeleton';
import { withSuspense } from '~/components/skeleton/withSuspense';
import { useQuery } from '~/gql';
import { StackNavigatorScreenProps } from '~/navigation/StackNavigator';
import { showError } from '~/provider/SnackbarProvider';

const Query = gql(/* GraphQL */ `
query CreateAccountScreen {
accounts {
id
address
}
}
`);

const Create = gql(/* GraphQL */ `
mutation CreateAccountScreen_Create($input: CreateAccountInput!) {
createAccount(input: $input) {
Expand All @@ -37,26 +26,17 @@ interface Inputs {
name: string;
}

export interface CreateAccountScreenParams {
isOnboarding?: boolean;
}
export interface CreateAccountScreenParams {}

export type CreateAccountScreenProps = StackNavigatorScreenProps<'CreateAccount'>;

export const CreateAccountScreen = withSuspense(
({ route, navigation: { replace } }: CreateAccountScreenProps) => {
const { isOnboarding } = route.params;
({ navigation: { replace } }: CreateAccountScreenProps) => {
const approver = useApproverAddress();

const { accounts } = useQuery(Query).data;
const create = useMutation(Create)[1];

const { control, handleSubmit } = useForm<Inputs>();

useEffect(() => {
if (isOnboarding && accounts.length) replace('Home', { account: accounts[0].address });
}, [accounts, isOnboarding, replace]);

return (
<Screen>
<Appbar mode="large" leading="back" headline="Account" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { gql } from '@api';
import { useNavigation } from '@react-navigation/native';
import { useQuery } from '~/gql';

const Query = gql(/* GraphQL */ `
query CreateAccountScreen {
accounts {
id
address
}
}
`);

export function useNavigateToCreateAccountOnboardScreen() {
const { navigate } = useNavigation();
const accounts = useQuery(Query).data.accounts;

return async () => {
return accounts?.length
? navigate('Home', { account: accounts[0].address })
: navigate('CreateAccount', {});
};
}
9 changes: 4 additions & 5 deletions app/src/screens/notifications/NotificationSettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ListItem } from '~/components/list/ListItem';
import { NotificationsOutlineIcon } from '@theme/icons';
import { useAtomValue } from 'jotai';
import { ListHeader } from '~/components/list/ListHeader';
import { useNavigateToCreateAccountOnboardScreen } from '../create-account/useNavigateToCreateAccountOnboardScreen';

export type NotificationChannel = 'activity' | 'product';
export const NotificationChannelConfig: Record<NotificationChannel, NotificationChannelInput> = {
Expand Down Expand Up @@ -49,9 +50,11 @@ export interface NotificationSettingsParams {
export type NotificationSettingsScreenProps = StackNavigatorScreenProps<'NotificationSettings'>;

export const NotificationSettingsScreen = withSuspense(
({ navigation, route }: NotificationSettingsScreenProps) => {
({ route }: NotificationSettingsScreenProps) => {
const { isOnboarding } = route.params;
const [settings, update] = useImmerAtom(NOTIFICATIONS_ATOM);
const navigateToCreateAccountOnboarding = useNavigateToCreateAccountOnboardScreen();
const next = isOnboarding ? navigateToCreateAccountOnboarding : undefined;

const [perm, requestPerm] = Notifications.usePermissions({
ios: {
Expand All @@ -63,10 +66,6 @@ export const NotificationSettingsScreen = withSuspense(
},
});

const next = isOnboarding
? () => navigation.navigate('CreateAccount', { isOnboarding: true })
: undefined;

return (
<Screen>
<Appbar mode="small" leading="back" headline="" />
Expand Down

0 comments on commit 19136d3

Please sign in to comment.