Commit cc4ae9ee authored by Sergei Zubov's avatar Sergei Zubov

Modify wallets

Remove bitcoin and stratis wallet, add destream wallet
parent 88763a9f
......@@ -77,8 +77,7 @@ app.on('ready', function () {
console.log("Breeze UI was started in development mode. This requires the user to be running the Breeze Daemon himself.")
}
else {
startBitcoinApi();
startStratisApi();
startDeStreamApi();
}
createTray();
createWindow();
......@@ -88,8 +87,7 @@ app.on('ready', function () {
});
app.on('before-quit', function () {
closeBitcoinApi(),
closeStratisApi();
closeDeStreamApi();
});
// Quit when all windows are closed.
......@@ -109,24 +107,7 @@ app.on('activate', function () {
}
});
function closeBitcoinApi() {
// if (process.platform !== 'darwin' && !serve) {
if (!serve) {
var http1 = require('http');
const options1 = {
hostname: 'localhost',
port: 37220,
path: '/api/node/shutdown',
method: 'POST'
};
const req = http1.request(options1, (res) => {});
req.write('');
req.end();
}
};
function closeStratisApi() {
function closeDeStreamApi() {
// if (process.platform !== 'darwin' && !serve) {
if (process.platform !== 'darwin' && !serve) {
var http2 = require('http');
......@@ -143,42 +124,11 @@ function closeStratisApi() {
}
};
function startBitcoinApi() {
var bitcoinProcess;
const spawnBitcoin = require('child_process').spawn;
//Start Breeze Bitcoin Daemon
let apiPath = path.resolve(__dirname, 'assets//daemon//Stratis.BreezeD');
if (os.platform() === 'win32') {
apiPath = path.resolve(__dirname, '..\\..\\resources\\daemon\\Stratis.BreezeD.exe');
} else if(os.platform() === 'linux') {
apiPath = path.resolve(__dirname, '..//..//resources//daemon//Stratis.BreezeD');
} else {
apiPath = path.resolve(__dirname, '..//..//resources//daemon//Stratis.BreezeD');
}
if(!testnet) {
bitcoinProcess = spawnBitcoin(apiPath, {
detached: true
});
} else if (testnet) {
bitcoinProcess = spawnBitcoin(apiPath, ['-testnet'], {
detached: true
});
}
bitcoinProcess.stdout.on('data', (data) => {
writeLog(`Bitcoin: ${data}`);
});
}
function startStratisApi() {
var stratisProcess;
const spawnStratis = require('child_process').spawn;
function startDeStreamApi() {
var destreamProcess;
const spawnDeStream = require('child_process').spawn;
//Start Breeze Stratis Daemon
//Start Breeze DeStream Daemon
let apiPath = path.resolve(__dirname, 'assets//daemon//Stratis.BreezeD');
if (os.platform() === 'win32') {
apiPath = path.resolve(__dirname, '..\\..\\resources\\daemon\\Stratis.BreezeD.exe');
......@@ -189,17 +139,17 @@ function startStratisApi() {
}
if (!testnet) {
stratisProcess = spawnStratis(apiPath, ['stratis'], {
destreamProcess = spawnDeStream(apiPath, ['destream'], {
detached: true
});
} else if (testnet) {
stratisProcess = spawnStratis(apiPath, ['stratis', '-testnet'], {
destreamProcess = spawnDeStream(apiPath, ['destream', '-testnet'], {
detached: true
});
}
stratisProcess.stdout.on('data', (data) => {
writeLog(`Stratis: ${data}`);
destreamProcess.stdout.on('data', (data) => {
writeLog(`DeStream: ${data}`);
});
}
......
......@@ -23,11 +23,11 @@ export class AppComponent implements OnInit {
ngOnInit() {
this.setTitle();
this.apiService.getWalletFiles().retryWhen(errors => errors.delay(2000)).subscribe(() => this.checkStratisDaemon());
this.apiService.getWalletFiles().retryWhen(errors => errors.delay(2000)).subscribe(() => this.checkDeStreamDaemon());
}
private checkStratisDaemon() {
this.apiService.getStratisWalletFiles().retryWhen(errors => errors.delay(2000)).subscribe(() => this.startApp());
private checkDeStreamDaemon() {
this.apiService.getWalletFiles().retryWhen(errors => errors.delay(2000)).subscribe(() => this.startApp());
}
private startApp() {
......@@ -36,7 +36,7 @@ export class AppComponent implements OnInit {
}
private setTitle() {
const applicationName = "Stratis Breeze Wallet";
const applicationName = "DeStream Breeze Wallet";
const newTitle = applicationName + " v" + remote.app.getVersion();
this.titleService.setTitle(newTitle);
}
......
......@@ -127,33 +127,8 @@ export class LoginComponent implements OnInit {
}
private loadWallets(walletLoad: WalletLoad) {
this.apiService.loadBitcoinWallet(walletLoad)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
this.globalService.setWalletName(walletLoad.name);
}
},
error => {
this.isDecrypting = false;
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);
}
}
},
() => this.loadStratisWallet(walletLoad)
)
;
}
private loadStratisWallet(walletLoad: WalletLoad) {
this.apiService.loadStratisWallet(walletLoad)
this.apiService.loadDeStreamWallet(walletLoad)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
......@@ -180,19 +155,14 @@ export class LoginComponent implements OnInit {
private getCurrentNetwork() {
let walletInfo = new WalletInfo(this.globalService.getWalletName())
this.apiService.getGeneralInfoOnce(walletInfo)
this.apiService.getGeneralInfo(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");
}
this.globalService.setCoinName("DeStreamCoin");
this.globalService.setCoinUnit("DST");
}
},
error => {
......
......@@ -141,36 +141,7 @@ export class ConfirmMnemonicComponent implements OnInit {
private createWallets(wallet: WalletCreation) {
this.apiService
.createBitcoinWallet(wallet)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400){
// Bitcoin wallet created
}
},
error => {
console.log(error);
this.isCreating = false;
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);
this.router.navigate(['/setup/create']);
}
}
},
() => this.createStratisWallet(wallet)
)
;
}
private createStratisWallet(wallet: WalletCreation) {
this.apiService
.createStratisWallet(wallet)
.createDeStreamWallet(wallet)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400){
......
......@@ -114,39 +114,9 @@ export class RecoverComponent implements OnInit {
}
private recoverWallets(recoverWallet: WalletRecovery) {
let bitcoinErrorMessage = "";
let destreamErrorMessage = "";
this.apiService
.recoverBitcoinWallet(recoverWallet)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
//Bitcoin Wallet Recovered
}
this.recoverStratisWallet(recoverWallet, bitcoinErrorMessage);
},
error => {
this.isRecovering = false;
console.log(error);
if (error.status === 0) {
this.genericModalService.openModal(null, null);
} else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
bitcoinErrorMessage = error.json().errors[0].message;
}
}
this.recoverStratisWallet(recoverWallet, bitcoinErrorMessage);
}
)
;
}
private recoverStratisWallet(recoverWallet: WalletRecovery, bitcoinErrorMessage: string){
let stratisErrorMessage = "";
this.apiService
.recoverStratisWallet(recoverWallet)
.recoverDeStreamWallet(recoverWallet)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
......@@ -154,7 +124,7 @@ export class RecoverComponent implements OnInit {
this.genericModalService.openModal("Wallet Recovered", body);
this.router.navigate([''])
}
this.AlertIfNeeded(bitcoinErrorMessage, stratisErrorMessage);
this.AlertIfNeeded(destreamErrorMessage);
},
error => {
this.isRecovering = false;
......@@ -166,18 +136,18 @@ export class RecoverComponent implements OnInit {
console.log(error);
}
else {
stratisErrorMessage = error.json().errors[0].message;
destreamErrorMessage = error.json().errors[0].message;
}
}
this.AlertIfNeeded(bitcoinErrorMessage, stratisErrorMessage);
this.AlertIfNeeded(destreamErrorMessage);
}
)
;
}
private AlertIfNeeded(bitcoinErrorMessage: string, stratisErrorMessage: string) {
if(bitcoinErrorMessage !== "" || stratisErrorMessage !== "") {
let errorMessage = "<strong>Bitcoin wallet recovery:</strong><br>" + bitcoinErrorMessage + "<br><br><strong>Stratis wallet recovery:</strong><br>" + stratisErrorMessage;
private AlertIfNeeded(destreamErrorMessage: string) {
if(destreamErrorMessage !== "") {
let errorMessage = "<strong>DeStream wallet recovery:</strong><br>" + destreamErrorMessage;
this.genericModalService.openModal(null, errorMessage);
}
}
......
......@@ -27,34 +27,15 @@ export class ApiService {
private headers = new Headers({'Content-Type': 'application/json'});
private pollingInterval = 3000;
private bitcoinApiUrl = 'http://localhost:37220/api';
private stratisApiUrl = 'http://localhost:37221/api';
private currentApiUrl = 'http://localhost:37220/api';
private getCurrentCoin() {
let currentCoin = this.globalService.getCoinName();
if (currentCoin === "Bitcoin" || currentCoin === "TestBitcoin") {
this.currentApiUrl = this.bitcoinApiUrl;
} else if (currentCoin === "Stratis" || currentCoin === "TestStratis") {
this.currentApiUrl = this.stratisApiUrl;
}
}
private destreamApiUrl = 'http://localhost:56864/api';
private currentApiUrl = 'http://localhost:56864/api';
/**
* Gets available wallets at the default path
*/
getWalletFiles(): Observable<any> {
return this.http
.get(this.bitcoinApiUrl + '/wallet/files')
.map((response: Response) => response);
}
/**
* Gets available wallets at the default path
*/
getStratisWalletFiles(): Observable<any> {
return this.http
.get(this.stratisApiUrl + '/wallet/files')
.get(this.destreamApiUrl + '/wallet/files')
.map((response: Response) => response);
}
......@@ -67,61 +48,33 @@ export class ApiService {
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 Bitcoin wallet.
*/
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.stratisApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers})
.get(this.destreamApiUrl + '/wallet/mnemonic', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response);
}
/**
* Recover a Bitcoin wallet.
*/
recoverBitcoinWallet(data: WalletRecovery): Observable<any> {
return this.http
.post(this.bitcoinApiUrl + '/wallet/recover/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response);
}
/**
* Recover a Stratis wallet.
* Create a new DeStream wallet.
*/
recoverStratisWallet(data: WalletRecovery): Observable<any> {
createDeStreamWallet(data: WalletCreation): Observable<any> {
return this.http
.post(this.stratisApiUrl + '/wallet/recover/', JSON.stringify(data), {headers: this.headers})
.post(this.destreamApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response);
}
/**
* Load a Bitcoin wallet
* Recover a DeStream wallet.
*/
loadBitcoinWallet(data: WalletLoad): Observable<any> {
recoverDeStreamWallet(data: WalletRecovery): Observable<any> {
return this.http
.post(this.bitcoinApiUrl + '/wallet/load/', JSON.stringify(data), {headers: this.headers})
.post(this.destreamApiUrl + '/wallet/recover/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response);
}
/**
* Load a Stratis wallet
* Load a DeStream wallet
*/
loadStratisWallet(data: WalletLoad): Observable<any> {
loadDeStreamWallet(data: WalletLoad): Observable<any> {
return this.http
.post(this.stratisApiUrl + '/wallet/load/', JSON.stringify(data), {headers: this.headers})
.post(this.destreamApiUrl + '/wallet/load/', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response);
}
......@@ -129,30 +82,16 @@ export class ApiService {
* Get wallet status info from the API.
*/
getWalletStatus(): Observable<any> {
this.getCurrentCoin();
return this.http
.get(this.currentApiUrl + '/wallet/status')
.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.
*/
getGeneralInfo(data: WalletInfo): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('Name', data.walletName);
......@@ -168,7 +107,6 @@ export class ApiService {
* Get wallet balance info from the API.
*/
getWalletBalance(data: WalletInfo): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -184,7 +122,6 @@ export class ApiService {
* Get the maximum sendable amount for a given fee from the API
*/
getMaximumBalance(data): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -201,7 +138,6 @@ export class ApiService {
* Get a wallets transaction history info from the API.
*/
getWalletHistory(data: WalletInfo): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -217,7 +153,6 @@ export class ApiService {
* Get an unused receive address for a certain wallet from the API.
*/
getUnusedReceiveAddress(data: WalletInfo): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -231,7 +166,6 @@ export class ApiService {
* Get multiple unused receive addresses for a certain wallet from the API.
*/
getUnusedReceiveAddresses(data: WalletInfo, count: string): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -246,7 +180,6 @@ export class ApiService {
* Get get all receive addresses for an account of a wallet from the API.
*/
getAllReceiveAddresses(data: WalletInfo): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -260,7 +193,6 @@ export class ApiService {
* Estimate the fee of a transaction
*/
estimateFee(data: FeeEstimation): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
......@@ -279,7 +211,6 @@ export class ApiService {
* Build a transaction
*/
buildTransaction(data: TransactionBuilding): Observable<any> {
this.getCurrentCoin();
return this.http
.post(this.currentApiUrl + '/wallet/build-transaction', JSON.stringify(data), {headers: this.headers})
......@@ -290,7 +221,6 @@ export class ApiService {
* Send transaction
*/
sendTransaction(data: TransactionSending): Observable<any> {
this.getCurrentCoin();
return this.http
.post(this.currentApiUrl + '/wallet/send-transaction', JSON.stringify(data), {headers: this.headers})
......@@ -301,7 +231,6 @@ export class ApiService {
* Send shutdown signal to the daemon
*/
shutdownNode(): Observable<any> {
this.getCurrentCoin();
return this.http
.post(this.currentApiUrl + '/node/shutdown', '')
......
......@@ -3,7 +3,7 @@ import { Router, NavigationEnd } from '@angular/router';
import { ReplaySubject } from 'rxjs/ReplaySubject';
export enum Page {
Bitcoin, Stratis
DeStream
}
@Injectable()
......@@ -16,8 +16,7 @@ export class NavigationService {
.map(x => <NavigationEnd>x)
.map(x => x.url);
navigation$.filter(x => x === this.navBase).subscribe(_ => this.pageSubject.next(Page.Bitcoin));
navigation$.filter(x => x === `${this.navBase}/stratis-wallet`).subscribe(_ => this.pageSubject.next(Page.Stratis));
navigation$.filter(x => x === `${this.navBase}/destream-wallet`).subscribe(_ => this.pageSubject.next(Page.DeStream));
}
public pageSubject = new ReplaySubject(1);
......
......@@ -58,10 +58,15 @@ export class DashboardComponent implements OnInit {
this.walletBalanceSubscription = this.apiService.getWalletBalance(walletInfo)
.subscribe(
response => {
console.log("HJERE");
if (response.status >= 200 && response.status < 400) {
console.log("HJERE2");
let balanceResponse = response.json();
console.log(balanceResponse);
this.confirmedBalance = balanceResponse.balances[0].amountConfirmed;
console.log(balanceResponse.balances[0].amountConfirmed);
this.unconfirmedBalance = balanceResponse.balances[0].amountUnconfirmed;
console.log(balanceResponse.balances[0].amountUnconfirmed);
}
},
error => {
......
......@@ -81,6 +81,7 @@ export class HistoryComponent {
private getTransactionInfo(transactions: any) {
this.transactions = [];
console.log("hit it");
for (let transaction of transactions) {
let transactionType;
if (transaction.type === "send") {
......@@ -100,6 +101,12 @@ export class HistoryComponent {
let transactionTimestamp = transaction.timestamp;
let transactionConfirmed;
console.log("transactionType: " + transactionType);
console.log("transactionId: " + transactionId);
console.log("transactionAmount: " + transactionAmount);
console.log("transactionFee: " + transactionFee);
console.log("transactionConfirmedInBlock: " + transactionConfirmedInBlock);
console.log("transactionTimestamp: " + transactionTimestamp);
this.transactions.push(new TransactionInfo(transactionType, transactionId, transactionAmount, transactionFee, transactionConfirmedInBlock, transactionTimestamp));
}
}
......
......@@ -2,11 +2,7 @@
<aside id="sidebar">
<!-- menu-->
<ul class="list-unstyled menu">
<li (click)="loadBitcoinWallet()" [class.active]="bitcoinActive">
<img src="../../../assets/images/ico_bitcoin.svg" alt="Bitcoin">
<span class="bar"></span>
</li>
<li (click)="loadStratisWallet()" [class.active]="stratisActive">
<li (click)="loadDeStreamWallet()" [class.active]="stratisActive">
<img src="../../../assets/images/ico_stratis.svg" alt="Stratis">
<span class="bar"></span>
</li>
......
......@@ -20,47 +20,15 @@ export class SidebarComponent implements OnInit {
constructor(private globalService: GlobalService, private apiService: ApiService,
private router: Router, private modalService: NgbModal, private genericModalService: ModalService,
private navigationService: NavigationService) { }
public bitcoinActive: boolean;
public stratisActive: boolean;
ngOnInit() {
if (this.globalService.getCoinName() === "Bitcoin" || this.globalService.getCoinName() === "TestBitcoin") {
this.bitcoinActive = true;
this.stratisActive = false;
} else if (this.globalService.getCoinName() === "Stratis" || this.globalService.getCoinName() === "TestStratis") {
this.bitcoinActive = false;
this.stratisActive = true;
}
}
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");
}
public loadDestreamWallet() {
this.globalService.setCoinName("DeStreamCoin");
this.globalService.setCoinUnit("DST");
this.bitcoinActive = true;
this.stratisActive = false;
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.router.navigate(['/wallet/stratis-wallet']);
this.router.navigate(['/wallet/destream-wallet']);
}
public logOut() {
......
......@@ -15,7 +15,7 @@ const routes: Routes = [
{ path: 'advanced', component: AdvancedComponent }
]
},
{ path: 'stratis-wallet', component: WalletComponent,
{ path: 'destream-wallet', component: WalletComponent,
children: [
{ path: '', redirectTo:'dashboard', pathMatch:'full' },
{ path: 'dashboard', component: DashboardComponent },
......
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