diff --git a/src/app/App.test.tsx b/src/app/App.test.tsx index 9b8ff52814..d0c0adcebb 100644 --- a/src/app/App.test.tsx +++ b/src/app/App.test.tsx @@ -3,6 +3,7 @@ import { translations as errorTranslations } from "domains/error/i18n"; import { translations as profileTranslations } from "domains/profile/i18n"; +import { ipcRenderer } from "electron"; import electron from "electron"; import nock from "nock"; import React from "react"; @@ -18,6 +19,7 @@ import { import { App } from "./App"; jest.mock("electron", () => ({ + ipcRenderer: { on: jest.fn(), send: jest.fn(), removeListener: jest.fn() }, remote: { nativeTheme: { shouldUseDarkColors: true, @@ -42,6 +44,10 @@ describe("App", () => { .persist(); }); + beforeEach(() => { + ipcRenderer.on.mockImplementationOnce((event, callback) => callback(event, null)); + }); + it("should render splash screen", async () => { process.env.REACT_APP_BUILD_MODE = "demo"; diff --git a/src/app/App.tsx b/src/app/App.tsx index ffe2cbcab0..7eaac99fc5 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -28,8 +28,8 @@ import { Theme } from "types"; import { middlewares, RouterView, routes } from "../router"; import { EnvironmentProvider, ThemeProvider, useEnvironmentContext, useThemeContext } from "./contexts"; +import { useDeeplink, useEnvSynchronizer, useNetworkStatus } from "./hooks"; import { useNetworkStatus } from "./hooks"; -import { useEnvSynchronizer } from "./hooks/use-synchronizer"; import { i18n } from "./i18n"; import { httpClient } from "./services"; @@ -37,11 +37,12 @@ const __DEV__ = process.env.NODE_ENV !== "production"; const Main = () => { const [showSplash, setShowSplash] = useState(true); - + const { pathname } = useLocation(); const { theme, setTheme } = useThemeContext(); const { env, persist } = useEnvironmentContext(); const isOnline = useNetworkStatus(); const { start, runAll } = useEnvSynchronizer(); + useDeeplink(); const location = useLocation(); const pathname = (location as any).location?.pathname || location.pathname; diff --git a/src/app/hooks/index.ts b/src/app/hooks/index.ts index 99921fbce6..549aa8cf8d 100644 --- a/src/app/hooks/index.ts +++ b/src/app/hooks/index.ts @@ -4,4 +4,6 @@ export * from "./env"; export * from "./network-status"; export * from "./use-clipboard"; export * from "./use-query-params"; +export * from "./use-deeplink"; +export * from "./use-synchronizer"; export * from "./use-reload-path"; diff --git a/src/app/hooks/use-deeplink.test.tsx b/src/app/hooks/use-deeplink.test.tsx new file mode 100644 index 0000000000..ca6cadab0f --- /dev/null +++ b/src/app/hooks/use-deeplink.test.tsx @@ -0,0 +1,148 @@ +import { translations } from "app/i18n/common/i18n"; +import { toasts } from "app/services"; +import { ipcRenderer } from "electron"; +import { createMemoryHistory } from "history"; +import React from "react"; +import { Route } from "react-router-dom"; +import { getDefaultProfileId, getDefaultWalletId, renderWithRouter } from "testing-library"; + +import { useDeeplink } from "./use-deeplink"; + +const history = createMemoryHistory(); +const walletURL = `/profiles/${getDefaultProfileId()}/wallets/${getDefaultWalletId()}`; + +jest.mock("electron", () => ({ + ipcRenderer: { on: jest.fn(), send: jest.fn(), removeListener: jest.fn() }, +})); + +describe("useDeeplink hook", () => { + const toastSpy = jest.spyOn(toasts, "warning").mockImplementationOnce((subject) => jest.fn(subject)); + + const TestComponent: React.FC = () => { + useDeeplink(); + + return
+ test smartbridge +
++ Your transaction was successfully sent. Please monitor the blockchain to ensure your transaction is confirmed and processed. The following is relevant information for your transaction: +
+