Commit 2e591cb6 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Change wallet detection, login and logout functionality (#28)

- Use /wallet/files to see if the user has created a wallet on the default path (instead of /wallet/status)
- Change load function to POST
- Added login and logout functionality
- Enabled wallet loading
- Various small fixes
parents bb09b023 f36ed56e
{ {
"create": "files": {
{ "walletsPath": "/home/dev0tion/Desktop/Wallets",
"mnemonic": "foo bar buz" "walletsFiles": [
}, "myFirstWallet.json",
"load": "mySecondWallet.json"
{ ]
"success": "true"
}, },
"status": "status":
{ {
......
...@@ -8,7 +8,7 @@ const routes: Routes = [ ...@@ -8,7 +8,7 @@ const routes: Routes = [
]; ];
@NgModule({ @NgModule({
imports: [ RouterModule.forRoot(routes) ], imports: [ RouterModule.forRoot(routes, {useHash: true}) ],
exports: [ RouterModule ] exports: [ RouterModule ]
}) })
......
...@@ -15,25 +15,26 @@ export class AppComponent implements OnInit { ...@@ -15,25 +15,26 @@ export class AppComponent implements OnInit {
private responseMessage: any; private responseMessage: any;
ngOnInit() { ngOnInit() {
this.checkWalletStatus(); this.router.navigate(['/login']);
//this.checkWalletStatus();
} }
private checkWalletStatus(){ // private checkWalletStatus(){
this.apiService.getWalletStatus() // this.apiService.getWalletStatus()
.subscribe( // .subscribe(
response => { // response => {
if (response.status >= 200 && response.status < 400) { // if (response.status >= 200 && response.status < 400) {
this.responseMessage = response; // this.responseMessage = response;
this.router.navigate(['/login']); // this.router.navigate(['/login']);
} // }
}, // },
error => { // error => {
this.errorMessage = <any>error; // this.errorMessage = <any>error;
if (error.status === 400 || error.status === 404) { // if (error.status === 400 || error.status === 404) {
this.router.navigate(['/setup']); // this.router.navigate(['/setup']);
console.log(this.errorMessage); // console.log(this.errorMessage);
} // }
} // }
); // );
} // }
} }
\ No newline at end of file
<h1>Welcome back</h1> <h1>Welcome to Breeze</h1>
<p>Please enter your password to decrypt your wallet</p> <div *ngIf="hasWallet">
<form (ngSubmit)="onSubmit()" #passwordForm="ngForm"> <p>Choose the wallet you want to open:</p>
<div class="form-group"> <div class="form-group">
<label for="password">Your password: </label> <label for="walletLabel">Wallet to open:</label>
<input type="password" class="form-control" id="password" required name="password"> <select name="wallet" #walletName (change)="walletChanged(walletName.value)">
<option *ngFor="let wallet of wallets" [value]="wallet">{{wallet}}</option>
</select>
</div> </div>
<button type="submit" class="btn btn-success">Decrypt</button> <p>Please enter your password to decrypt your wallet</p>
</form> <form (ngSubmit)="onSubmit()" #passwordForm="ngForm">
\ No newline at end of file <div class="form-group">
<label for="password">Your password: </label>
<input type="password" class="form-control" id="password" [(ngModel)]="password" required name="password">
</div>
<button type="submit" class="btn btn-success">Decrypt</button>
</form>
<p></p>
</div>
<div *ngIf="hasWallet;else no_wallet">
<p> If you like to create or restore a wallet please click the button below.</p>
</div>
<ng-template #no_wallet>
<p> Looks like you're new here. Please create or restore a wallet.</p>
</ng-template>
<button type="button" (click)="clickedCreate()" class="btn btn-success">Create or restore wallet</button>
\ No newline at end of file
...@@ -10,35 +10,80 @@ import { WalletLoad } from '../shared/wallet-load'; ...@@ -10,35 +10,80 @@ import { WalletLoad } from '../shared/wallet-load';
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
constructor(private apiService: ApiService, private router: Router) { } constructor(private apiService: ApiService, private router: Router) { }
private walletLoad: WalletLoad;
private hasWallet: boolean = false;
private currentWalletName: string;
private wallets: [any];
private walletPath: string;
private password: string;
private responseMessage: any; private responseMessage: any;
private errorMessage: any; private errorMessage: any;
private walletLoad: WalletLoad;
ngOnInit() { ngOnInit() {
this.apiService.getWalletFiles()
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
this.responseMessage=response;
this.wallets = response.json().walletsFiles;
this.walletPath = response.json().walletsPath;
if (this.wallets.length > 0) {
this.hasWallet = true;
this.currentWalletName = this.wallets[0].slice(0, -5);
} else {
this.hasWallet = false;
}
}
},
error => {
this.errorMessage = <any>error;
if (error.status >= 400) {
alert(this.errorMessage);
console.log(this.errorMessage);
}
}
);
} }
private onSubmit() { private onSubmit() {
this.walletLoad = new WalletLoad(); this.walletLoad = new WalletLoad();
this.walletLoad.password = "123"; this.walletLoad.password = this.password;
this.walletLoad.name = "test" this.walletLoad.name = this.currentWalletName;
this.walletLoad.folderPath = "folderPath" this.walletLoad.folderPath = this.walletPath;
console.log(this.walletLoad);
this.apiService.loadWallet(this.walletLoad) this.apiService.loadWallet(this.walletLoad)
.subscribe( .subscribe(
response => { response => {
console.log(response);
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.responseMessage = response; this.responseMessage = response;
this.router.navigate['/wallet'] this.router.navigate(['/wallet']);
} }
}, },
error => { error => {
this.errorMessage = <any>error; this.errorMessage = <any>error;
if (error.status >= 400) { if (error.status === 403 && error.json().errors[0].message === "Wrong password, please try again.") {
alert("Wrong password, try again.");
} else if (error.status >= 400) {
alert(this.errorMessage); alert(this.errorMessage);
console.log(this.errorMessage); console.log(this.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
...@@ -31,7 +31,7 @@ export class CreateComponent { ...@@ -31,7 +31,7 @@ export class CreateComponent {
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400){ if (response.status >= 200 && response.status < 400){
this.responseMessage = response; this.responseMessage = response.json();
} }
}, },
error => { error => {
......
<h1>Welcome to Breeze. Looks like you're new here.</h1> <h1>Welcome to Breeze.</h1>
<p> <p>
If you haven't used Breeze before, please create a new wallet. If you haven't used Breeze before, please create a new wallet.
</p> </p>
......
...@@ -21,6 +21,15 @@ export class ApiService { ...@@ -21,6 +21,15 @@ export class ApiService {
private webApiUrl = 'http://localhost:5000/api/v1'; private webApiUrl = 'http://localhost:5000/api/v1';
private headers = new Headers({'Content-Type': 'application/json'}); private headers = new Headers({'Content-Type': 'application/json'});
/**
* Gets available wallets at the default path
*/
getWalletFiles(): Observable<any> {
return this.http
.get(this.mockApiUrl + '/wallet/files')
.map((response: Response) => response);
}
/** /**
* Create a new wallet. * Create a new wallet.
*/ */
...@@ -44,7 +53,7 @@ export class ApiService { ...@@ -44,7 +53,7 @@ export class ApiService {
*/ */
loadWallet(data: WalletLoad): Observable<any> { loadWallet(data: WalletLoad): Observable<any> {
return this.http return this.http
.get(this.webApiUrl + '/wallet/load/', {headers: this.headers, body: JSON.stringify(data)}) .post(this.webApiUrl + '/wallet/load/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -62,7 +71,7 @@ export class ApiService { ...@@ -62,7 +71,7 @@ export class ApiService {
*/ */
getWalletBalance(): Observable<any> { getWalletBalance(): Observable<any> {
return this.http return this.http
.get(this.webApiUrl + '/wallet/balance') .get(this.mockApiUrl + '/wallet/balance')
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -71,7 +80,7 @@ export class ApiService { ...@@ -71,7 +80,7 @@ export class ApiService {
*/ */
getWalletHistory(): Observable<any> { getWalletHistory(): Observable<any> {
return this.http return this.http
.get(this.webApiUrl + '/wallet/history') .get(this.mockApiUrl + '/wallet/history')
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -80,9 +89,7 @@ export class ApiService { ...@@ -80,9 +89,7 @@ export class ApiService {
*/ */
getUnusedReceiveAddresses(): Observable<any> { getUnusedReceiveAddresses(): Observable<any> {
return this.http return this.http
.get(this.webApiUrl + '/wallet/receive') .get(this.mockApiUrl + '/wallet/receive')
.map((response: Response) => response); .map((response: Response) => response);
} }
}
} }
...@@ -23,7 +23,7 @@ export class HistoryComponent { ...@@ -23,7 +23,7 @@ export class HistoryComponent {
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.transactions = response.history; this.transactions = response.json().history;
} }
}, },
error => { error => {
......
...@@ -23,7 +23,7 @@ export class DashboardComponent { ...@@ -23,7 +23,7 @@ export class DashboardComponent {
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.balanceResponse = response this.balanceResponse = response.json();
this.confirmedBalance = this.balanceResponse.confirmed; this.confirmedBalance = this.balanceResponse.confirmed;
this.unconfirmedBalance = this.balanceResponse.unconfirmed; this.unconfirmedBalance = this.balanceResponse.unconfirmed;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<li class="nav-item"><a class="nav-link" routerLink="send">Send</a></li> <li class="nav-item"><a class="nav-link" routerLink="send">Send</a></li>
<li class="nav-item"><a class="nav-link" routerLink="receive">Receive</a></li> <li class="nav-item"><a class="nav-link" routerLink="receive">Receive</a></li>
<li class="nav-item"><a class="nav-link" routerLink="history">History</a></li> <li class="nav-item"><a class="nav-link" routerLink="history">History</a></li>
<li class="nav-item"><a class="nav-link" (click)="logOut()">Logout</a></li>
</ul> </ul>
</div> </div>
</nav> </nav>
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({ @Component({
selector: 'app-menu', selector: 'app-menu',
...@@ -6,5 +7,9 @@ import { Component } from '@angular/core'; ...@@ -6,5 +7,9 @@ import { Component } from '@angular/core';
styleUrls: ['./menu.component.css'], styleUrls: ['./menu.component.css'],
}) })
export class MenuComponent { export class MenuComponent {
constructor(private router: Router) {}
private logOut() {
this.router.navigate(['/login']);
}
} }
...@@ -23,7 +23,7 @@ export class ReceiveComponent { ...@@ -23,7 +23,7 @@ export class ReceiveComponent {
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.addresses = response.addresses; this.addresses = response.json().addresses;
} }
}, },
error => { error => {
......
...@@ -15,7 +15,7 @@ let mainWindow = null; ...@@ -15,7 +15,7 @@ let mainWindow = null;
function createWindow () { function createWindow () {
setTimeout(() => { setTimeout(() => {
// Create the browser window. // Create the browser window.
mainWindow = new BrowserWindow({width: 1000, height: 600, frame: true, minWidth: 1000, minHeight: 600, icon: "./assets/images/stratis-tray.png"}) mainWindow = new BrowserWindow({width: 1000, height: 600, frame: true, minWidth: 1000, minHeight: 600, icon: "./src/assets/images/stratis-tray.png"})
mainWindow.loadURL(url.format({ mainWindow.loadURL(url.format({
pathname: 'localhost:4200', pathname: 'localhost:4200',
......
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