-
Notifications
You must be signed in to change notification settings - Fork 89
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
||
|
@@ -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(); | ||
} | ||
|
@@ -68,7 +79,13 @@ export class RPCService { | |
* @returns void | ||
*/ | ||
|
||
call(instance: Injectable, method: string, params: Array<any> | null, successCB: Function, errorCB?: Function): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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'])) ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); | ||
} | ||
} | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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); | ||
}; | ||
|
@@ -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); | ||
}; | ||
|
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.center { | ||
text-align: center; | ||
} |
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(); | ||
}); | ||
}); |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
|
@@ -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 { | ||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appeared twice