Skip to content

Commit

Permalink
Merge pull request #236 from novasamatech/fix/onboarding
Browse files Browse the repository at this point in the history
Fix: Onboarding redirect
  • Loading branch information
tuul-wq authored and stepanLav committed Oct 17, 2024
1 parent f1cf23d commit b0b7177
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
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

0 comments on commit b0b7177

Please sign in to comment.