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

Release 1.4.0 #233

Merged
merged 4 commits into from
Oct 22, 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,
},
};
2 changes: 1 addition & 1 deletion app/shared/api/telegram/bot-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getWalletCreationData(publicKey: PublicKey): string | null {
if (!TelegramApi.initData || !TelegramApi.initDataUnsafe.user?.id) return null;

return JSON.stringify({
publicKey,
accountId: publicKey,
userId: TelegramApi.initDataUnsafe.user.id,
auth: TelegramApi.initData,
});
Expand Down
2 changes: 0 additions & 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "telenova",
"version": "1.3.2",
"version": "1.4.0",
"type": "module",
"private": true,
"scripts": {
Expand Down
Loading