Skip to content

Commit

Permalink
Add support for did.request in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Oct 8, 2023
1 parent 6a06a3f commit 07de06e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 17 additions & 2 deletions angular/src/app/loading/loading.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class LoadingComponent implements OnInit, OnDestroy {
private orchestrator: OrchestratorService,
private runtime: RuntimeService,
@Inject(DOCUMENT) private document: Document
) {}
) { }

ngOnDestroy(): void {
if (this.sub) {
Expand All @@ -52,6 +52,18 @@ export class LoadingComponent implements OnInit, OnDestroy {
window.location.href = 'index.html';
}

hasJsonStructure(str: any) {
if (typeof str !== 'string') return false;
try {
const result = JSON.parse(str);
const type = Object.prototype.toString.call(result);
return type === '[object Object]'
|| type === '[object Array]';
} catch (err) {
return false;
}
}

instanceName: string;

async ngOnInit() {
Expand Down Expand Up @@ -133,10 +145,13 @@ export class LoadingComponent implements OnInit, OnDestroy {
}

if (parameters.action) {
// Transform the content to be displayed to user.
const parsedContent = this.hasJsonStructure(parameters.content) ? JSON.parse(parameters.content) : parameters.content;

this.uiState.action = {
action: parameters.action,
id: parameters.id,
content: JSON.parse(parameters.content), // Transform the content to be displayed to user.
content: parsedContent,
params: JSON.parse(parameters.params), // Transform the params from string to object here after we've received it through the query string.
app: parameters.app,
verify: verify,
Expand Down
14 changes: 12 additions & 2 deletions angular/src/app/services/frontend.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, OnInit, NgZone } from '@angular/core';
import { Injectable, OnInit, NgZone, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { DecentralizedWebNode, Message, MessageService } from 'src/shared';
import { BackgroundManager, ProcessResult } from 'src/shared/background-manager';
Expand All @@ -9,6 +9,7 @@ import { EventBus } from '../../shared/event-bus';
import { SettingsService } from './settings.service';
import { StateService } from './state.service';
import { WalletManager } from './wallet-manager';
import { DOCUMENT } from '@angular/common';

@Injectable({
providedIn: 'root',
Expand All @@ -21,6 +22,7 @@ export class FrontendService implements OnInit {
private indexing: boolean;

constructor(
@Inject(DOCUMENT) private document: Document,
private ngZone: NgZone,
private walletManager: WalletManager,
private events: EventBus,
Expand Down Expand Up @@ -78,6 +80,14 @@ export class FrontendService implements OnInit {
await this.state.refresh();
return 'ok';
}
case 'did.request': {
debugger;
const msg = message as any;
let url = msg.request.params[0].callback;
url = url.replace('%s', msg.key); // This is the DID.
this.document.location.href = url;
return 'ok';
}
case 'reload': {
// console.log('Wallet / Account might be deleted, so we must reload state.');
await this.state.reload();
Expand Down Expand Up @@ -186,7 +196,7 @@ export class FrontendService implements OnInit {
runIndexer = async () => {
// Stop and ensure watcher doesn't start up while indexer is running.
if (this.watchManager) {
this.watchManager.onStopped = () => {};
this.watchManager.onStopped = () => { };
this.watchManager.stop();
this.watchManager = null;
}
Expand Down

0 comments on commit 07de06e

Please sign in to comment.