diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index af2214bb0e4170cb8c03548ba49ccf3d276e1fbd..3b4e518665e12c91379f3b95cc951075d0b34444 100644 --- a/src/components/Splash/SplashRoot.tsx +++ b/src/components/Splash/SplashRoot.tsx @@ -19,7 +19,6 @@ import { PartnersInfo, Profile, ProfileType, - UserChallenge, } from 'models' import React, { ReactNode, useCallback, useEffect, useState } from 'react' import ActionService from 'services/action.service' @@ -195,19 +194,24 @@ const SplashRoot = ({ fadeTimer = 1000, children }: SplashRootProps) => { const transaction = Sentry.startTransaction({ name: 'Initialize app' }) try { console.groupCollapsed('Initialization logs') - // init Terms - const termsStatus = await initializationService.initConsent() + // Run init steps in parallel + const [ + termsStatus, + , + profile, + profileType, + profileEcogesture, + fluidStatus, + ] = await Promise.all([ + initializationService.initConsent(), + initializationService.initFluidPrices(), + initializationService.initProfile(), + initializationService.initProfileType(), + initializationService.initProfileEcogesture(), + initializationService.initFluidStatus(), + ]) if (subscribed) dispatch(updateTermsStatus(termsStatus)) - // Init fluidPrices - await initializationService.initFluidPrices() - - // Init profile and update ecogestures, challenges, analysis - const profile = await initializationService.initProfile() - const profileType = await initializationService.initProfileType() - const profileEcogesture = - await initializationService.initProfileEcogesture() - const migrationsResult = await ms.runMigrations(migrations) // Init last release notes when they exist dispatch( @@ -250,11 +254,11 @@ const SplashRoot = ({ fadeTimer = 1000, children }: SplashRootProps) => { } dispatch(toggleAnalysisNotification(!profile.haveSeenLastAnalysis)) } - // Init Fluid status && lastDate for the chart - const fluidStatus = await initializationService.initFluidStatus() + + // Process fluids status if (subscribed) { dispatch(setFluidStatus(fluidStatus)) - let lastDataDate: DateTime | null = DateTime.fromISO('0001-01-01') + let lastDataDate = DateTime.fromISO('0001-01-01') for (const fluid of fluidStatus) { if (fluid.lastDataDate && fluid.lastDataDate > lastDataDate) { lastDataDate = fluid.lastDataDate @@ -282,10 +286,9 @@ const SplashRoot = ({ fadeTimer = 1000, children }: SplashRootProps) => { UserActionState.ONGOING ) { const actionService = new ActionService(client) - const updatedUserChallenge: UserChallenge | null = - await actionService.isActionDone( - filteredCurrentOngoingChallenge[0] - ) + const updatedUserChallenge = await actionService.isActionDone( + filteredCurrentOngoingChallenge[0] + ) if (updatedUserChallenge) { dispatch(updateUserChallengeList(updatedUserChallenge)) } diff --git a/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap b/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap index 1cc016b6bf9ee4e84abc6eba83474d49907a400e..17d47890730c9f78a4bd3eba41b3bdb193b51bbf 100644 --- a/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap +++ b/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap @@ -27,7 +27,7 @@ exports[`SplashRoot component should be rendered correctly 1`] = ` > <div class="splash-progress-bar-content" - style="left: -73%;" + style="left: -40%;" /> </div> </div> @@ -35,7 +35,7 @@ exports[`SplashRoot component should be rendered correctly 1`] = ` <div class="step-label text-18-normal" > - splashscreen.step.1 + splashscreen.step.3 </div> <div class="splash-logos-container" @@ -83,7 +83,7 @@ exports[`SplashRoot component should render the error screen 1`] = ` <div class="splash-error-text text-18-normal" > - splashscreen.consent_error + splashscreen.consos_error </div> </div> </div> diff --git a/src/components/Splash/__snapshots__/SplashScreen.spec.tsx.snap b/src/components/Splash/__snapshots__/SplashScreen.spec.tsx.snap index fee381e60a027c591bb21d19cc7a20a4f0d565cf..41988b37679733c27e154d98ac988224f1f90181 100644 --- a/src/components/Splash/__snapshots__/SplashScreen.spec.tsx.snap +++ b/src/components/Splash/__snapshots__/SplashScreen.spec.tsx.snap @@ -23,7 +23,7 @@ exports[`SplashScreen component should be rendered correctly 1`] = ` > <div class="splash-progress-bar-content" - style="left: -73%;" + style="left: -80%;" /> </div> </div> @@ -31,7 +31,7 @@ exports[`SplashScreen component should be rendered correctly 1`] = ` <div class="step-label text-18-normal" > - splashscreen.step.1 + splashscreen.step.0 </div> <div class="splash-logos-container" diff --git a/src/models/initialisationSteps.model.ts b/src/models/initialisationSteps.model.ts index fd9cb97b414f2aab8c18118ad913e2d31de9783e..9ccccf4f43699fef3bbd5c73e0ed7ae3d91605fd 100644 --- a/src/models/initialisationSteps.model.ts +++ b/src/models/initialisationSteps.model.ts @@ -1,10 +1,10 @@ export enum InitSteps { - MIGRATION, CONSENT, + PRICES, PROFILE, - CHALLENGES, - PRICES, // never used CONSOS, + MIGRATION, + CHALLENGES, } export enum InitStepsErrors { MIGRATION_ERROR = 'migration_error', diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts index b30bb683aa36206da0c133acd1404a47d2c643d6..e01b9dd782ba8f0f8868547cd647c5bced8641bf 100644 --- a/src/services/initialization.service.ts +++ b/src/services/initialization.service.ts @@ -160,6 +160,7 @@ export default class InitializationService { public async initFluidPrices(): Promise<void> { const startTime = performance.now() + this._setInitStep(InitSteps.PRICES) logDuration('[Initialization] Launching fluidPrices service', startTime) const triggerQuery: QueryDefinition = Q(TRIGGERS_DOCTYPE).where({ 'message.name': 'fluidsPrices',