From 1bb4a1b9a01a61c25fb0e9dacd51846c08aad0ec Mon Sep 17 00:00:00 2001 From: Thorsten Schau Date: Fri, 25 Aug 2023 15:53:32 +0200 Subject: [PATCH] fix Mocklogin & add min and maxdate to survey datepicker --- .../o-onboarding/processes/loginWithTorus.ts | 34 +++++++++++++++---- .../UserDataCollectionSurvey.svelte | 6 ++-- shell/src/shared/web3AuthNoModal.ts | 17 ++++++++-- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/shell/src/dapps/o-onboarding/processes/loginWithTorus.ts b/shell/src/dapps/o-onboarding/processes/loginWithTorus.ts index a9d8cdbd6..3c0b0c5bf 100644 --- a/shell/src/dapps/o-onboarding/processes/loginWithTorus.ts +++ b/shell/src/dapps/o-onboarding/processes/loginWithTorus.ts @@ -13,11 +13,12 @@ import HtmlViewer from "../../../../../packages/o-editors/src/HtmlViewer.svelte" import { PlatformEvent } from "@o-platform/o-events/dist/platformEvent"; import { show } from "@o-platform/o-process/dist/actions/show"; import ErrorView from "../../../shared/atoms/Error.svelte"; -import { Web3Auth } from "../../../shared/web3AuthNoModal"; +import { Web3Auth, GetWeb3AuthResult } from "../../../shared/web3AuthNoModal"; import { FindInvitationCreatorDocument, Profile, QueryFindInvitationCreatorArgs } from "../../../shared/api/data/types"; import { ApiClient } from "../../../shared/apiConnection"; import { AvataarGenerator } from "../../../shared/avataarGenerator"; import { setWindowLastError } from "../../../shared/processes/actions/setWindowLastError"; +import { OpenloginUserInfo } from "@web3auth/openlogin-adapter"; import { Environment } from "../../../shared/environment"; @@ -132,11 +133,11 @@ const processDefinition = (processId: string) => onDone: [ { cond: (context) => Environment.useMockLogin === true, - target: "useMockProfile", + target: "#useMockProfile", }, { cond: (context) => context.data.accountAddress === undefined, - target: "chooseFlow", + target: "#chooseFlow", }, { cond: (context) => context.data.accountAddress !== undefined, @@ -197,9 +198,30 @@ const processDefinition = (processId: string) => src: async (context) => { const webauth = new Web3Auth(); await webauth.init(); - await webauth.login("mock", context.data.useMockProfileIndex); - const privateKey = await webauth.getPrivateKey(); - const userInfo = await webauth.getUserInfo(context.data.useMockProfileIndex); + let privateKey: { privKey: any } = undefined; + let userInfo: OpenloginUserInfo; + + const mockProfile = Environment.getTestProfile(context.data.useMockProfileIndex); + + if (mockProfile) { + privateKey = { + privKey: mockProfile.privateKey, + }; + + const openLogin = { + async getUserInfo(): Promise> { + delete mockProfile.privateKey; + return mockProfile; + }, + }; + + userInfo = await openLogin.getUserInfo(); + } else { + await webauth.login("mock", context.data.useMockProfileIndex); + privateKey = await webauth.getPrivateKey(); + userInfo = await webauth.getUserInfo(context.data.useMockProfileIndex); + } + return { privateKey: privateKey.privKey, userInfo: userInfo, diff --git a/shell/src/dapps/o-survey/components/UserDataCollectionSurvey.svelte b/shell/src/dapps/o-survey/components/UserDataCollectionSurvey.svelte index fd9c044b3..ca36181ab 100644 --- a/shell/src/dapps/o-survey/components/UserDataCollectionSurvey.svelte +++ b/shell/src/dapps/o-survey/components/UserDataCollectionSurvey.svelte @@ -261,7 +261,7 @@ const options = { {#if $inviteUrl} {$_("dapps.o-homepage.components.survey.userDataCollection.inviteValid")} {:else} - {/if} @@ -287,13 +287,13 @@ const options = { {/if}
-
{#if $myForm.dirty} diff --git a/shell/src/shared/web3AuthNoModal.ts b/shell/src/shared/web3AuthNoModal.ts index ccfbd8db0..4c48b2106 100644 --- a/shell/src/shared/web3AuthNoModal.ts +++ b/shell/src/shared/web3AuthNoModal.ts @@ -116,10 +116,23 @@ export class Web3Auth { console.log("idToken: ", idToken); }; - getUserInfo = async (mockprofileIndex: number = 0) => { + getUserInfo = async (mockprofileIndex: number = undefined) => { console.log("Mockindes:", mockprofileIndex); if (Environment.useMockLogin) { - const user: Partial = Environment.getTestProfile(mockprofileIndex); + let user: Partial; + if (mockprofileIndex) { + user = Environment.getTestProfile(mockprofileIndex); + } else { + user = { + email: "email@some.hostname.of.some.mailserver.somewhere", + name: "Oauth profile name", + typeOfLogin: "google", + profileImage: "https://some.url.to.somewhere", + aggregateVerifier: "not-verified", + verifier: "not-verified", + verifierId: "not-verified", + }; + } return user as OpenloginUserInfo; } else { if (!this.web3auth) {