Commit d9cf0208 authored by dev0tion's avatar dev0tion

Update wallet creation to include Bitcoin and Stratis

parent 6418f25b
import { Component, Injectable } from '@angular/core';
import { Component, Injectable, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
......@@ -16,7 +16,7 @@ import { Mnemonic } from '../../shared/classes/mnemonic';
styleUrls: ['./create.component.css'],
})
export class CreateComponent {
export class CreateComponent implements OnInit {
constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) {
this.buildCreateForm();
}
......@@ -25,6 +25,10 @@ export class CreateComponent {
private newWallet: WalletCreation;
private mnemonic: string;
ngOnInit() {
this.getNewMnemonic();
}
private buildCreateForm(): void {
this.createWalletForm = this.fb.group({
"walletName": ["",
......@@ -95,22 +99,76 @@ export class CreateComponent {
}
private onCreateClicked() {
this.newWallet = new WalletCreation(
this.createWalletForm.get("walletPassword").value,
this.createWalletForm.get("selectNetwork").value,
this.globalService.getWalletPath(),
this.createWalletForm.get("walletName").value
if (this.mnemonic) {
this.newWallet = new WalletCreation(
this.createWalletForm.get("walletName").value,
this.mnemonic,
this.createWalletForm.get("walletPassword").value,
this.createWalletForm.get("selectNetwork").value
);
this.createWallet(this.newWallet);
this.createWallets(this.newWallet);
}
}
private createWallet(wallet: WalletCreation) {
private getNewMnemonic() {
this.apiService
.createWallet(wallet)
.getNewMnemonic()
.subscribe(
response => {
if (response.status >= 200 && response.status < 400){
this.mnemonic = response.json();
}
},
error => {
console.log(error);
if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
}
}
)
;
}
private createWallets(wallet: WalletCreation) {
this.apiService
.createBitcoinWallet(wallet)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400){
// Bitcoin wallet created
}
},
error => {
console.log(error);
if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
}
},
() => this.createStratisWallet(wallet)
)
;
}
private createStratisWallet(wallet: WalletCreation) {
this.apiService
.createStratisWallet(wallet)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400){
alert("Your wallet has been created.\n\nPlease write down your 12 word passphrase: \n" + this.mnemonic + "\n\nYou can recover your wallet on any computer with:\n- your passphrase AND\n- your password AND\n- the wallet creation time\n\nUnlike most other wallets if an attacker acquires your passphrase, it will not be able to hack your wallet without knowing your password. On the contrary, unlike other wallets, you will not be able to recover your wallet only with your passphrase if you lose your password.");
this.router.navigate(['']);
}
......
export class WalletCreation {
constructor(password: string, network:string, folderPath: string, name: string) {
constructor(name: string, mnemonic: string, password: string, network:string, folderPath: string = null ) {
this.name = name;
this.mnemonic = mnemonic;
this.password = password;
this.network = network;
this.folderPath = folderPath;
this.name = name;
}
name: string;
mnemonic: string;
password: string;
network: string;
folderPath: string;
name: string;
folderPath?: string;
}
......@@ -43,19 +43,39 @@ export class ApiService {
* Gets available wallets at the default path
*/
getWalletFiles(): Observable<any> {
return this.http
.get(this.bitcoinApiUrl + '/wallet/files')
.map((response: Response) => response);
return this.http
.get(this.bitcoinApiUrl + '/wallet/files')
.map((response: Response) => response);
}
/**
* Get a new mnemonic
*/
getNewMnemonic(): Observable<any> {
let params: URLSearchParams = new URLSearchParams();
params.set('language', 'English');
params.set('wordCount', '12');
return this.http
.get(this.bitcoinApiUrl + '/wallet/mnemonic', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response);
}
/**
* Create a new wallet.
* Create a new Bitcoin wallet.
*/
createWallet(data: WalletCreation): Observable<any> {
this.getCurrentCoin();
createBitcoinWallet(data: WalletCreation): Observable<any> {
return this.http
.post(this.bitcoinApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response);
}
/**
* Create a new Stratis wallet.
*/
createStratisWallet(data: WalletCreation): Observable<any> {
return this.http
.post(this.currentApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers})
.post(this.stratisApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response);
}
......
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