Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Mocklogin & add min and maxdate to survey datepicker #414

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions shell/src/dapps/o-onboarding/processes/loginWithTorus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -132,11 +133,11 @@ const processDefinition = (processId: string) =>
onDone: [
{
cond: (context) => Environment.useMockLogin === true,
target: "useMockProfile",
target: "#useMockProfile",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state name or state id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id. it has both, but we're using id everywhere else.

},
{
cond: (context) => context.data.accountAddress === undefined,
target: "chooseFlow",
target: "#chooseFlow",
},
{
cond: (context) => context.data.accountAddress !== undefined,
Expand Down Expand Up @@ -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 = <GetWeb3AuthResult>{
async getUserInfo(): Promise<Partial<OpenloginUserInfo>> {
delete mockProfile.privateKey;
return mockProfile;
},
};

userInfo = <OpenloginUserInfo>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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const options = {
{#if $inviteUrl}
<span class="text-sm grow text-success">{$_("dapps.o-homepage.components.survey.userDataCollection.inviteValid")}</span>
{:else}
<button class="px-8 overflow-hidden transition-all transform grow btn btn-primary text-lg" on:click="{() => handleClick('openQRCode')}" disabled="{$inviteUrl}">
<button class="px-8 overflow-hidden text-lg transition-all transform grow btn btn-primary" on:click="{() => handleClick('openQRCode')}" disabled="{$inviteUrl}">
{$_("dapps.o-homepage.components.survey.button.scanInviteNow")}
</button>
{/if}
Expand All @@ -287,13 +287,13 @@ const options = {
{/if}
<div class="flex flex-row justify-between w-full pr-4 mt-10 mb-5 text-center">
<div>
<button class="relative px-8 overflow-hidden transition-all transform btn bg-cpurple border-warning text-warning text-lg" on:click="{() => handleClick('back')}">
<button class="relative px-8 overflow-hidden text-lg transition-all transform btn bg-cpurple border-warning text-warning" on:click="{() => handleClick('back')}">
{$_("dapps.o-homepage.components.survey.button.goBack")}</button>
</div>
<div>
{#if $myForm.dirty}
<button
class="relative px-8 overflow-hidden transition-all transform btn btn-primary bg-primary text-cpurple text-lg"
class="relative px-8 overflow-hidden text-lg transition-all transform btn btn-primary bg-primary text-cpurple"
on:click="{() => handleClick('next')}"
disabled="{!$myForm.valid}">
{$_("dapps.o-homepage.components.survey.button.next")}</button>
Expand Down
17 changes: 15 additions & 2 deletions shell/src/shared/web3AuthNoModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenloginUserInfo> = Environment.getTestProfile(mockprofileIndex);
let user: Partial<OpenloginUserInfo>;
if (mockprofileIndex) {
user = Environment.getTestProfile(mockprofileIndex);
} else {
user = {
email: "[email protected]",
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) {
Expand Down
Loading