Skip to content

Commit

Permalink
test: fix types issues
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Feb 28, 2025
1 parent ec9192b commit cacbd38
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useAsyncActionHandler, useRestoreBackup } from "@umami/state";
import { FormProvider, useForm } from "react-hook-form";

import { RotateIcon } from "../../../assets/icons";
import { persistor } from "../../../utils/persistor";
import { PasswordInput } from "../../PasswordInput";
import { ModalContentWrapper } from "../ModalContentWrapper";

Expand All @@ -32,11 +31,11 @@ export const RestoreBackupFile = () => {
const { handleAsyncAction } = useAsyncActionHandler();
const restoreBackup = useRestoreBackup();

const onSubmit = ({ password, file }: FormFields) =>
const onSubmit = ({ file }: FormFields) =>
handleAsyncAction(async () => {
const fileContent = await file[0].text();
const backup = JSON.parse(fileContent);
await restoreBackup(backup, password, persistor);
restoreBackup(backup);
});

return (
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/utils/useSaveBackup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const useSaveBackup = () => {
</ModalHeader>
<MasterPassword
onClose={onClose}
onVerify={password => downloadBackupFile(password).then(onClose)}
onVerify={() => {
downloadBackupFile();
onClose();
}}
/>
</ModalContent>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ import {
useAppDispatch,
useAsyncActionHandler,
useCurrentAccount,
useDownloadBackupFile,
useGetDecryptedMnemonic,
useGetNextAvailableAccountLabels,
useRestoreFromMnemonic,
useRestoreFromSecretKey,
} from "@umami/state";
import { decryptSecretKey } from "@umami/tezos";

export type Mode =
| "mnemonic"
| "secret_key"
| "new_mnemonic"
| "verification"
| "add_account"
| "save_backup";
export type Mode = "mnemonic" | "secret_key" | "new_mnemonic" | "verification" | "add_account";

const useGetSecretKeyHandler = () => {
const restoreFromSecretKey = useRestoreFromSecretKey();
Expand Down Expand Up @@ -82,7 +75,6 @@ export const useGetSetupPasswordSubmitHandler = (mode: Mode) => {
// const checkPassword = useValidateMasterPassword();

const handleVerify = useGetVerificationHandler();
const handleDownloadBackupFile = useDownloadBackupFile();
const handleSecretKey = useGetSecretKeyHandler();
const handleMnemonic = useGetMnemonicHandler();

Expand All @@ -109,10 +101,6 @@ export const useGetSetupPasswordSubmitHandler = (mode: Mode) => {
case "verification": {
return handleVerify(password);
}
case "save_backup": {
await handleDownloadBackupFile(password);
break;
}
}
}),
isLoading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const DeriveMnemonicAccountModal = ({ account }: DeriveMnemonicAccountMod
const toast = useToast();

const handleNameSubmit = ({ accountName }: { accountName: string }) => {
const handlePasswordSubmit = ({ password }: { password: string }) =>
const handlePasswordSubmit = (password?: string) =>
handleAsyncAction(
async () => {
trackAccountEvent("submit_account_derivation");

const newAccount = await deriveMnemonicAccount({
fingerPrint: account.seedFingerPrint,
password,
password: password || "",
label: accountName.trim() || DEFAULT_ACCOUNT_LABEL,
});

Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/ErrorPage/ErrorPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { type UmamiStore, addTestAccount, makeStore } from "@umami/state";
import { ErrorPage } from "./ErrorPage";
import { act, dynamicModalContextMock, render, screen, userEvent } from "../../testUtils";
import { LogoutModal } from "../Menu/LogoutModal";
import { SetupPassword } from "../Onboarding/SetupPassword";

let store: UmamiStore;

Expand Down Expand Up @@ -104,14 +103,11 @@ describe("ErrorPage", () => {
});

it("calls saveBackup function when 'Save Backup' button is clicked", async () => {
const { openWith } = dynamicModalContextMock;
const user = userEvent.setup();
render(<ErrorPage />, { store });

const saveBackupButton = screen.getByRole("button", { name: "Save backup" });
await act(() => user.click(saveBackupButton));

expect(openWith).toHaveBeenCalledWith(<SetupPassword mode="save_backup" />);
});

it("opens LogoutModal when 'Logout' button is clicked", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { PasswordInput } from "../PasswordInput";
type MasterPasswordModalProps = {
onSubmit: (password?: string) => void;
isLoading?: boolean;
defaultAccount: ImplicitAccount | null;
defaultAccount?: ImplicitAccount | null;
};

export const MasterPasswordModal = ({
Expand Down
63 changes: 0 additions & 63 deletions apps/web/src/components/Menu/ImportBackupModal.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export const ImportBackupTab = () => {
await login({ password });
}

onClose();

trackSuccessfulConnection("onboarding", "restore_from_backup");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "@chakra-ui/react";
import hj from "@hotjar/browser";
import { useImplicitAccounts } from "@umami/state";
import { useEffect } from "react";
import { useSearchParams } from "react-router-dom";

import { ImportBackupTab } from "./ImportBackupTab";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
useAppDispatch,
useAsyncActionHandler,
useCurrentAccount,
useDownloadBackupFile,
useGetDecryptedMnemonic,
useGetNextAvailableAccountLabels,
useRestoreFromMnemonic,
Expand All @@ -16,11 +15,7 @@ import {
import { decryptSecretKey } from "@umami/tezos";

import { type FormFields, type Mode } from "./types";
import {
trackAccountEvent,
trackButtonClick,
trackOnboardingEvent,
} from "../../../utils/analytics";
import { trackAccountEvent, trackOnboardingEvent } from "../../../utils/analytics";
import { setupPersistence } from "../../../utils/store";
import { ImportantNoticeModal } from "../VerificationFlow/ImportantNoticeModal";

Expand Down Expand Up @@ -85,7 +80,6 @@ export const useGetSetupPasswordSubmitHandler = (mode: Mode) => {
const checkPassword = useValidateMasterPassword();

const handleVerify = useGetVerificationHandler();
const handleDownloadBackupFile = useDownloadBackupFile();
const handleSecretKey = useGetSecretKeyHandler();
const handleMnemonic = useGetMnemonicHandler();

Expand Down Expand Up @@ -120,11 +114,6 @@ export const useGetSetupPasswordSubmitHandler = (mode: Mode) => {
case "verification": {
return handleVerify(password);
}
case "save_backup": {
trackButtonClick("backup", "download_backup");
await handleDownloadBackupFile(password);
break;
}
}

onClose();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/views/SessionLogin/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type LoginType = Omit<IDP, "email" | "apple">;
type LoginButtonProps = {
idp: LoginType;
prefix?: string;
onSubmit?: () => void;
onSubmit?: () => void | (() => void);
};

export const LoginButton = ({ idp, prefix, onSubmit }: LoginButtonProps) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/state/src/hooks/backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ beforeEach(() => {
});

describe("<RestoreBackupFile />", () => {
it("shows error for wrong backup file format", async () => {
it("shows error for wrong backup file format", () => {
const {
result: { current: restoreBackup },
} = renderHook(() => useRestoreBackup(), { store });
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("useDownloadBackupFile", () => {
addTestAccounts(store, mockAccounts);
});

it("fetches an encrypted state backup", async () => {
it("fetches an encrypted state backup", () => {
const linkMock: any = { click: jest.fn() };

localStorage.setItem("persist:accounts", backup["persist:accounts"]);
Expand Down

0 comments on commit cacbd38

Please sign in to comment.