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 @@ ...@@ -22,17 +22,17 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/animations": "^4.0.0", "@angular/animations": "^4.0.1",
"@angular/common": "^4.0.0", "@angular/common": "^4.0.1",
"@angular/compiler": "^4.0.0", "@angular/compiler": "^4.0.1",
"@angular/compiler-cli": "^4.0.0", "@angular/compiler-cli": "^4.0.1",
"@angular/core": "^4.0.0", "@angular/core": "^4.0.1",
"@angular/forms": "^4.0.0", "@angular/forms": "^4.0.1",
"@angular/http": "^4.0.0", "@angular/http": "^4.0.1",
"@angular/platform-browser": "^4.0.0", "@angular/platform-browser": "^4.0.1",
"@angular/platform-browser-dynamic": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.1",
"@angular/platform-server": "^4.0.0", "@angular/platform-server": "^4.0.1",
"@angular/router": "^4.0.0", "@angular/router": "^4.0.1",
"bootstrap": "^4.0.0-alpha.6", "bootstrap": "^4.0.0-alpha.6",
"core-js": "^2.4.1", "core-js": "^2.4.1",
"rxjs": "^5.2.0", "rxjs": "^5.2.0",
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
}, },
"devDependencies": { "devDependencies": {
"@angular/cli": "^1.0.0", "@angular/cli": "^1.0.0",
"@angular/compiler-cli": "^4.0.0", "@angular/compiler-cli": "^4.0.1",
"@types/electron": "^1.4.35", "@types/electron": "^1.4.35",
"@types/jasmine": "2.5.46", "@types/jasmine": "2.5.46",
"@types/node": "~7.0.12", "@types/node": "~7.0.12",
......
{
"/api/v1/wallet/": "/",
"/api/v1/create/": "/"
}
\ No newline at end of file
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.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') 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