Commit e64dc99c authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Upgrade Angular, use JSON-Server for mock API data, add status call (#13)

- Upgrade Angular
- Use JSON-Server to provide mock API data
- Add wallet status call
parents d0e82faf a035ad9c
{
"status":
{
"success": "true",
"connectedNodeCount": "7",
"maxConnextedNodeCount": "8",
"headerChainHeight": "1048",
"trackingHeight": "1047",
"trackedTransactionCount": "306",
"trackedScriptPubKeyCount": "100",
"walletState": "syncingBlocks",
"historyChangeBump": "231321"
}
}
\ No newline at end of file
......@@ -22,17 +22,17 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/platform-server": "^4.0.0",
"@angular/router": "^4.0.0",
"@angular/animations": "^4.0.1",
"@angular/common": "^4.0.1",
"@angular/compiler": "^4.0.1",
"@angular/compiler-cli": "^4.0.1",
"@angular/core": "^4.0.1",
"@angular/forms": "^4.0.1",
"@angular/http": "^4.0.1",
"@angular/platform-browser": "^4.0.1",
"@angular/platform-browser-dynamic": "^4.0.1",
"@angular/platform-server": "^4.0.1",
"@angular/router": "^4.0.1",
"bootstrap": "^4.0.0-alpha.6",
"core-js": "^2.4.1",
"rxjs": "^5.2.0",
......@@ -40,7 +40,7 @@
},
"devDependencies": {
"@angular/cli": "^1.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/compiler-cli": "^4.0.1",
"@types/electron": "^1.4.35",
"@types/jasmine": "2.5.46",
"@types/node": "~7.0.12",
......
{
"/api/v1/wallet/": "/",
"/api/v1/create/": "/"
}
\ No newline at end of file
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.checkWalletStatus();
}
private checkWalletStatus(){
this.apiService.getWalletStatus()
.subscribe(
response => this.response = response.success,
error => this.errorMessage = <any>error
);
if (this.response = "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