Commit b4366998 authored by dev0tion's avatar dev0tion

Add wallet status call

parent 564c52a4
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { remote } from 'electron';
import { ApiService } from './shared/api/api.service';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
...@@ -8,19 +10,31 @@ import { Router } from '@angular/router'; ...@@ -8,19 +10,31 @@ import { Router } from '@angular/router';
}) })
export class AppComponent implements OnInit { 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 isConfigured: boolean = true;
private checkConfigured(){ ngOnInit() {
if (this.isConfigured) { 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') this.router.navigateByUrl('/wallet')
} else { } else {
this.router.navigateByUrl('/setup') this.router.navigateByUrl('/setup')
} }
} }
ngOnInit() { private hasWallet() {
this.checkConfigured(); return true;
} }
} }
\ No newline at end of file
...@@ -10,6 +10,9 @@ import { AppRoutingModule } from './app-routing.module'; ...@@ -10,6 +10,9 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { ApiService } from './shared/api/api.service';
@NgModule({ @NgModule({
imports: [ imports: [
AppRoutingModule, AppRoutingModule,
...@@ -22,8 +25,8 @@ import { AppComponent } from './app.component'; ...@@ -22,8 +25,8 @@ import { AppComponent } from './app.component';
declarations: [ declarations: [
AppComponent AppComponent
], ],
providers: [], providers: [ ApiService ],
bootstrap: [AppComponent] bootstrap: [ AppComponent ]
}) })
export class AppModule { } export class AppModule { }
\ No newline at end of file
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { SetupComponent } from './setup.component'; import { SetupComponent } from './setup.component';
...@@ -11,13 +10,11 @@ import { ApiComponent } from './create/api.component'; ...@@ -11,13 +10,11 @@ import { ApiComponent } from './create/api.component';
import { SharedModule } from '../shared/shared.module'; import { SharedModule } from '../shared/shared.module';
import { SetupRoutingModule } from './setup-routing.module'; import { SetupRoutingModule } from './setup-routing.module';
import { ApiService } from '../shared/api/api.service';
@NgModule({ @NgModule({
imports: [ imports: [
BrowserModule, BrowserModule,
FormsModule, FormsModule,
HttpModule,
SetupRoutingModule, SetupRoutingModule,
SharedModule SharedModule
], ],
...@@ -26,7 +23,7 @@ import { ApiService } from '../shared/api/api.service'; ...@@ -26,7 +23,7 @@ import { ApiService } from '../shared/api/api.service';
SetupComponent, SetupComponent,
ApiComponent ApiComponent
], ],
exports: [SetupComponent], exports: [ SetupComponent ],
providers: [] providers: []
}) })
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http'; import { Http, Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise'; import 'rxjs/add/operator/catch';
import { SafeCreation } from '../safe-creation'; import { SafeCreation } from '../safe-creation';
import { Mnemonic } from '../mnemonic'; import { Mnemonic } from '../mnemonic';
...@@ -11,13 +11,21 @@ import { Mnemonic } from '../mnemonic'; ...@@ -11,13 +11,21 @@ import { Mnemonic } from '../mnemonic';
export class ApiService { export class ApiService {
constructor(private http: Http) {}; 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'}); private headers = new Headers({'Content-Type': 'application/json'});
isConnected(): Observable<string> { isConnected(): Observable<any> {
return this.http return this.http
.get(this.webApiUrl + '/safe/connected') .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> { createWallet(data: SafeCreation): Observable<any> {
...@@ -27,8 +35,16 @@ export class ApiService { ...@@ -27,8 +35,16 @@ export class ApiService {
.map(response => response.json()); .map(response => response.json());
} }
private handleError(error: any): Promise<any> { private handleError (error: Response | any) {
console.error('An error occurred', error); let errMsg: string;
return Promise.reject(error.message || error); 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 { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { WalletComponent } from './wallet.component'; import { WalletComponent } from './wallet.component';
...@@ -18,7 +17,6 @@ import { WalletRoutingModule } from './wallet-routing.module'; ...@@ -18,7 +17,6 @@ import { WalletRoutingModule } from './wallet-routing.module';
imports: [ imports: [
BrowserModule, BrowserModule,
FormsModule, FormsModule,
HttpModule,
WalletRoutingModule, WalletRoutingModule,
SharedModule 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