Commit 67ea0921 authored by dev0tion's avatar dev0tion

Make recovery form a reactive form

parent ec1245d5
...@@ -33,7 +33,11 @@ export class LoginComponent implements OnInit { ...@@ -33,7 +33,11 @@ export class LoginComponent implements OnInit {
private onDecryptClicked() { private onDecryptClicked() {
this.setGlobalWalletName(this.openWalletForm.get("selectWallet").value); this.setGlobalWalletName(this.openWalletForm.get("selectWallet").value);
let walletLoad = new WalletLoad(this.openWalletForm.get("password").value, this.globalService.getWalletPath(), 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); this.loadWallet(walletLoad);
} }
......
...@@ -22,14 +22,19 @@ export class CreateComponent { ...@@ -22,14 +22,19 @@ export class CreateComponent {
}); });
} }
private newWallet: WalletCreation;
private createWalletForm: FormGroup; private createWalletForm: FormGroup;
private newWallet: WalletCreation;
private responseMessage: string; private responseMessage: string;
private errorMessage: string; private errorMessage: string;
private onCreateClicked() { private onCreateClicked() {
this.newWallet = new WalletCreation(this.createWalletForm.get("walletPassword").value, this.createWalletForm.get("selectNetwork").value, this.globalService.getWalletPath(), this.createWalletForm.get("walletName").value); 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); this.createWallet(this.newWallet);
} }
......
...@@ -2,27 +2,27 @@ ...@@ -2,27 +2,27 @@
<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> </form>
\ No newline at end of file
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/services/api.service' import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { WalletRecovery } from '../../shared/classes/wallet-recovery'
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 +13,39 @@ import { WalletRecovery } from '../../shared/classes/wallet-recovery' ...@@ -9,26 +13,39 @@ import { WalletRecovery } from '../../shared/classes/wallet-recovery'
}) })
export class RecoverComponent implements OnInit { export class RecoverComponent implements OnInit {
constructor(private apiService: ApiService) { } constructor(private globalService: GlobalService, private apiService: ApiService, 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 onRecoverClicked(){
this.walletRecovery = new WalletRecovery(); this.walletRecovery = new WalletRecovery(
this.walletRecovery.mnemonic = mnemonic; this.recoverWalletForm.get("walletMnemonic").value,
this.walletRecovery.password = password; this.recoverWalletForm.get("walletPassword").value,
this.walletRecovery.folderPath = folderPath; this.recoverWalletForm.get("selectNetwork").value,
this.walletRecovery.name = name; this.globalService.getWalletPath(),
this.walletRecovery.network = network; 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 +60,4 @@ export class RecoverComponent implements OnInit { ...@@ -43,4 +60,4 @@ export class RecoverComponent implements OnInit {
} }
); );
} }
} }
\ No newline at end of file
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
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