Unverified Commit f7c107e9 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Merge pull request #350 from stratisproject/ui

Make frontend network aware
parents 0ef810ed 313255eb
......@@ -11,8 +11,10 @@ const url = require('url');
const os = require('os');
let serve;
let testnet;
const args = process.argv.slice(1);
serve = args.some(val => val === "--serve");
testnet = args.some(val => val === "--testnet");
if (serve) {
require('electron-reload')(__dirname, {
......@@ -158,9 +160,16 @@ function startBitcoinApi() {
apiPath = path.resolve(__dirname, 'assets\\daemon\\Stratis.BreezeD.exe');
}
bitcoinProcess = spawnBitcoin(apiPath, ['-testnet'], {
if(!testnet) {
bitcoinProcess = spawnBitcoin(apiPath, {
detached: true
});
});
} else if (testnet) {
bitcoinProcess = spawnBitcoin(apiPath, ['-testnet'], {
detached: true
});
}
bitcoinProcess.stdout.on('data', (data) => {
writeLog(`Bitcoin: ${data}`);
......@@ -177,9 +186,16 @@ function startStratisApi() {
apiPath = path.resolve(__dirname, 'assets\\daemon\\Stratis.BreezeD.exe');
}
stratisProcess = spawnStratis(apiPath, ['stratis', '-testnet'], {
if (!testnet) {
stratisProcess = spawnStratis(apiPath, ['stratis'], {
detached: true
});
});
} else if (testnet) {
stratisProcess = spawnStratis(apiPath, ['stratis', '-testnet'], {
detached: true
});
}
stratisProcess.stdout.on('data', (data) => {
writeLog(`Stratis: ${data}`);
......
......@@ -7,6 +7,7 @@ import { ApiService } from '../shared/services/api.service';
import { ModalService } from '../shared/services/modal.service';
import { WalletLoad } from '../shared/classes/wallet-load';
import { WalletInfo } from '../shared/classes/wallet-info';
@Component({
selector: 'app-login',
......@@ -117,6 +118,7 @@ export class LoginComponent implements OnInit {
private onDecryptClicked() {
this.isDecrypting = true;
this.globalService.setWalletName(this.openWalletForm.get("selectWallet").value);
this.getCurrentNetwork();
let walletLoad = new WalletLoad(
this.openWalletForm.get("selectWallet").value,
this.openWalletForm.get("password").value
......@@ -129,11 +131,7 @@ export class LoginComponent implements OnInit {
.subscribe(
response => {
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.setCoinType(1);
}
},
error => {
......@@ -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 {
.map((response: Response) => response);
}
/**
* Get a new mnemonic
*/
......@@ -136,6 +135,18 @@ export class ApiService {
.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.
*/
......
......@@ -6,10 +6,10 @@ export class GlobalService {
private walletPath: string;
private currentWalletName: string;
private coinType: number = 0;
private coinName: string = "TestBitcoin";
private coinUnit: string = "TBTC";
private network: string = "TestNet";
private coinType: number;
private coinName: string;
private coinUnit: string;
private network: string;
getWalletPath() {
return this.walletPath;
......
......@@ -3,7 +3,11 @@ import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { LogoutConfirmationComponent } from '../logout-confirmation/logout-confirmation.component';
import { Router } from '@angular/router';
import { ApiService } from '../../shared/services/api.service';
import { GlobalService } from '../../shared/services/global.service';
import { ModalService } from '../../shared/services/modal.service';
import { WalletInfo } from '../../shared/classes/wallet-info';
@Component({
selector: 'sidebar',
......@@ -12,7 +16,7 @@ import { GlobalService } from '../../shared/services/global.service';
})
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 stratisActive: boolean;
......@@ -27,18 +31,32 @@ export class SidebarComponent implements OnInit {
}
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.stratisActive = false;
this.globalService.setCoinName("TestBitcoin");
this.globalService.setCoinUnit("TBTC");
this.router.navigate(['/wallet']);
}
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.stratisActive = true;
this.globalService.setCoinName("TestStratis");
this.globalService.setCoinUnit("TSTRAT");
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