Commit b4366998 authored by dev0tion's avatar dev0tion

Add wallet status call

parent 564c52a4
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { remote } from 'electron';
import { ApiService } from './shared/api/api.service';
@Component({
selector: 'app-root',
......@@ -8,19 +10,31 @@ import { Router } from '@angular/router';
})
export class AppComponent implements OnInit {
constructor(private router: Router) {}
constructor(private router: Router, private apiService: ApiService) {}
private errorMessage: string;
private response: any;
private isConfigured: boolean = true;
private checkConfigured(){
if (this.isConfigured) {
ngOnInit() {
this.response = this.checkWalletStatus();
}
private checkWalletStatus(){
this.apiService.getWalletStatus()
.subscribe(
response => this.response = response,
error => this.errorMessage = <any>error
);
if (this.response.success = "true") {
remote.dialog.showMessageBox({message: remote.app.getPath('userData')})
this.router.navigateByUrl('/wallet')
} else {
this.router.navigateByUrl('/setup')
}
}
ngOnInit() {
this.checkConfigured();
private hasWallet() {
return true;
}
}
\ No newline at end of file
......@@ -10,6 +10,9 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ApiService } from './shared/api/api.service';
@NgModule({
imports: [
AppRoutingModule,
......@@ -22,8 +25,8 @@ import { AppComponent } from './app.component';
declarations: [
AppComponent
],
providers: [],
bootstrap: [AppComponent]
providers: [ ApiService ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
\ No newline at end of file
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { SetupComponent } from './setup.component';
......@@ -11,13 +10,11 @@ import { ApiComponent } from './create/api.component';
import { SharedModule } from '../shared/shared.module';
import { SetupRoutingModule } from './setup-routing.module';
import { ApiService } from '../shared/api/api.service';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
SetupRoutingModule,
SharedModule
],
......@@ -26,7 +23,7 @@ import { ApiService } from '../shared/api/api.service';
SetupComponent,
ApiComponent
],
exports: [SetupComponent],
exports: [ SetupComponent ],
providers: []
})
......
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { Http, Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/catch';
import { SafeCreation } from '../safe-creation';
import { Mnemonic } from '../mnemonic';
......@@ -11,13 +11,21 @@ import { Mnemonic } from '../mnemonic';
export class ApiService {
constructor(private http: Http) {};
private webApiUrl = 'http://localhost:5000/api/v1';
private webApiUrl = 'http://localhost:3000/api/v1';
private headers = new Headers({'Content-Type': 'application/json'});
isConnected(): Observable<string> {
isConnected(): Observable<any> {
return this.http
.get(this.webApiUrl + '/safe/connected')
.map(data => data.json())
.map((response:Response) => response.json())
.catch(this.handleError);
}
getWalletStatus(): Observable<any> {
return this.http
.get(this.webApiUrl + '/wallet/status')
.map((response:Response) => response.json())
.catch(this.handleError);
}
createWallet(data: SafeCreation): Observable<any> {
......@@ -27,8 +35,16 @@ export class ApiService {
.map(response => response.json());
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
private handleError (error: Response | any) {
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { WalletComponent } from './wallet.component';
......@@ -18,7 +17,6 @@ import { WalletRoutingModule } from './wallet-routing.module';
imports: [
BrowserModule,
FormsModule,
HttpModule,
WalletRoutingModule,
SharedModule
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment