Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/daemon modal #70

Merged
merged 4 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/app/core/rpc/rpc.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export class RpcModule {
RPCService,
PeerService,
PassphraseService,
BlockStatusService,
ElectronService
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appeared twice

BlockStatusService
]
};
}
Expand Down
55 changes: 46 additions & 9 deletions src/app/core/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Injectable } from '@angular/core';
import { ElectronService } from 'ngx-electron';
import { Log } from 'ng2-logger';
import { Subject } from 'rxjs/Subject';

import { Headers, Http } from '@angular/http';

import { ModalsService } from '../../modals/modals.service';

const MAINNET_PORT = 51935;
const TESTNET_PORT = 51935;

Expand Down Expand Up @@ -37,7 +41,14 @@ export class RPCService {

public isElectron: boolean = false;

constructor(private http: Http, public electronService: ElectronService) {
private log: any = Log.create('rpc.service');

public modalUpdates: Subject<any> = new Subject<any>();

constructor(
private http: Http,
public electronService: ElectronService
) {
this.isElectron = this.electronService.isElectronApp;
this.poll();
}
Expand Down Expand Up @@ -68,7 +79,13 @@ export class RPCService {
* @returns void
*/

call(instance: Injectable, method: string, params: Array<any> | null, successCB: Function, errorCB?: Function): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readability

call(
instance: Injectable,
method: string,
params: Array<any> | null,
successCB: Function,
errorCB?: Function
): void {
const postData = JSON.stringify({
method: method,
params: params,
Expand All @@ -88,13 +105,23 @@ export class RPCService {
.subscribe(
response => {
successCB.call(instance, response.json().result);
this.modalUpdates.next({
response: response,
electron: this.isElectron
});
},
error => {
if (errorCB) {
errorCB.call(instance, (typeof error['_body'] === 'object' ? error['_body'] : JSON.parse(error['_body'])) )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readability

errorCB.call(instance, (typeof error['_body'] === 'object'
? error['_body']
: JSON.parse(error['_body']))
);
}
// TODO: Call error modal?
console.log('RPC Call returned an error', error);
this.modalUpdates.next({
error: error,
electron: this.isElectron
});
this.log.er('RPC Call returned an error', error);
});
}
}
Expand Down Expand Up @@ -127,8 +154,14 @@ export class RPCService {
* @returns void
*/

register(instance: Injectable, method: string, params: Array<any> | Function | null,
successCB: Function, when: string, errorCB?: Function): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readability

register(
instance: Injectable,
method: string,
params: Array<any> | Function | null,
successCB: Function,
when: string,
errorCB?: Function
): void {
let valid = false;
const _call = {
instance: instance,
Expand Down Expand Up @@ -162,7 +195,9 @@ export class RPCService {
this.call(
element.instance,
element.method,
element.params && element.params.typeOf === 'function' ? element.params() : element.params,
element.params && element.params.typeOf === 'function'
? element.params()
: element.params,
element.successCB,
element.errorCB);
};
Expand All @@ -180,7 +215,9 @@ export class RPCService {
this.call(
element.instance,
element.method,
element.params && element.params.typeOf === 'function' ? element.params() : element.params,
element.params && element.params.typeOf === 'function'
? element.params()
: element.params,
element.successCB,
element.errorCB);
};
Expand Down
10 changes: 10 additions & 0 deletions src/app/modals/daemon/daemon.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="center">
<div *ngIf="message && !message.electron">
you are running Particl in a browser.
</div>
<div *ngIf="message && message.error">
<div *ngIf="message.error.status === 0">
Couldn't connect to Particl Daemon : connection refused
</div>
</div>
</div>
3 changes: 3 additions & 0 deletions src/app/modals/daemon/daemon.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.center {
text-align: center;
}
36 changes: 36 additions & 0 deletions src/app/modals/daemon/daemon.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DaemonComponent } from './daemon.component';

import { SharedModule } from '../../shared/shared.module';
import { RpcModule } from '../../core/rpc/rpc.module';
import { ModalsService } from '../modals.service';

describe('DaemonComponent', () => {
let component: DaemonComponent;
let fixture: ComponentFixture<DaemonComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DaemonComponent ],
imports: [
SharedModule,
RpcModule.forRoot()
],
providers: [
ModalsService
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DaemonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
});
23 changes: 23 additions & 0 deletions src/app/modals/daemon/daemon.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, Inject, forwardRef } from '@angular/core';

import { ModalsService } from '../modals.service';

@Component({
selector: 'app-daemon',
templateUrl: './daemon.component.html',
styleUrls: ['./daemon.component.scss']
})
export class DaemonComponent {

public message: any;

constructor(
@Inject(forwardRef(() => ModalsService)) private _modalsService: ModalsService
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unused? triggering moved to the model.service

) {
}

setData(data: any) {
this.message = data;
}

}
2 changes: 2 additions & 0 deletions src/app/modals/modals.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ModalDirective } from 'ngx-bootstrap/modal';
import { ModalsService } from './modals.service';

import { CreateWalletComponent } from './createwallet/createwallet.component';
import { DaemonComponent } from './daemon/daemon.component';
import { SyncingComponent } from './syncing/syncing.component';
import { UnlockwalletComponent } from './unlockwallet/unlockwallet.component';

Expand All @@ -27,6 +28,7 @@ import { UnlockwalletComponent } from './unlockwallet/unlockwallet.component';
styleUrls: ['./modals.component.scss'],
entryComponents: [
CreateWalletComponent,
DaemonComponent,
SyncingComponent,
UnlockwalletComponent
]
Expand Down
2 changes: 2 additions & 0 deletions src/app/modals/modals.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PassphraseComponent } from './createwallet/passphrase/passphrase.compon
import { PasswordComponent } from './shared/password/password.component';

import { CreateWalletComponent } from './createwallet/createwallet.component';
import { DaemonComponent } from './daemon/daemon.component';
import { SyncingComponent } from './syncing/syncing.component';
import { UnlockwalletComponent } from './unlockwallet/unlockwallet.component';

Expand All @@ -28,6 +29,7 @@ import { UnlockwalletComponent } from './unlockwallet/unlockwallet.component';
PassphraseComponent,
PasswordComponent,
CreateWalletComponent,
DaemonComponent,
SyncingComponent,
UnlockwalletComponent
],
Expand Down
19 changes: 16 additions & 3 deletions src/app/modals/modals.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Subject } from 'rxjs/Subject';
import { Log } from 'ng2-logger';

import { BlockStatusService } from '../core/rpc/rpc.module';
import { RPCService } from '../core/rpc/rpc.module';

import { CreateWalletComponent } from './createwallet/createwallet.component';
import { DaemonComponent } from './daemon/daemon.component';
import { SyncingComponent } from './syncing/syncing.component';
import { UnlockwalletComponent } from './unlockwallet/unlockwallet.component';

Expand All @@ -23,17 +25,26 @@ export class ModalsService {

messages: Object = {
createWallet: CreateWalletComponent,
daemon: DaemonComponent,
syncing: SyncingComponent,
unlock: UnlockwalletComponent
};

constructor (
private _statusService: BlockStatusService
private _blockStatusService: BlockStatusService,
private _rpcService: RPCService
) {
this._statusService.statusUpdates.asObservable().subscribe(status => {
this._blockStatusService.statusUpdates.asObservable().subscribe(status => {
this.progress.next(status.syncPercentage);
this.needToOpenModal(status);
});
this._rpcService.modalUpdates.asObservable().subscribe(status => {
if (status.error) {
this.open('daemon', status);
} else if (this.modal === this.messages['daemon']) {
this.close();
}
});
}

open(modal: string, data?: Object): void {
Expand Down Expand Up @@ -71,7 +82,9 @@ export class ModalsService {

needToOpenModal(status: any) {
// Open syncing Modal
if (!this.isOpen && (status.networkBH <= 0 || status.internalBH <= 0 || status.networkBH - status.internalBH > 50)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readability

if (!this.isOpen && (status.networkBH <= 0
|| status.internalBH <= 0
|| status.networkBH - status.internalBH > 50)) {
this.open('syncing');
}
}
Expand Down