Commit 380b60c0 authored by dev0tion's avatar dev0tion

Update login component to load Bitcoin and Stratis

parent 5403d689
...@@ -62,18 +62,43 @@ export class LoginComponent implements OnInit { ...@@ -62,18 +62,43 @@ export class LoginComponent implements OnInit {
} }
}; };
private updateWalletFileDisplay(walletName: string) { private getWalletFiles() {
this.openWalletForm.patchValue({selectWallet: walletName}) this.apiService.getWalletFiles()
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
let responseMessage = response.json();
this.wallets = responseMessage.walletsFiles;
this.globalService.setWalletPath(responseMessage.walletsPath);
if (this.wallets.length > 0) {
this.hasWallet = true;
for (let wallet in this.wallets) {
this.wallets[wallet] = this.wallets[wallet].slice(0, -12);
}
this.updateWalletFileDisplay(this.wallets[0]);
} else {
this.hasWallet = false;
}
}
},
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 onDecryptClicked() { private updateWalletFileDisplay(walletName: string) {
this.setGlobalWalletName(this.openWalletForm.get("selectWallet").value); this.openWalletForm.patchValue({selectWallet: walletName})
let walletLoad = new WalletLoad(
this.openWalletForm.get("password").value,
this.globalService.getWalletPath(),
this.openWalletForm.get("selectWallet").value
);
this.loadWallet(walletLoad);
} }
private onCreateClicked() { private onCreateClicked() {
...@@ -86,27 +111,21 @@ export class LoginComponent implements OnInit { ...@@ -86,27 +111,21 @@ export class LoginComponent implements OnInit {
} }
} }
private setGlobalWalletName(walletName: string) { private onDecryptClicked() {
this.globalService.setWalletName(walletName); this.globalService.setWalletName(this.openWalletForm.get("selectWallet").value);
let walletLoad = new WalletLoad(
this.openWalletForm.get("selectWallet").value,
this.openWalletForm.get("password").value
);
this.loadWallets(walletLoad);
} }
private getWalletFiles() { private loadWallets(walletLoad: WalletLoad) {
this.apiService.getWalletFiles() this.apiService.loadBitcoinWallet(walletLoad)
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
let responseMessage = response.json(); //Bitcoin wallet loaded
this.wallets = responseMessage.walletsFiles;
this.globalService.setWalletPath(responseMessage.walletsPath);
if (this.wallets.length > 0) {
this.hasWallet = true;
for (let wallet in this.wallets) {
this.wallets[wallet] = this.wallets[wallet].slice(0, -12);
}
this.updateWalletFileDisplay(this.wallets[0]);
} else {
this.hasWallet = false;
}
} }
}, },
error => { error => {
...@@ -123,14 +142,13 @@ export class LoginComponent implements OnInit { ...@@ -123,14 +142,13 @@ export class LoginComponent implements OnInit {
} }
) )
; ;
}
private loadWallet(walletLoad: WalletLoad) { this.apiService.loadStratisWallet(walletLoad)
this.apiService.loadWallet(walletLoad)
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
this.globalService.setWalletName(walletLoad.name) this.globalService.setCoinName("Bitcoin");
this.globalService.setWalletName(walletLoad.name);
this.globalService.setCoinType(1); this.globalService.setCoinType(1);
this.router.navigate(['/wallet']); this.router.navigate(['/wallet']);
} }
......
export class WalletLoad { export class WalletLoad {
constructor(password: string, folderPath: string, name: string) { constructor(name: string, password: string, folderPath: string = null ) {
this.name = name;
this.password = password; this.password = password;
this.folderPath = folderPath; this.folderPath = folderPath;
this.name = name;
} }
public password: string;
public folderPath: string;
public name: string; public name: string;
public password: string;
public folderPath?: string;
} }
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