-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathpopup-mode-login.ts
More file actions
65 lines (59 loc) · 2.03 KB
/
popup-mode-login.ts
File metadata and controls
65 lines (59 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ChangeDetectorRef, Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { TORUS_SAPPHIRE_NETWORK } from '@toruslabs/constants';
import { UX_MODE } from '@toruslabs/customauth';
import {
FormData,
networkOptions,
sapphireDevnetVerifierOptions,
testnetVerifierOptions,
WEB3AUTH_EMAIL_PASSWORDLESS,
WEB3AUTH_SMS_PASSWORDLESS,
} from '../config';
import { CustomAuthService } from '../custom-auth';
@Component({
selector: 'app-popup-mode-login',
imports: [FormsModule],
templateUrl: './popup-mode-login.html',
styleUrl: './popup-mode-login.css',
})
export class PopupModeLogin {
formData: FormData;
status: 'idle' | 'loading' | 'success' | 'error' = 'idle';
result = '';
private readonly popupTimeoutMs = 15000;
readonly networkOptions = networkOptions;
readonly sapphireDevnetVerifierOptions = sapphireDevnetVerifierOptions;
readonly testnetVerifierOptions = testnetVerifierOptions;
readonly emailPasswordless = WEB3AUTH_EMAIL_PASSWORDLESS;
readonly smsPasswordless = WEB3AUTH_SMS_PASSWORDLESS;
constructor(
private readonly authService: CustomAuthService,
private readonly cdr: ChangeDetectorRef,
) {
this.formData = this.authService.getDefaultFormData(UX_MODE.POPUP);
}
get verifierOptions(): string[] {
return this.formData.network === TORUS_SAPPHIRE_NETWORK.SAPPHIRE_DEVNET
? this.sapphireDevnetVerifierOptions
: this.testnetVerifierOptions;
}
async login(): Promise<void> {
this.status = 'loading';
this.result = '';
try {
const loginResult = await this.authService.triggerLogin(this.formData);
if (!loginResult) {
throw new Error('Popup login finished without returning a result.');
}
this.authService.saveLoginResult(loginResult);
this.result = this.authService.stringifyForDisplay(loginResult);
this.status = 'success';
this.cdr.detectChanges();
} catch (error) {
this.result = (error as Error).message;
this.status = 'error';
this.cdr.detectChanges();
}
}
}