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

Append a testnet=true query param if using testnet for the identity embed URL #595

Merged
merged 1 commit into from
Aug 24, 2022
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
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class AppComponent implements OnInit {
this.globalVars.jumioKickbackUSDCents = res.JumioKickbackUSDCents;
this.globalVars.isTestnet = res.IsTestnet;
this.identityService.isTestnet = res.IsTestnet;
this.identityService.setSanitizedIdentityServiceURL();
this.globalVars.showPhoneNumberVerification =
res.HasTwilioAPIKey && res.HasStarterDeSoSeed;
this.globalVars.createProfileFeeNanos = res.CreateProfileFeeNanos;
Expand Down
6 changes: 1 addition & 5 deletions src/app/global-vars.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { FollowChangeObservableResult } from '../lib/observable-results/follow-c
import { SwalHelper } from '../lib/helpers/swal-helper';
import { environment } from '../environments/environment';
import { AmplitudeClient } from 'amplitude-js';
import { DomSanitizer } from '@angular/platform-browser';
import { IdentityService } from './identity.service';
import {
BithuntService,
Expand Down Expand Up @@ -65,7 +64,6 @@ export class GlobalVarsService {

constructor(
private backendApi: BackendApiService,
private sanitizer: DomSanitizer,
private identityService: IdentityService,
private router: Router,
private httpClient: HttpClient
Expand Down Expand Up @@ -1051,9 +1049,7 @@ export class GlobalVarsService {
);
}
this.identityService.identityServiceURL = identityServiceURL;
this.identityService.sanitizedIdentityServiceURL = this.sanitizer.bypassSecurityTrustResourceUrl(
`${identityServiceURL}/embed?v=2`
);
this.identityService.setSanitizedIdentityServiceURL();

this._globopoll(() => {
if (!this.defaultFeeRateNanosPerKB) {
Expand Down
19 changes: 13 additions & 6 deletions src/app/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { v4 as uuid } from 'uuid';
import { HttpParams } from '@angular/common/http';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -34,7 +35,7 @@ export class IdentityService {
// Using testnet or mainnet
isTestnet = false;

constructor() {
constructor(private sanitizer: DomSanitizer) {
window.addEventListener('message', (event) => this.handleMessage(event));
}

Expand Down Expand Up @@ -181,11 +182,8 @@ export class IdentityService {
// Helpers

identityServiceParamsForKey(publicKey: string) {
const {
encryptedSeedHex,
accessLevel,
accessLevelHmac,
} = this.identityServiceUsers[publicKey];
const { encryptedSeedHex, accessLevel, accessLevelHmac } =
this.identityServiceUsers[publicKey];
return { encryptedSeedHex, accessLevel, accessLevelHmac };
}

Expand Down Expand Up @@ -299,4 +297,13 @@ export class IdentityService {
private respond(window: Window, id: string, payload: any): void {
window.postMessage({ id, service: 'identity', payload }, '*');
}

setSanitizedIdentityServiceURL(): void {
this.sanitizedIdentityServiceURL =
this.sanitizer.bypassSecurityTrustResourceUrl(
`${this.identityServiceURL}/embed?v=2${
this.isTestnet ? '&testnet=true' : ''
}`
);
}
}