Commit 313255eb authored by dev0tion's avatar dev0tion

Make frontend network aware

parent 8e42d5f3
...@@ -7,6 +7,7 @@ import { ApiService } from '../shared/services/api.service'; ...@@ -7,6 +7,7 @@ import { ApiService } from '../shared/services/api.service';
import { ModalService } from '../shared/services/modal.service'; import { ModalService } from '../shared/services/modal.service';
import { WalletLoad } from '../shared/classes/wallet-load'; import { WalletLoad } from '../shared/classes/wallet-load';
import { WalletInfo } from '../shared/classes/wallet-info';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
...@@ -117,6 +118,7 @@ export class LoginComponent implements OnInit { ...@@ -117,6 +118,7 @@ export class LoginComponent implements OnInit {
private onDecryptClicked() { private onDecryptClicked() {
this.isDecrypting = true; this.isDecrypting = true;
this.globalService.setWalletName(this.openWalletForm.get("selectWallet").value); this.globalService.setWalletName(this.openWalletForm.get("selectWallet").value);
this.getCurrentNetwork();
let walletLoad = new WalletLoad( let walletLoad = new WalletLoad(
this.openWalletForm.get("selectWallet").value, this.openWalletForm.get("selectWallet").value,
this.openWalletForm.get("password").value this.openWalletForm.get("password").value
...@@ -129,11 +131,7 @@ export class LoginComponent implements OnInit { ...@@ -129,11 +131,7 @@ export class LoginComponent implements OnInit {
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
// Set Bitcoin as the default wallet
this.globalService.setCoinName("TestBitcoin");
this.globalService.setCoinUnit("TBTC");
this.globalService.setWalletName(walletLoad.name); this.globalService.setWalletName(walletLoad.name);
this.globalService.setCoinType(1);
} }
}, },
error => { error => {
...@@ -179,4 +177,37 @@ export class LoginComponent implements OnInit { ...@@ -179,4 +177,37 @@ export class LoginComponent implements OnInit {
) )
; ;
} }
private getCurrentNetwork() {
let walletInfo = new WalletInfo(this.globalService.getWalletName())
this.apiService.getGeneralInfoOnce(walletInfo)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
let responseMessage = response.json();
this.globalService.setNetwork(responseMessage.network);
if (responseMessage.network === "Main") {
this.globalService.setCoinName("Bitcoin");
this.globalService.setCoinUnit("BTC");
} else if (responseMessage.network === "TestNet") {
this.globalService.setCoinName("TestBitcoin");
this.globalService.setCoinUnit("TBTC");
}
}
},
error => {
if (error.status === 0) {
this.genericModalService.openModal(null, null);
} else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
this.genericModalService.openModal(null, error.json().errors[0].message);
}
}
}
)
;
}
} }
...@@ -57,7 +57,6 @@ export class ApiService { ...@@ -57,7 +57,6 @@ export class ApiService {
.map((response: Response) => response); .map((response: Response) => response);
} }
/** /**
* Get a new mnemonic * Get a new mnemonic
*/ */
...@@ -136,6 +135,18 @@ export class ApiService { ...@@ -136,6 +135,18 @@ export class ApiService {
.map((response: Response) => response); .map((response: Response) => response);
} }
/**
* Get general wallet info from the API once.
*/
getGeneralInfoOnce(data: WalletInfo): Observable<any> {
let params: URLSearchParams = new URLSearchParams();
params.set('Name', data.walletName);
return this.http
.get(this.bitcoinApiUrl + '/wallet/general-info', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response);
}
/** /**
* Get general wallet info from the API. * Get general wallet info from the API.
*/ */
......
...@@ -6,10 +6,10 @@ export class GlobalService { ...@@ -6,10 +6,10 @@ export class GlobalService {
private walletPath: string; private walletPath: string;
private currentWalletName: string; private currentWalletName: string;
private coinType: number = 0; private coinType: number;
private coinName: string = "TestBitcoin"; private coinName: string;
private coinUnit: string = "TBTC"; private coinUnit: string;
private network: string = "TestNet"; private network: string;
getWalletPath() { getWalletPath() {
return this.walletPath; return this.walletPath;
......
...@@ -3,7 +3,11 @@ import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; ...@@ -3,7 +3,11 @@ import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { LogoutConfirmationComponent } from '../logout-confirmation/logout-confirmation.component'; import { LogoutConfirmationComponent } from '../logout-confirmation/logout-confirmation.component';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ApiService } from '../../shared/services/api.service';
import { GlobalService } from '../../shared/services/global.service'; import { GlobalService } from '../../shared/services/global.service';
import { ModalService } from '../../shared/services/modal.service';
import { WalletInfo } from '../../shared/classes/wallet-info';
@Component({ @Component({
selector: 'sidebar', selector: 'sidebar',
...@@ -12,7 +16,7 @@ import { GlobalService } from '../../shared/services/global.service'; ...@@ -12,7 +16,7 @@ import { GlobalService } from '../../shared/services/global.service';
}) })
export class SidebarComponent implements OnInit { export class SidebarComponent implements OnInit {
constructor(private globalService: GlobalService, private router: Router, private modalService: NgbModal) { } constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private modalService: NgbModal, private genericModalService: ModalService) { }
public bitcoinActive: boolean; public bitcoinActive: boolean;
public stratisActive: boolean; public stratisActive: boolean;
...@@ -27,18 +31,32 @@ export class SidebarComponent implements OnInit { ...@@ -27,18 +31,32 @@ export class SidebarComponent implements OnInit {
} }
public loadBitcoinWallet() { public loadBitcoinWallet() {
let currentNetwork = this.globalService.getNetwork();
if (currentNetwork === "Main") {
this.globalService.setCoinName("Bitcoin");
this.globalService.setCoinUnit("BTC");
} else if (currentNetwork === "TestNet"){
this.globalService.setCoinName("TestBitcoin");
this.globalService.setCoinUnit("TBTC");
}
this.bitcoinActive = true; this.bitcoinActive = true;
this.stratisActive = false; this.stratisActive = false;
this.globalService.setCoinName("TestBitcoin");
this.globalService.setCoinUnit("TBTC");
this.router.navigate(['/wallet']); this.router.navigate(['/wallet']);
} }
public loadStratisWallet() { public loadStratisWallet() {
let currentNetwork = this.globalService.getNetwork();
if (currentNetwork === "Main") {
this.globalService.setCoinName("Stratis");
this.globalService.setCoinUnit("STRAT");
} else if (currentNetwork === "TestNet"){
this.globalService.setCoinName("TestStratis");
this.globalService.setCoinUnit("TSTRAT");
}
this.bitcoinActive = false; this.bitcoinActive = false;
this.stratisActive = true; this.stratisActive = true;
this.globalService.setCoinName("TestStratis");
this.globalService.setCoinUnit("TSTRAT");
this.router.navigate(['/wallet/stratis-wallet']); this.router.navigate(['/wallet/stratis-wallet']);
} }
......
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