Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Onboarding redirect #236

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/navigation/navigation-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ export const navigationModel = {
navigatorChanged,
navigatorPushed,
},

/* Internal API (tests only) */
_internal: {
navigateFx,
},
};
24 changes: 24 additions & 0 deletions app/models/wallet/wallet-model.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import secureLocalStorage from 'react-secure-storage';

import { allSettled, fork } from 'effector';
import { $path } from 'remix-routes';
import { describe, expect, test, vi } from 'vitest';

import { navigationModel } from '../navigation';

import { TelegramApi, cryptoApi, localStorageApi } from '@/shared/api';

import { walletModel } from './wallet-model';
Expand Down Expand Up @@ -52,4 +55,25 @@ describe('models/wallet/wallet-model', () => {

expect(walletPK).toEqual('mnemonic');
});

test('should navigate to onboarding on empty mnemonic', async () => {
const spyNavigate = vi.fn();

const scope = fork({
handlers: [
[walletModel._internal.requestMnemonicFx, vi.fn().mockRejectedValue(new Error('no mnemonic'))],
[navigationModel._internal.navigateFx, spyNavigate],
],
});

await allSettled(walletModel._internal.requestMnemonicFx, { scope });
expect(spyNavigate).toHaveBeenCalledWith({
navigator: expect.any(Function),
params: {
type: 'navigate',
to: $path('/onboarding'),
options: { replace: true },
},
});
});
});
9 changes: 7 additions & 2 deletions app/models/wallet/wallet-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ const clearWalletFx = createEffect((clearRemote: boolean): Promise<boolean> => {
: Promise.resolve(true);
});

const requestMnemonicFx = createEffect((): Promise<Mnemonic> => {
return TelegramApi.getItem(MNEMONIC_STORE);
const requestMnemonicFx = createEffect(async (): Promise<Mnemonic> => {
const mnemonic = await TelegramApi.getItem(MNEMONIC_STORE);

if (!mnemonic) throw new Error('Mnemonic not found');

return mnemonic;
});

type SaveMnemonicParams = {
Expand Down Expand Up @@ -161,5 +165,6 @@ export const walletModel = {
/* Internal API (tests only) */
_internal: {
$wallet: $wallet,
requestMnemonicFx,
},
};
4 changes: 1 addition & 3 deletions app/ui/molecules/PasswordReset/PasswordForgotten.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useState } from 'react';

import { Button, ModalBody, ModalFooter, ModalHeader } from '@nextui-org/react';

import { walletModel } from '@/models/wallet';
import { BigTitle, BodyText, Countdown, Icon, MediumTitle } from '@/ui/atoms';

type Props = {
Expand All @@ -20,7 +19,6 @@ export const PasswordForgotten = ({ onClose, onSubmit }: Props) => {

const handleSubmit = () => {
setIsDisabled(true);
walletModel.input.walletCleared({ clearRemote: true });
onSubmit();
};

Expand Down Expand Up @@ -48,7 +46,7 @@ export const PasswordForgotten = ({ onClose, onSubmit }: Props) => {
onPress={handleSubmit}
>
<MediumTitle className="text-white">
Delete Backup <Countdown initValue={60} onFinish={() => setIsDisabled(false)} />
Delete Backup <Countdown initValue={4} onFinish={() => setIsDisabled(false)} />
</MediumTitle>
</Button>
<Button className="h-[50px] w-full rounded-full bg-bg-input" onPress={handleClose}>
Expand Down
Loading