Commit 36d50d41 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Switch to reactive forms, add pipes, improve navigation, various fixes (#35)

- Switch from template driven forms to reactive forms
- Add pipes for coin notation and coin abbreviation (tbc)
- Improve navigation, add lazy loading and back buttons
- Add classes for creation, recovery and loading of wallets
- Various small improvements
parents b0838544 f590db2a
...@@ -4,7 +4,10 @@ import { RouterModule, Routes } from '@angular/router'; ...@@ -4,7 +4,10 @@ import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
const routes: Routes = [ const routes: Routes = [
{ path: 'login', component: LoginComponent} { path: '', redirectTo: 'login', pathMatch: 'full'},
{ path: 'login', component: LoginComponent},
{ path: 'setup', loadChildren: 'app/setup/setup.module#SetupModule'},
{ path: 'wallet', loadChildren: 'app/wallet/wallet.module#WalletModule'}
]; ];
@NgModule({ @NgModule({
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ApiService } from './shared/api/api.service'; import { ApiService } from './shared/services/api.service';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
......
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { HttpModule } from '@angular/http'; import { HttpModule } from '@angular/http';
import { SetupModule } from './setup/setup.module';
import { WalletModule } from './wallet/wallet.module';
import { SharedModule } from './shared/shared.module'; import { SharedModule } from './shared/shared.module';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
...@@ -11,25 +10,25 @@ import { AppRoutingModule } from './app-routing.module'; ...@@ -11,25 +10,25 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
import { ApiService } from './shared/api/api.service'; import { ApiService } from './shared/services/api.service';
import { GlobalService } from './shared/services/global.service';
@NgModule({ @NgModule({
imports: [ imports: [
AppRoutingModule, AppRoutingModule,
BrowserModule, BrowserModule,
ReactiveFormsModule,
FormsModule,
HttpModule, HttpModule,
SetupModule,
WalletModule,
SharedModule.forRoot() SharedModule.forRoot()
], ],
declarations: [ declarations: [
AppComponent, AppComponent,
LoginComponent LoginComponent
], ],
providers: [ ApiService ], providers: [ ApiService, GlobalService ],
bootstrap: [ AppComponent ] bootstrap: [ AppComponent ]
}) })
export class AppModule { } export class AppModule { }
\ No newline at end of file
<h1>Welcome to Breeze</h1> <h1>Welcome to Breeze</h1>
<div *ngIf="hasWallet"> <form *ngIf="hasWallet" [formGroup]="openWalletForm" (ngSubmit)="onDecryptClicked()">
<p>Choose the wallet you want to open:</p> <p>Choose the wallet you want to open:</p>
<div class="form-group"> <div class="form-group">
<label for="walletLabel">Wallet to open:</label> <label>Select wallet name to open:</label>
<select name="wallet" #walletName (change)="walletChanged(walletName.value)"> <select class="form-control" formControlName="selectWallet">
<option *ngFor="let wallet of wallets" [value]="wallet">{{wallet}}</option> <option *ngFor="let wallet of wallets" [value]="wallet">{{wallet}}</option>
</select> </select>
</div> </div>
<p>Please enter your password to decrypt your wallet</p> <p>Please enter your password to decrypt your wallet</p>
<form (ngSubmit)="onSubmit()" #passwordForm="ngForm"> <div class="form-group">
<div class="form-group"> <label>Your password: </label>
<label for="password">Your password: </label> <input class="form-control" type="password" formControlName="password" placeholder="Enter password here">
<input type="password" class="form-control" id="password" [(ngModel)]="password" required name="password"> </div>
</div> <div class="form-group">
<button type="submit" class="btn btn-success">Decrypt</button> <button type="submit" [disabled]="!openWalletForm.valid" class="btn btn-success">Decrypt</button>
</form> </div>
<p></p> </form>
</div>
<div *ngIf="hasWallet;else no_wallet"> <div *ngIf="hasWallet;else no_wallet">
<p> If you like to create or restore a wallet please click the button below.</p> <p> If you like to create or restore a wallet please click the button below.</p>
</div> </div>
...@@ -24,4 +24,4 @@ ...@@ -24,4 +24,4 @@
<p> Looks like you're new here. Please create or restore a wallet.</p> <p> Looks like you're new here. Please create or restore a wallet.</p>
</ng-template> </ng-template>
<button type="button" (click)="clickedCreate()" class="btn btn-success">Create or restore wallet</button> <button type="button" (click)="onCreateClicked()" class="btn btn-success">Create or restore wallet</button>
\ No newline at end of file
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ApiService } from '../shared/api/api.service';
import { WalletLoad } from '../shared/wallet-load'; import { GlobalService } from '../shared/services/global.service';
import { ApiService } from '../shared/services/api.service';
import { WalletLoad } from '../shared/classes/wallet-load';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
...@@ -9,81 +12,91 @@ import { WalletLoad } from '../shared/wallet-load'; ...@@ -9,81 +12,91 @@ import { WalletLoad } from '../shared/wallet-load';
styleUrls: ['./login.component.css'] styleUrls: ['./login.component.css']
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
constructor(private apiService: ApiService, private router: Router) { } constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) {
this.openWalletForm = fb.group({
"selectWallet": ["", Validators.required],
"password": ["", Validators.required]
});
}
private walletLoad: WalletLoad; private openWalletForm: FormGroup;
private hasWallet: boolean = false; private hasWallet: boolean = false;
private currentWalletName: string; private wallets: [string];
private wallets: [any];
private walletPath: string;
private password: string;
private responseMessage: any;
private errorMessage: any;
ngOnInit() { ngOnInit() {
this.getWalletFiles();
}
private updateWalletFileDisplay(walletName: string) {
this.openWalletForm.patchValue({selectWallet: walletName})
}
private onDecryptClicked() {
this.setGlobalWalletName(this.openWalletForm.get("selectWallet").value);
let walletLoad = new WalletLoad(
this.openWalletForm.get("password").value,
this.globalService.getWalletPath(),
this.openWalletForm.get("selectWallet").value
);
this.loadWallet(walletLoad);
}
private onCreateClicked() {
this.router.navigate(['/setup']);
}
private setGlobalWalletName(walletName: string) {
this.globalService.setCurrentWalletName(walletName);
}
private getWalletFiles() {
this.apiService.getWalletFiles() this.apiService.getWalletFiles()
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.responseMessage=response; let responseMessage = response.json();
this.wallets = response.json().walletsFiles; this.wallets = responseMessage.walletsFiles;
this.walletPath = response.json().walletsPath; this.globalService.setWalletPath(responseMessage.walletsPath);
if (this.wallets.length > 0) { if (this.wallets.length > 0) {
this.hasWallet = true; this.hasWallet = true;
this.currentWalletName = this.wallets[0].slice(0, -5); for (let wallet in this.wallets) {
this.wallets[wallet] = this.wallets[wallet].slice(0, -5);
}
this.updateWalletFileDisplay(this.wallets[0]);
} else { } else {
this.hasWallet = false; this.hasWallet = false;
} }
} }
}, },
error => { error => {
this.errorMessage = <any>error; let errorMessage = <any>error;
if (error.status >= 400) { if (error.status >= 400) {
alert(this.errorMessage); alert(errorMessage);
console.log(this.errorMessage); console.log(errorMessage);
} }
} }
); );
} }
private onSubmit() { private loadWallet(walletLoad: WalletLoad) {
this.apiService.loadWallet(walletLoad)
this.walletLoad = new WalletLoad();
this.walletLoad.password = this.password;
this.walletLoad.name = this.currentWalletName;
this.walletLoad.folderPath = this.walletPath;
console.log(this.walletLoad);
this.apiService.loadWallet(this.walletLoad)
.subscribe( .subscribe(
response => { response => {
console.log(response); console.log(response);
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.responseMessage = response; let responseMessage = response.json();
this.router.navigate(['/wallet']); this.router.navigate(['/wallet']);
} }
}, },
error => { error => {
this.errorMessage = <any>error; let errorMessage = <any>error;
if (error.status === 403 && error.json().errors[0].message === "Wrong password, please try again.") { if (error.status === 403 && error.json().errors[0].message === "Wrong password, please try again.") {
alert("Wrong password, try again."); alert("Wrong password, try again.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(this.errorMessage); alert(errorMessage);
console.log(this.errorMessage); console.log(errorMessage);
} }
} }
); );
} }
}
private walletChanged(walletName: string) {
let walletNameNoJson: string = walletName.slice(0, -5);
this.currentWalletName = walletNameNoJson;
}
private clickedCreate() {
this.router.navigate(['/setup']);
}
}
\ No newline at end of file
...@@ -2,30 +2,33 @@ ...@@ -2,30 +2,33 @@
<h1> <h1>
Please create a new wallet. Please create a new wallet.
</h1> </h1>
<div class="form-group"> <form [formGroup]="createWalletForm" (ngSubmit)="onCreateClicked()">
<label for="name">Name:</label> <div class="form-group">
<input class="form-control" type="text" #walletName required> <label>Name:</label>
</div> <input class="form-control" formControlName="walletName" type="text" placeholder="Enter a name for your wallet.">
<div class="form-group"> </div>
<label for="password">Password:</label> <div class="form-group">
<input class="form-control" type="password" #walletPassword required> <label>Password:</label>
</div> <input class="form-control" formControlName="walletPassword" type="password" placeholder="Enter a password for your wallet.">
<div class="form-group"> </div>
<label for="networklabel">Network:</label> <div class="form-group">
<select name="network" #walletNetwork> <label>Network:</label>
<option value="main">Main</option> <select name="network" formControlName="selectNetwork">
<option value="test">Testnet</option> <option value="main">Main</option>
</select> <option value="test">Testnet</option>
</div> </select>
<div class="form-group"> </div>
<label for="path">Path:</label> <div class="form-group">
<input class="form-control" type="text" #walletPath required> <button type="submit" [disabled]="!createWalletForm.valid" class="btn btn-success">Create Wallet</button>
</div> </div>
<button type="submit" (click)="createWallet(walletPassword.value, walletNetwork.value, walletPath.value, walletName.value)">Create</button> </form>
<div> <div>
<label>Mnemonic:</label> <label>Mnemonic:</label>
</div> </div>
<div> <div>
<label>{{responseMessage}}</label> <label>{{responseMessage}}</label>
</div> </div>
</div> <div class="form-group">
\ No newline at end of file <button type="button" class="btn btn-success" (click)="onBackClicked()">Back</button>
</div>
</div>
import { Component, Injectable } from '@angular/core'; import { Component, Injectable } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { ApiService } from '../../shared/api/api.service'; import { GlobalService } from '../../shared/services/global.service';
import { ApiService } from '../../shared/services/api.service';
import { WalletCreation } from '../../shared/wallet-creation'; import { WalletCreation } from '../../shared/classes/wallet-creation';
import { Mnemonic } from '../../shared/mnemonic'; import { Mnemonic } from '../../shared/classes/mnemonic';
@Component({ @Component({
selector: 'create-component', selector: 'create-component',
...@@ -12,22 +15,37 @@ import { Mnemonic } from '../../shared/mnemonic'; ...@@ -12,22 +15,37 @@ import { Mnemonic } from '../../shared/mnemonic';
}) })
export class CreateComponent { export class CreateComponent {
constructor(private apiService: ApiService) {} constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) {
this.createWalletForm = fb.group({
"walletName": ["", Validators.required],
"walletPassword": ["", Validators.required],
"selectNetwork": ["main", Validators.required]
});
}
private createWalletForm: FormGroup;
private newWallet: WalletCreation; private newWallet: WalletCreation;
private responseMessage: string; private responseMessage: string;
private errorMessage: string; private errorMessage: string;
private createWallet(password: string, network: string, folderPath: string, name: string, ) { private onBackClicked() {
this.newWallet = new WalletCreation(); this.router.navigate(["/setup"]);
this.newWallet.password = password; }
this.newWallet.network = network;
this.newWallet.folderPath = folderPath; private onCreateClicked() {
this.newWallet.name = name; this.newWallet = new WalletCreation(
this.createWalletForm.get("walletPassword").value,
this.createWalletForm.get("selectNetwork").value,
this.globalService.getWalletPath(),
this.createWalletForm.get("walletName").value
);
this.createWallet(this.newWallet);
}
private createWallet(wallet: WalletCreation) {
this.apiService this.apiService
.createWallet(this.newWallet) .createWallet(wallet)
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400){ if (response.status >= 200 && response.status < 400){
......
...@@ -2,27 +2,30 @@ ...@@ -2,27 +2,30 @@
<p> <p>
Welcome, please complete the form below to recover your wallet. Welcome, please complete the form below to recover your wallet.
</p> </p>
<div class="form-group"> <form [formGroup]="recoverWalletForm" (ngSubmit)="onRecoverClicked()">
<label for="name">Mnemonic:</label> <div class="form-group">
<input class="form-control" type="text" #walletMnemonic required> <label>Mnemonic:</label>
</div> <input class="form-control" formControlName="walletMnemonic" type="text" placeholder="Enter your saved mnemonic.">
<div class="form-group"> </div>
<label for="name">Password:</label> <div class="form-group">
<input class="form-control" type="password" #walletPassword required> <label>Wallet password: </label>
</div> <input class="form-control" type="password" formControlName="walletPassword" placeholder="Enter password here.">
<div class="form-group"> </div>
<label for="name">Wallet Path:</label> <div class="form-group">
<input class="form-control" type="text" #walletPath required> <label>Name:</label>
</div> <input class="form-control" formControlName="walletName" type="text" placeholder="Enter a name for your wallet.">
<div class="form-group"> </div>
<label for="name">Wallet Name:</label> <div class="form-group">
<input class="form-control" type="text" #walletName required> <label>Network:</label>
</div> <select name="network" formControlName="selectNetwork">
<div class="form-group"> <option value="main">Main</option>
<label for="networklabel">Network:</label> <option value="test">Testnet</option>
<select name="network" #walletNetwork> </select>
<option value="main">Main</option> </div>
<option value="test">Testnet</option> <div class="form-group">
</select> <button type="submit" [disabled]="!recoverWalletForm.valid" class="btn btn-success">Recover Wallet</button>
</div> </div>
<button type="submit" (click)="recoverWallet(walletMnemonic.value, walletPassword.value, walletPath.value, walletName.value, walletNetwork.value)">Recover</button> <div class="form-group">
\ No newline at end of file <button type="button" class="btn btn-success" (click)="onBackClicked()">Back</button>
</div>
</form>
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/api/api.service' import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { WalletRecovery } from '../../shared/wallet-recovery' import { Router } from '@angular/router';
import { GlobalService } from '../../shared/services/global.service';
import { ApiService } from '../../shared/services/api.service';
import { WalletRecovery } from '../../shared/classes/wallet-recovery';
@Component({ @Component({
selector: 'app-recover', selector: 'app-recover',
...@@ -9,26 +14,43 @@ import { WalletRecovery } from '../../shared/wallet-recovery' ...@@ -9,26 +14,43 @@ import { WalletRecovery } from '../../shared/wallet-recovery'
}) })
export class RecoverComponent implements OnInit { export class RecoverComponent implements OnInit {
constructor(private apiService: ApiService) { } constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) {
this.recoverWalletForm = fb.group({
"walletMnemonic": ["", Validators.required],
"walletPassword": ["", Validators.required],
"walletName": ["", Validators.required],
"selectNetwork": ["main", Validators.required]
});
}
private recoverWalletForm: FormGroup;
private walletRecovery: WalletRecovery; private walletRecovery: WalletRecovery;
private responseMessage: string; private responseMessage: string;
private errorMessage: string; private errorMessage: string;
ngOnInit() { ngOnInit() {
} }
private recoverWallet(mnemonic: string, password: string, folderPath: string, name: string, network: string) { private onBackClicked() {
this.walletRecovery = new WalletRecovery(); this.router.navigate(["/setup"]);
this.walletRecovery.mnemonic = mnemonic; }
this.walletRecovery.password = password;
this.walletRecovery.folderPath = folderPath; private onRecoverClicked(){
this.walletRecovery.name = name; this.walletRecovery = new WalletRecovery(
this.walletRecovery.network = network; this.recoverWalletForm.get("walletMnemonic").value,
this.recoverWalletForm.get("walletPassword").value,
this.recoverWalletForm.get("selectNetwork").value,
this.globalService.getWalletPath(),
this.recoverWalletForm.get("walletName").value
);
this.recoverWallet(this.walletRecovery);
}
private recoverWallet(recoverWallet: WalletRecovery) {
this.apiService this.apiService
.recoverWallet(this.walletRecovery) .recoverWallet(recoverWallet)
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
...@@ -43,4 +65,4 @@ export class RecoverComponent implements OnInit { ...@@ -43,4 +65,4 @@ export class RecoverComponent implements OnInit {
} }
); );
} }
} }
\ No newline at end of file
...@@ -6,9 +6,10 @@ import { CreateComponent } from './create/create.component'; ...@@ -6,9 +6,10 @@ import { CreateComponent } from './create/create.component';
import { RecoverComponent } from './recover/recover.component'; import { RecoverComponent } from './recover/recover.component';
const routes: Routes = [ const routes: Routes = [
{ path: '', redirectTo: 'setup', pathMatch: 'full'},
{ path: 'setup', component: SetupComponent }, { path: 'setup', component: SetupComponent },
{ path: 'setup/create', component: CreateComponent }, { path: 'create', component: CreateComponent },
{ path: 'setup/recover', component: RecoverComponent } { path: 'recover', component: RecoverComponent }
]; ];
@NgModule({ @NgModule({
......
...@@ -5,5 +5,6 @@ ...@@ -5,5 +5,6 @@
<p> <p>
Users who have previously used Breeze, can choose to recover their wallet. Users who have previously used Breeze, can choose to recover their wallet.
</p> </p>
<button (click)="createWallet()">Create</button> <button (click)="onCreateClicked()">Create</button>
<button (click)="recoverWallet()">Recover</button> <button (click)="onRecoverClicked()">Recover</button>
\ No newline at end of file <button (click)="onBackClicked()">Back</button>
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import {Location} from '@angular/common';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
@Component({ @Component({
...@@ -7,12 +8,16 @@ import { Router } from '@angular/router'; ...@@ -7,12 +8,16 @@ import { Router } from '@angular/router';
styleUrls: ['./setup.component.css'], styleUrls: ['./setup.component.css'],
}) })
export class SetupComponent { export class SetupComponent {
constructor(private router: Router) {} constructor(private router: Router, private location: Location) {}
private createWallet() { private onCreateClicked() {
this.router.navigate(['/setup/create']) this.router.navigate(['/setup/create']);
} }
private recoverWallet() { private onRecoverClicked() {
this.router.navigate(['/setup/recover']) this.router.navigate(['/setup/recover']);
}
private onBackClicked() {
this.router.navigate(['']);
} }
} }
import { BrowserModule } from '@angular/platform-browser'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { SetupComponent } from './setup.component'; import { SetupComponent } from './setup.component';
import { CreateComponent } from './create/create.component'; import { CreateComponent } from './create/create.component';
...@@ -13,17 +12,17 @@ import { RecoverComponent } from './recover/recover.component'; ...@@ -13,17 +12,17 @@ import { RecoverComponent } from './recover/recover.component';
@NgModule({ @NgModule({
imports: [ imports: [
BrowserModule, CommonModule,
FormsModule, ReactiveFormsModule,
SetupRoutingModule, SetupRoutingModule,
SharedModule SharedModule.forRoot()
], ],
declarations: [ declarations: [
CreateComponent, CreateComponent,
SetupComponent, SetupComponent,
RecoverComponent RecoverComponent
], ],
exports: [ SetupComponent ], exports: [],
providers: [] providers: []
}) })
......
export class WalletCreation { export class WalletCreation {
constructor(password: string, network:string, folderPath: string, name: string) {
this.password = password;
this.network = network;
this.folderPath = folderPath;
this.name = name;
}
password: string; password: string;
network: string; network: string;
folderPath: string; folderPath: string;
......
export class WalletLoad {
constructor(password: string, folderPath: string, name: string) {
this.password = password;
this.folderPath = folderPath;
this.name = name;
}
private password: string;
private folderPath: string;
private name: string;
}
export class WalletRecovery { export class WalletRecovery {
constructor(mnemonic: string, password: string, network:string, folderPath: string, name: string) {
this.mnemonic = mnemonic;
this.password = password;
this.network = network;
this.folderPath = folderPath;
this.name = name;
}
mnemonic: string; mnemonic: string;
password: string; password: string;
folderPath: string; folderPath: string;
name: string; name: string;
network: string; network: string;
} }
\ No newline at end of file
import { CoinAbbreviationPipe } from './coin-abbreviation.pipe';
describe('CoinAbbreviationPipe', () => {
it('create an instance', () => {
const pipe = new CoinAbbreviationPipe();
expect(pipe).toBeTruthy();
});
});
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'coinAbbreviation'
})
export class CoinAbbreviationPipe implements PipeTransform {
transform(value: any): any {
if (!value) return value;
let abbreviationAdded = value + " BTC"
return abbreviationAdded;
}
}
import { CoinNotationPipe } from './coin-notation.pipe';
describe('CoinNotationPipe', () => {
it('create an instance', () => {
const pipe = new CoinNotationPipe();
expect(pipe).toBeTruthy();
});
});
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'coinNotation'
})
export class CoinNotationPipe implements PipeTransform {
transform(value: any): any {
if (!value) return value;
let coinNotation = Number(value).toFixed(8);
return coinNotation;
}
}
...@@ -4,10 +4,10 @@ import { Observable } from 'rxjs/Observable'; ...@@ -4,10 +4,10 @@ import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
import { WalletCreation } from '../wallet-creation'; import { WalletCreation } from '../classes/wallet-creation';
import { WalletRecovery } from '../wallet-recovery'; import { WalletRecovery } from '../classes/wallet-recovery';
import { WalletLoad } from '../wallet-load'; import { WalletLoad } from '../classes/wallet-load';
import { Mnemonic } from '../mnemonic'; import { Mnemonic } from '../classes/mnemonic';
/** /**
* For information on the API specification have a look at our Github: * For information on the API specification have a look at our Github:
...@@ -26,7 +26,7 @@ export class ApiService { ...@@ -26,7 +26,7 @@ export class ApiService {
*/ */
getWalletFiles(): Observable<any> { getWalletFiles(): Observable<any> {
return this.http return this.http
.get(this.mockApiUrl + '/wallet/files') .get(this.webApiUrl + '/wallet/files')
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -67,7 +67,7 @@ export class ApiService { ...@@ -67,7 +67,7 @@ export class ApiService {
} }
/** /**
* Get wallet balance info from the API. * Get wallet balance info from the API.
*/ */
getWalletBalance(): Observable<any> { getWalletBalance(): Observable<any> {
return this.http return this.http
......
import {Injectable} from "@angular/core";
@Injectable()
export class GlobalService {
constructor() {}
private walletPath: string;
private currentWalletName: string;
getWalletPath() {
return this.walletPath;
}
setWalletPath(walletPath: string) {
this.walletPath = walletPath;
}
getCurrentWalletName() {
return this.currentWalletName;
}
setCurrentWalletName(currentWalletName: string) {
this.currentWalletName = currentWalletName;
}
}
\ No newline at end of file
import { NgModule, ModuleWithProviders } from '@angular/core'; import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms'; import { CoinNotationPipe } from './pipes/coin-notation.pipe';
import { RouterModule } from '@angular/router'; import { CoinAbbreviationPipe } from './pipes/coin-abbreviation.pipe';
import { ApiService} from './api/api.service';
@NgModule({ @NgModule({
imports: [CommonModule, RouterModule], imports: [CommonModule],
declarations: [], declarations: [CoinNotationPipe, CoinAbbreviationPipe],
exports: [CommonModule, FormsModule, RouterModule] exports: [CoinNotationPipe, CoinAbbreviationPipe]
}) })
export class SharedModule { export class SharedModule {
static forRoot(): ModuleWithProviders { static forRoot(): ModuleWithProviders {
return { return {
ngModule: SharedModule, ngModule: SharedModule,
providers: [ApiService] providers: []
}; };
} }
} }
\ No newline at end of file
export class WalletLoad {
password: string;
folderPath: string;
name: string;
}
\ No newline at end of file
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/api/api.service' import { ApiService } from '../../shared/services/api.service'
@Component({ @Component({
selector: 'history-component', selector: 'history-component',
......
<p>Balance: {{confirmedBalance}}</p> <p>Balance: {{confirmedBalance | coinNotation | coinAbbreviation}}</p>
<p>Unconfirmed: {{unconfirmedBalance}}<p> <p>Unconfirmed: {{unconfirmedBalance | coinNotation | coinAbbreviation}}<p>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CoinNotationPipe } from '../../shared/pipes/coin-notation.pipe';
import { CoinAbbreviationPipe } from '../../shared/pipes/coin-abbreviation.pipe';
import { DashboardComponent } from './dashboard.component'; import { DashboardComponent } from './dashboard.component';
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/api/api.service'; import { ApiService } from '../../shared/services/api.service';
@Component({ @Component({
selector: 'dashboard-component', selector: 'dashboard-component',
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/api/api.service' import { ApiService } from '../../shared/services/api.service'
@Component({ @Component({
selector: 'receive-component', selector: 'receive-component',
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ApiService } from '../../shared/api/api.service'; import { ApiService } from '../../shared/services/api.service';
@Component({ @Component({
selector: 'send-component', selector: 'send-component',
......
...@@ -7,9 +7,10 @@ import { ReceiveComponent } from './receive/receive.component'; ...@@ -7,9 +7,10 @@ import { ReceiveComponent } from './receive/receive.component';
import { HistoryComponent } from './history/history.component'; import { HistoryComponent } from './history/history.component';
const routes: Routes = [ const routes: Routes = [
{ path: 'wallet', component: WalletComponent, { path: '', redirectTo: 'wallet', pathMatch: 'full' },
{ path: 'wallet', component: WalletComponent,
children: [ children: [
{ path: '', redirectTo:'send', pathMatch:'full' }, { path: '', redirectTo:'history', pathMatch:'full' },
{ path: 'send', component: SendComponent}, { path: 'send', component: SendComponent},
{ path: 'receive', component: ReceiveComponent}, { path: 'receive', component: ReceiveComponent},
{ path: 'history', component: HistoryComponent} { path: 'history', component: HistoryComponent}
......
import { BrowserModule } from '@angular/platform-browser'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { WalletComponent } from './wallet.component'; import { WalletComponent } from './wallet.component';
import { MenuComponent } from './menu/menu.component'; import { MenuComponent } from './menu/menu.component';
...@@ -10,16 +9,16 @@ import { SendComponent } from './send/send.component'; ...@@ -10,16 +9,16 @@ import { SendComponent } from './send/send.component';
import { ReceiveComponent } from './receive/receive.component'; import { ReceiveComponent } from './receive/receive.component';
import { HistoryComponent } from './history/history.component'; import { HistoryComponent } from './history/history.component';
import { SharedModule } from '../shared/shared.module'; import {SharedModule} from '../shared/shared.module';
import { WalletRoutingModule } from './wallet-routing.module'; import { WalletRoutingModule } from './wallet-routing.module';
@NgModule({ @NgModule({
imports: [ imports: [
BrowserModule, CommonModule,
FormsModule, FormsModule,
WalletRoutingModule, SharedModule.forRoot(),
SharedModule ReactiveFormsModule,
WalletRoutingModule
], ],
declarations: [ declarations: [
WalletComponent, WalletComponent,
...@@ -29,9 +28,7 @@ import { WalletRoutingModule } from './wallet-routing.module'; ...@@ -29,9 +28,7 @@ import { WalletRoutingModule } from './wallet-routing.module';
SendComponent, SendComponent,
HistoryComponent HistoryComponent
], ],
exports: [ exports: []
WalletComponent
]
}) })
export class WalletModule { } export class WalletModule { }
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