Skip to content

Commit

Permalink
chore: pulled from main + fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotrilitech committed Jan 22, 2025
2 parents 5de5356 + 0a3987e commit 00c3fa0
Show file tree
Hide file tree
Showing 26 changed files with 272 additions and 237 deletions.
6 changes: 3 additions & 3 deletions apps/desktop-e2e/src/helpers/AccountGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export class AccountGroupBuilder {

setDerivationPathTemplate(derivationPathTemplate: string): void {
if (this.accountGroup.type !== "mnemonic") {
throw new CustomError(`Derivation path is not used for ${this.accountGroup.type} accounts}`);
throw new CustomError(`Derivation path is not used for ${this.accountGroup.type} accounts`);
}
this.derivationPathTemplate = derivationPathTemplate;
}

setSeedPhrase(seedPhrase: string[]): void {
if (this.accountGroup.type !== "mnemonic") {
throw new CustomError(`Seed phrase is not used for ${this.accountGroup.type} accounts}`);
throw new CustomError(`Seed phrase is not used for ${this.accountGroup.type} accounts`);
}
this.seedPhrase = seedPhrase;
}
Expand All @@ -58,7 +58,7 @@ export class AccountGroupBuilder {

async setSecretKey(secretKey: string, accountIndex = 0): Promise<void> {
if (this.accountGroup.type !== "secret_key") {
throw new CustomError(`Secret key is not used for ${this.accountGroup.type} accounts}`);
throw new CustomError(`Secret key is not used for ${this.accountGroup.type} accounts`);
}
this.accountGroup.accounts[accountIndex].pkh = await (
await InMemorySigner.fromSecretKey(secretKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const RestoreLedger = ({
toast({ description: "Account successfully created!", status: "success" });
closeModal();
}, LEDGER_TIMEOUT),
error => {
(error: { name: string; message: any }) => {
if (error.name === "PublicKeyRetrievalError") {
return {
description: "Request rejected. Please unlock your Ledger and open the Tezos app",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useSignWithBeacon = (

return openWith(<SuccessStep hash={opHash} />);
},
error => ({
(error: { message: any }) => ({
description: `Failed to confirm Beacon operation: ${error.message}`,
})
);
Expand Down
21 changes: 14 additions & 7 deletions apps/desktop/src/providers/UmamiTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { ChakraProvider, ColorModeScript } from "@chakra-ui/react";
import { ChakraProvider, ColorModeScript, useToast } from "@chakra-ui/react";
import { ToastProvider } from "@umami/utils";

import theme from "../style/theme";

export const UmamiTheme = (props: any) => (
<ChakraProvider theme={theme}>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
{props.children}
</ChakraProvider>
);
export const UmamiTheme = (props: any) => {
const toast = useToast();

return (
<ToastProvider toast={toast}>
<ChakraProvider theme={theme}>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
{props.children}
</ChakraProvider>
</ToastProvider>
);
};
2 changes: 1 addition & 1 deletion apps/desktop/src/utils/beacon/useHandleBeaconMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const useHandleBeaconMessage = () => {

return openWith(modal, { onClose });
},
error => ({
(error: { message: any }) => ({
description: `Error while processing Beacon request: ${error.message}`,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useSignWithBeacon = ({

return openWith(<SuccessStep hash={opHash} />);
},
error => ({
(error: { message: any }) => ({
description: `Failed to confirm Beacon operation: ${error.message}`,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useSignWithWalletConnect = ({
await walletKit.respondSessionRequest({ topic: requestId.topic, response });
return openWith(<SuccessStep hash={opHash} />);
},
error => ({
(error: { message: any }) => ({
description: `Failed to confirm WalletConnect operation: ${error.message}`,
})
);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/beacon/useHandleBeaconMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const useHandleBeaconMessage = () => {

return openWith(modal, { onClose });
},
error => ({
(error: { message: any }) => ({
description: `Error while processing Beacon request: ${error.message}`,
})
);
Expand Down
30 changes: 15 additions & 15 deletions apps/web/src/providers/UmamiTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChakraProvider, ColorModeScript } from "@chakra-ui/react";
import { ChakraProvider, ColorModeScript, useToast } from "@chakra-ui/react";
import { Global, css } from "@emotion/react";
import { ToastProvider } from "@umami/utils";
import { type PropsWithChildren } from "react";
import "focus-visible/dist/focus-visible";

Expand All @@ -17,17 +18,16 @@ const GlobalStyles = css`
}
`;

export const UmamiTheme = ({ children }: PropsWithChildren) => (
<ChakraProvider
theme={theme}
toastOptions={{
defaultOptions: {
render: CustomToast,
},
}}
>
<Global styles={GlobalStyles} />
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
{children}
</ChakraProvider>
);
export const UmamiTheme = ({ children }: PropsWithChildren) => {
const toast = useToast({ render: CustomToast });

return (
<ChakraProvider theme={theme}>
<ToastProvider toast={toast}>
<Global styles={GlobalStyles} />
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
{children}
</ToastProvider>
</ChakraProvider>
);
};
5 changes: 5 additions & 0 deletions apps/web/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ jest.doMock("@chakra-ui/react", () => ({
useColorMode: () => ({ colorMode: "light", toggleColorMode: jest.fn() }),
}));

jest.mock("@umami/utils", () => ({
...jest.requireActual("@umami/utils"),
useCustomToast: () => mockToast,
}));

jest.mock("./utils/persistor", () => ({
pause: jest.fn(),
}));
Expand Down
1 change: 1 addition & 0 deletions packages/data-polling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@umami/state": "workspace:^",
"@umami/tezos": "workspace:^",
"@umami/tzkt": "workspace:^",
"@umami/test-utils": "workspace:^",
"date-fns": "^4.1.0",
"framer-motion": "^11.15.0",
"lodash": "^4.17.21",
Expand Down
2 changes: 2 additions & 0 deletions packages/data-polling/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { webcrypto } from "crypto";
import { TextDecoder, TextEncoder } from "util";

import { mockToast } from "@umami/state";
import { mockLocalStorage } from "@umami/test-utils";

beforeEach(() => {
Object.defineProperties(global, {
crypto: { value: webcrypto, writable: true },
TextDecoder: { value: TextDecoder, writable: true },
TextEncoder: { value: TextEncoder, writable: true },
localStorage: { value: mockLocalStorage(), writable: true },
});
});

Expand Down
7 changes: 3 additions & 4 deletions packages/data-polling/src/testUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import * as testLib from "@testing-library/react";
import { type UmamiStore, makeStore } from "@umami/state";
import { type PropsWithChildren, act } from "react";
import { Provider } from "react-redux";
import { makeStore, UmamiStore } from "@umami/state";
import { PropsWithChildren, act } from "react";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

const customRenderHook = <
Result,
Expand Down
3 changes: 0 additions & 3 deletions packages/state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@
},
"dependencies": {
"@airgap/beacon-wallet": "^4.3.1",
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@reduxjs/toolkit": "^2.5.0",
"@reown/walletkit": "^1.0.1",
"@tanstack/react-query": "^5.62.11",
Expand Down
22 changes: 16 additions & 6 deletions packages/state/src/hooks/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
// import { useToast } from "@chakra-ui/react";
import { useQuery } from "@tanstack/react-query";
import { type RawPkh } from "@umami/tezos";
import { useCustomToast } from "@umami/utils";
import { uniq } from "lodash";
import { useDispatch } from "react-redux";

Expand Down Expand Up @@ -102,7 +103,7 @@ export const useRemoveBeaconPeersByAccounts = () => {

export const useAddPeer = () => {
const { refresh } = useBeaconPeers();
const toast: any = undefined; //useToast();
const toast = useCustomToast();

return (payload: string) =>
new Serializer()
Expand All @@ -111,11 +112,20 @@ export const useAddPeer = () => {
.then(peer => WalletClient.addPeer(peer as ExtendedPeerInfo))
.then(() => refresh())
.catch(e => {
toast({
description:
"Beacon sync code in the clipboard is invalid. Please copy a beacon sync code from the dApp",
status: "error",
});
const description =
"Beacon sync code in the clipboard is invalid. Please copy a beacon sync code from the dApp";
const type = "error";

toast.show
? toast.show({
type,
text1: description,
})
: toast({
description,
status: type,
});

console.error(e);
});
};
4 changes: 2 additions & 2 deletions packages/state/src/hooks/useAsyncActionHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe("useAsyncActionHandler", () => {
view.result.current.handleAsyncActionUnsafe(() => Promise.reject(new Error("test error")))
)
).rejects.toThrow("test error");
expect(mockToast).toHaveBeenCalledTimes(2);
expect(mockToast).toHaveBeenCalledTimes(1);
});

it("Unsafe propagates the error and shows the toast once on first handling", async () => {
Expand All @@ -181,7 +181,7 @@ describe("useAsyncActionHandler", () => {
status: "error",
isClosable: true,
});
expect(mockToast).toHaveBeenCalledTimes(2);
expect(mockToast).toHaveBeenCalledTimes(1);
});

it("Unsafe propagates the error and shows no toast on second handling", async () => {
Expand Down
18 changes: 4 additions & 14 deletions packages/state/src/hooks/useAsyncActionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { type UseToastOptions } from "@chakra-ui/react";
import { getErrorContext } from "@umami/utils";
import { type ToastOptions, getErrorContext, useCustomToast } from "@umami/utils";
import { useCallback, useRef, useState } from "react";

import { useAppDispatch } from "./useAppDispatch";
import { errorsActions } from "../slices";
import { mockToast } from "../testUtils";

/**
* Hook for gracefully handling async actions.
Expand All @@ -22,13 +20,13 @@ import { mockToast } from "../testUtils";
export const useAsyncActionHandler = () => {
const [isLoading, setIsLoading] = useState(false);
const isLoadingRef = useRef(isLoading);
const toast: any = undefined; // useToast();
const toast = useCustomToast();
const dispatch = useAppDispatch();

const handleAsyncActionUnsafe = useCallback(
async <T>(
fn: () => Promise<T>,
toastOptions?: UseToastOptions | ((error: any) => UseToastOptions)
toastOptions?: ToastOptions | ((error: any) => ToastOptions)
): Promise<T | void> => {
if (isLoadingRef.current) {
return;
Expand All @@ -53,14 +51,6 @@ export const useAsyncActionHandler = () => {
...(typeof toastOptions === "function" ? toastOptions(error) : toastOptions),
});

// TODO: fix this dirty hack
mockToast({
description: errorContext.description,
status: "error",
isClosable: true,
...(typeof toastOptions === "function" ? toastOptions(error) : toastOptions),
});

dispatch(errorsActions.add(errorContext));
}
throw error;
Expand All @@ -76,7 +66,7 @@ export const useAsyncActionHandler = () => {
const handleAsyncAction = useCallback(
async <T>(
fn: () => Promise<T>,
toastOptions?: UseToastOptions | ((error: any) => UseToastOptions)
toastOptions?: ToastOptions | ((error: any) => ToastOptions)
): Promise<T | void> => handleAsyncActionUnsafe(fn, toastOptions).catch(() => {}),
[handleAsyncActionUnsafe]
);
Expand Down
6 changes: 3 additions & 3 deletions packages/state/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Object.defineProperties(global, {
fetch: { value: jest.fn(), writable: true },
});

jest.mock("@chakra-ui/react", () => ({
...jest.requireActual("@chakra-ui/react"),
useToast: () => mockToast,
jest.mock("@umami/utils", () => ({
...jest.requireActual("@umami/utils"),
useCustomToast: () => mockToast,
}));

jest.mock("./beacon/WalletClient", () => ({
Expand Down
13 changes: 6 additions & 7 deletions packages/state/src/testUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import * as testLib from "@testing-library/react";
import { type Account } from "@umami/core";
import { type Multisig } from "@umami/multisig";
import { type RawPkh } from "@umami/tezos";
import { type PropsWithChildren, act } from "react";
import { Provider } from "react-redux";

import { accountsActions, multisigsActions } from "./slices";
import { makeStore, UmamiStore } from "./store";
import * as testLib from "@testing-library/react";
import { type UmamiStore, makeStore } from "./store";

export const addTestAccount = (store: UmamiStore, account: Account | Multisig) => {
if (!("type" in account) || account.type === "multisig") {
Expand All @@ -18,11 +22,6 @@ export const addTestAccounts = (store: UmamiStore, accounts: (Account | Multisig
accounts.forEach(account => addTestAccount(store, account));
};

import { PropsWithChildren, act } from "react";
import { Provider } from "react-redux";
import { RawPkh } from "@umami/tezos";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

const customRenderHook = <
Result,
Props,
Expand Down
4 changes: 3 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/eslint": "^8",
"@types/jest": "^29.5.14",
"@types/lodash": "^4",
"@types/sanitize-html": "^2.13.0",
"@umami/eslint-config": "workspace:^",
"@umami/jest-config": "workspace:^",
"@umami/test-utils": "workspace:^",
Expand Down Expand Up @@ -60,6 +61,7 @@
},
"dependencies": {
"bignumber.js": "^9.1.2",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"sanitize-html": "^2.14.0"
}
}
Loading

0 comments on commit 00c3fa0

Please sign in to comment.