From 1529c7f69cb760567795fc85a875f26feb69c5b2 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 17 Nov 2023 14:34:48 +0100 Subject: [PATCH] Extract app wrapper (#2060) This extracts everything related to setting up a single-page II app (preloading some assets, setting up polyfills, compatibility checks etc) into a helper function. This is preparation work for adding new endpoints, so that they won't need to import/use the main app code (more readable + smaller bundlers). An apparently unnecessary endpoint (`#compatibilityNotice`) was also removed. --- src/frontend/src/flows/manage/index.ts | 2 +- src/frontend/src/index.ts | 122 ++------------------- src/frontend/src/spa.ts | 105 ++++++++++++++++++ src/frontend/src/utils/featureDetection.ts | 6 +- 4 files changed, 119 insertions(+), 116 deletions(-) create mode 100644 src/frontend/src/spa.ts diff --git a/src/frontend/src/flows/manage/index.ts b/src/frontend/src/flows/manage/index.ts index c7439488a3..ac8a7c1e6f 100644 --- a/src/frontend/src/flows/manage/index.ts +++ b/src/frontend/src/flows/manage/index.ts @@ -122,7 +122,7 @@ export const authFlowManage = async (connection: Connection) => { await recoveryWizard(userNumber, authenticatedConnection); } // From here on, the user is authenticated to II. - void renderManage({ + return renderManage({ userNumber, connection: authenticatedConnection, identityBackground, diff --git a/src/frontend/src/index.ts b/src/frontend/src/index.ts index 1d381a086f..d5bc04a349 100644 --- a/src/frontend/src/index.ts +++ b/src/frontend/src/index.ts @@ -1,114 +1,16 @@ -import loaderUrl from "$src/components/loader.webp"; +import { + handleLogin, + handleLoginFlowResult, +} from "$src/components/authenticateBox"; import { addDeviceSuccess } from "$src/flows/addDevice/manage/addDeviceSuccess"; -import { showWarningIfNecessary } from "./banner"; -import { displayError } from "./components/displayError"; -import { anyFeatures, features } from "./features"; +import { nonNullish } from "@dfinity/utils"; import { registerTentativeDevice } from "./flows/addDevice/welcomeView/registerTentativeDevice"; import { authFlowAuthorize } from "./flows/authorize"; -import { compatibilityNotice } from "./flows/compatibilityNotice"; import { authFlowManage, renderManageWarmup } from "./flows/manage"; -import "./styles/main.css"; +import { createSpa } from "./spa"; import { getAddDeviceAnchor } from "./utils/addDeviceLink"; -import { checkRequiredFeatures } from "./utils/featureDetection"; -import { Connection } from "./utils/iiConnection"; -import { version } from "./version"; - -import { isNullish, nonNullish } from "@dfinity/utils"; - -// Polyfill Buffer globally for the browser -import { - handleLogin, - handleLoginFlowResult, -} from "$src/components/authenticateBox"; -import { Buffer } from "buffer"; -globalThis.Buffer = Buffer; - -/** Reads the canister ID from the