Skip to content

Commit

Permalink
Merge 4b3a865 into 5cd84bf
Browse files Browse the repository at this point in the history
  • Loading branch information
pciavald authored Dec 21, 2017
2 parents 5cd84bf + 4b3a865 commit dc5a6e9
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 95 deletions.
35 changes: 17 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,19 @@
"asar": true
},
"dependencies": {
"@angular/animations": "^5.0.3",
"@angular/cdk": "2.0.0-beta.12",

"@angular/common": "^5.0.3",
"@angular/compiler": "^5.0.3",
"@angular/core": "^5.0.3",
"@angular/flex-layout": "^2.0.0-beta.10-4905443",
"@angular/forms": "^5.0.3",
"@angular/http": "^5.0.3",
"@angular/material": "2.0.0-beta.12",
"@angular/platform-browser": "^5.0.3",
"@angular/platform-browser-dynamic": "^5.0.3",
"@angular/platform-server": "^5.0.3",
"@angular/router": "^5.0.3",
"@angular/animations": "^5.1.2",
"@angular/cdk": "^5.0.2",
"@angular/common": "^5.1.2",
"@angular/compiler": "^5.1.2",
"@angular/core": "^5.1.2",
"@angular/flex-layout": "^2.0.0-beta.12",
"@angular/forms": "^5.1.2",
"@angular/http": "^5.1.2",
"@angular/material": "^5.0.2",
"@angular/platform-browser": "^5.1.2",
"@angular/platform-browser-dynamic": "^5.1.2",
"@angular/platform-server": "^5.1.2",
"@angular/router": "^5.1.2",
"angular2-qrcode": "^2.0.1",
"bluebird": "^3.4.7",
"buffered-spawn": "^3.3.2",
Expand All @@ -124,13 +123,13 @@
"node-unzip-2": "^0.2.1",
"open-sans-all": "^0.1.3",
"rx-ipc-electron": "^0.1.2",
"rxjs": "5.5.0",
"rxjs": "5.5.2",
"tmp": "0.0.33",
"zone.js": "0.8.18"
},
"devDependencies": {
"@angular/cli": "^1.5.4",
"@angular/compiler-cli": "^5.0.3",
"@angular/cli": "^1.6.1",
"@angular/compiler-cli": "^5.1.2",
"@compodoc/compodoc": "^1.0.4",
"@types/jasmine": "^2.8.2",
"@types/node": "^8.0.53",
Expand All @@ -153,6 +152,6 @@
"ts-node": "~3.3.0",
"tslint": "~5.8.0",
"tslint-microsoft-contrib": "^5.0.1",
"typescript": "^2.6.1"
"typescript": "2.4.2"
}
}
9 changes: 6 additions & 3 deletions src/app/core-ui/material/material.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import {
MatButtonModule, MatCardModule, MatCheckboxModule, MatExpansionModule, MatGridListModule, MatIconModule, MatListModule,
MatButtonModule, MatCardModule, MatCheckboxModule, MatExpansionModule, MatGridListModule, MatIconModule,
MatListModule,
MatMenuModule,
MatProgressBarModule,
MatSidenavModule,
MatSnackBarModule, MatTabsModule, MatToolbarModule, MatRadioModule, MatInputModule,
MatTooltipModule,
MatSelectModule, MatPaginatorModule
MatSelectModule, MatPaginatorModule, MatProgressSpinnerModule, MatDialogModule
} from '@angular/material';

import {A11yModule} from '@angular/cdk/a11y';
Expand Down Expand Up @@ -67,7 +68,9 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
MatRadioModule,
MatSelectModule,
MatInputModule,
MatPaginatorModule
MatPaginatorModule,
MatProgressSpinnerModule,
MatDialogModule
],
declarations: []
})
Expand Down
8 changes: 3 additions & 5 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';

import { RpcModule } from './rpc/rpc.module';

Expand All @@ -19,11 +19,10 @@ import { SnackbarService } from './snackbar/snackbar.service';
@NgModule({
imports: [
CommonModule,
RpcModule.forRoot() // TODO: should be here?
RpcModule.forRoot(), // TODO: should be here?
],
exports: [
HttpModule

HttpClientModule
],
declarations: []
})
Expand All @@ -50,4 +49,3 @@ export { BlockStatusService } from './rpc/blockstatus/blockstatus.service'
export { PeerService } from './rpc/peer/peer.service';
export { SnackbarService } from './snackbar/snackbar.service';
export { StateService } from './state/state.service';

88 changes: 42 additions & 46 deletions src/app/core/rpc/rpc-state/rpc-state.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export class RpcStateClass {

private lastBlockTimeState() {
let _checkLastBlock = false;
this._rpc.state.observe('mediantime').subscribe(
mediantime => {
const lastblocktime = new Date(mediantime * 1000);
if (!_checkLastBlock && new Date().getTime() - (4 * 60 * 1000) > lastblocktime.getTime()) {
setTimeout(() => {
_checkLastBlock = false;
this._rpc.stateCall('getblockchaininfo');
}, 100);
_checkLastBlock = true;
}
});
this._rpc.state.observe('mediantime').subscribe(mediantime => {
const now = new Date().getTime() - (4 * 60 * 1000);
const lastblocktime = new Date(mediantime * 1000);
if (!_checkLastBlock && now > lastblocktime.getTime()) {
_checkLastBlock = true;
setTimeout(() => {
_checkLastBlock = false;
this._rpc.stateCall('getblockchaininfo');
}, 100);
}
});
}

private blockLoop() {
Expand All @@ -44,8 +44,8 @@ export class RpcStateClass {

private walletLockedState() {
this._rpc.state.observe('encryptionstatus')
.subscribe(status => this._rpc.state
.set('locked', ['Locked', 'Unlocked, staking only'].includes(status)));
.subscribe(status => this._rpc.state
.set('locked', ['Locked', 'Unlocked, staking only'].includes(status)));
}

/*
Expand All @@ -54,45 +54,41 @@ export class RpcStateClass {
* update the coldstaking state.
*/
private coldStakeHook() {
this._rpc.state.observe('locked').subscribe(
locked => {
if (locked === false) {
// only available if unlocked
this._rpc.call('walletsettings', ['changeaddress'])
.subscribe(
// set state for coldstaking
response => this._rpc.state.set('ui:coldstaking',
response.changeaddress === 'default' ? false : !!response.changeaddress.coldstakingaddress
),
error => this.log.er('walletsettings changeaddress, returned an error', error));

}
});
this._rpc.state.observe('locked').subscribe(locked => {
if (locked === false) {
// only available if unlocked
this._rpc.call('walletsettings', ['changeaddress'])
.subscribe(
// set state for coldstaking
response => this._rpc.state.set('ui:coldstaking',
response.changeaddress === 'default'
? false
: !!response.changeaddress.coldstakingaddress
),
error => this.log.er('walletsettings changeaddress', error)
);
}
});
}

private initWalletState() {

this._rpc.state.observe('encryptionstatus').take(1)
.subscribe(
status => {
const locked = this._rpc.state.get('locked');
this._rpc.state.observe('encryptionstatus').take(1).subscribe(status => {
const locked = this._rpc.state.get('locked');

if (locked) {
if (locked) {
this._rpc.state.set('ui:walletInitialized', true);
return;
}

this._rpc.call('extkey', ['list']).subscribe(response => {
// check if account is active
if (response.result === 'No keys to list.') {
this._rpc.state.set('ui:walletInitialized', false);
} else {
this._rpc.state.set('ui:walletInitialized', true);
return;
}

this._rpc.call('extkey', ['list'])
.subscribe(
response => {
// check if account is active
if (response.result === 'No keys to list.') {
this._rpc.state.set('ui:walletInitialized', false);
} else {
this._rpc.state.set('ui:walletInitialized', true);
}
},
error => this.log.er('RPC Call returned an error', error));
});
}, error => this.log.er('RPC Call returned an error', error));
});
}
}
4 changes: 2 additions & 2 deletions src/app/core/rpc/rpc.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpModule } from '@angular/http';
import { HttpClient } from '@angular/common/http';

import { RpcModule } from './rpc.module';
import { RpcService } from './rpc.service';
Expand All @@ -9,7 +9,7 @@ describe('RpcService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpModule,
HttpClient,
RpcModule.forRoot()
],
providers: [
Expand Down
35 changes: 19 additions & 16 deletions src/app/core/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Log } from 'ng2-logger';
import { Subject } from 'rxjs/Subject';
import { Headers, Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';

import { Log } from 'ng2-logger';
import { map, catchError } from 'rxjs/operators';

import { IpcService } from '../ipc/ipc.service';
import { StateService } from '../state/state.service';
import { RpcStateClass } from './rpc-state/rpc-state.class';


const MAINNET_PORT = 51735;
const TESTNET_PORT = 51935;

const HOSTNAME = 'localhost';


declare global {
interface Window {
electron: boolean;
Expand Down Expand Up @@ -58,7 +55,7 @@ export class RpcService {
private _rpcState: RpcStateClass;

constructor(
private _http: Http,
private _http: HttpClient,
private _ipc: IpcService,
public state: StateService
) {
Expand All @@ -85,10 +82,12 @@ export class RpcService {
*/
call(method: string, params?: Array<any> | null): Observable<any> {
if (this.isElectron) {
return this._ipc.runCommand('rpc-channel', null, method, params)
.map(response => response && (response.result !== undefined)
? response.result
: response);
return this._ipc.runCommand('rpc-channel', null, method, params).pipe(
map(response => response && (response.result !== undefined)
? response.result
: response
)
);
} else {
// Running in browser, delete?
const postData = JSON.stringify({
Expand All @@ -97,16 +96,20 @@ export class RpcService {
id: 1
});

const headers = new Headers();
const headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic ' + btoa(`${this.username}:${this.password}`));
headers.append('Accept', 'application/json');

return this._http
.post(`http://${this.hostname}:${this.port}`, postData, { headers: headers })
.map(response => response.json().result)
.catch(error => Observable.throw(
typeof error._body === 'object' ? error._body : JSON.parse(error._body)));
.post(`http://${this.hostname}:${this.port}`, postData, { headers: headers })
.pipe(
map((response: any) => response.result),
catchError(error => Observable.throw(typeof error._body === 'object'
? error._body
: JSON.parse(error._body))
)
);
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/app/wallet/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { FlexLayoutModule } from '@angular/flex-layout';
import {
MatButtonModule,
MatDialogModule,
MatExpansionModule,
MatIconModule,
MatInputModule
} from '@angular/material';

import { ClipboardModule } from 'ngx-clipboard';
import { MaterialModule } from '../../core-ui/material/material.module';
import { AccordionModule } from './accordion/accordion.module';

import { HeaderComponent } from './header/header.component';
import { TableComponent } from './table/table.component';
import { GridComponent } from './grid/grid.component';
Expand All @@ -26,13 +33,13 @@ import { DeleteConfirmationModalComponent } from './delete-confirmation-modal/de
],
exports: [
CommonModule,
HttpModule,
FormsModule,
HttpClient,
ClipboardModule,
AccordionModule,
HeaderComponent,
TableComponent,
GridComponent,
AccordionModule
GridComponent
],
entryComponents: [
DeleteConfirmationModalComponent
Expand Down

0 comments on commit dc5a6e9

Please sign in to comment.