Skip to content

Commit

Permalink
Merge branch 'master' into feature/tx
Browse files Browse the repository at this point in the history
  • Loading branch information
rynomster committed Jun 30, 2017
2 parents 58d142a + 9b6df8a commit ad7f011
Show file tree
Hide file tree
Showing 59 changed files with 1,712 additions and 66 deletions.
38 changes: 35 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,45 @@ before_install:
- sh -e /etc/init.d/xvfb start

before_script:
- npm install -g @angular/cli
- npm install
- ng build
- npm install -g @angular/cli
- npm install

script:
- echo 'Build Dist' && echo -en 'travis_fold:start:script.build\\r'

- ng build --base-href="./"

- echo -en 'travis_fold:end:script.build\\r'
- echo 'Lint Codebase' && echo -en 'travis_fold:start:script.lint\\r'

- ng lint

- echo -en 'travis_fold:end:script.lint\\r'
- echo 'Test Codebase' && echo -en 'travis_fold:start:script.test\\r'

- ng test --single-run --code-coverage

- echo -en 'travis_fold:end:script.test\\r'
- echo 'Package Dist' && echo -en 'travis_fold:start:script.dist\\r'

- cd dist
- zip -r $TRAVIS_BUILD_DIR/dist.zip *

- cd $TRAVIS_BUILD_DIR
- sha256sum $TRAVIS_BUILD_DIR/dist.zip > $TRAVIS_BUILD_DIR/dist.zip.sha256sum.txt

- echo -en 'travis_fold:end:script.dist\\r'

after_script:
- npm run coveralls

#deploy:
# - provider: releases
# api-key:
# secure: <>
# file:
# - $TRAVIS_BUILD_DIR/dist.zip
# - $TRAVIS_BUILD_DIR/dist.zip.sha256sum.txt
# overwrite: true
# on:
# tags: true
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ git clone https://github.com/particl/partgui
cd partgui
npm install
```
* Run `ng serve` for as dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
* Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## With real rpc data
### Start
```
./particld -daemon -testnet -debug -rpcuser=test -rpcpassword=test -rpccorsdomain=http://localhost:4200
```

### Stop
```
./particl-cli -rpcuser=test -rpcpassword=test stop
```

You can now navigate to `http://localhost:4200/`.

## Code scaffolding

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@angular/platform-browser": "^4.1.3",
"@angular/platform-browser-dynamic": "^4.1.3",
"@angular/router": "^4.1.3",
"angular2-qrcode": "^2.0.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
Expand Down
12 changes: 9 additions & 3 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</a>
</accordion-heading>
<hr>
<a class="item" routerLinkActive="active" routerLink="#">
<a class="item" routerLinkActive="active" routerLink="/wallet/receive">
<span class="icon fa fa-arrow-left"></span>
Receive
</a>
Expand Down Expand Up @@ -58,6 +58,12 @@
Settings
</a>
</accordion-group>
<div>
<span><button (click)="firsttime()">firsttime</button></span>
<span><button (click)="syncing()">syncing</button></span>
<span><button (click)="passphrase()">passphrase</button></span>
<span><button (click)="recover()">recover</button></span>
</div>
</accordion>

</sidebar>
Expand All @@ -80,5 +86,5 @@
<sidebar position="bottom" #sidebarBottom></sidebar>

<router-outlet></router-outlet>

</sidebar-container>
<app-modals></app-modals>
</sidebar-container>
6 changes: 3 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed, async } from '@angular/core/testing';
import { APP_BASE_HREF } from '@angular/common'
import { APP_BASE_HREF } from '@angular/common';

import { RouterTestingModule } from '@angular/router/testing';

Expand All @@ -19,11 +19,11 @@ describe('AppComponent', () => {
}).compileComponents();
}));

it('should create the app', async(() => {
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
});

/*
it('should render title in a h1 tag', async(() => {
Expand Down
35 changes: 32 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { Observable } from 'rxjs/Rx';

import { AppService } from './app.service';
import { WindowService } from './core/window.service';

import { SettingsService } from './settings/settings.service';
// Modal example
import { ModalsService } from './modals/modals.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss', './app.component.controls.scss'],
providers: [SettingsService]
providers: [
SettingsService
]
})
export class AppComponent implements OnInit {
isCollapsed: boolean = true;
Expand All @@ -23,7 +26,9 @@ export class AppComponent implements OnInit {
private _route: ActivatedRoute,
private appService: AppService,
public window: WindowService,
private _settingsService: SettingsService
private _settingsService: SettingsService,
// Modal example
private _modalsService: ModalsService
) { }

ngOnInit() {
Expand All @@ -41,5 +46,29 @@ export class AppComponent implements OnInit {
.filter(route => route.outlet === 'primary')
.flatMap(route => route.data)
.subscribe(data => this.title = data['title']);

this.appService.rpc.poll();
}

// Modal examples
firsttime() {
this._modalsService.open('firstTime');
this._modalsService.updateProgress(33);
}

syncing() {
this._modalsService.open('syncing');
this._modalsService.updateProgress(48);
}

passphrase() {
this._modalsService.open('passphrase');
this._modalsService.updateProgress(99);
}

recover() {
this._modalsService.open('recover');
this._modalsService.updateProgress(100);
}
// End Modal Examples
}
7 changes: 6 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { NgxElectronModule } from 'ngx-electron';
import { SharedModule } from './shared/shared.module';
import { SidebarModule } from './core/sidebar/sidebar.module';
import { WalletModule } from './wallet/wallet.module';
import { ModalsModule } from './modals/modals.module';

import { WindowService } from './core/window.service';

import { AppComponent } from './app.component';
import { AppService } from './app.service';
import { RPCService } from './core/rpc/rpc.service';
import { StatusComponent } from './core/status/status.component';
import { OverviewComponent } from './overview/overview.component';
import { SettingsComponent } from './settings/settings.component';
Expand All @@ -37,13 +39,16 @@ const routes: Routes = [
CollapseModule.forRoot(),
PaginationModule.forRoot(),
RouterModule.forRoot(routes),
ModalModule.forRoot(),
SharedModule,
SidebarModule.forRoot(),
WalletModule.forRoot()
WalletModule.forRoot(),
ModalsModule
],
providers: [
WindowService,
AppService,
RPCService
],
bootstrap: [ AppComponent ]
})
Expand Down
1 change: 0 additions & 1 deletion src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TestBed, inject } from '@angular/core/testing';
import { APP_BASE_HREF } from '@angular/common';

import { AppService } from './app.service';

import { AppModule } from './app.module';

describe('AppService', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from '@angular/core';

import { ElectronService } from 'ngx-electron';
import { RPCService } from './core/rpc/rpc.service';

@Injectable()
export class AppService {
public isElectron: boolean = false;

constructor(public electronService: ElectronService) {
this.isElectron = this.electronService.isElectronApp;
constructor(public rpc: RPCService) {
this.isElectron = this.rpc.electronService.isElectronApp;
rpc.postConstruct(this);
}

}
14 changes: 10 additions & 4 deletions src/app/core/rpc/rpc.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpModule } from '@angular/http';

import { RpcService } from './rpc.service';
import { RPCService } from './rpc.service';
import { ElectronService } from 'ngx-electron';

describe('RpcService', () => {
describe('RPCService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [RpcService]
imports: [HttpModule],
providers: [
RPCService,
ElectronService
]
});
});

it('should ...', inject([RpcService], (service: RpcService) => {
it('should be created', inject([RPCService], (service: RPCService) => {
expect(service).toBeTruthy();
}));
});
99 changes: 97 additions & 2 deletions src/app/core/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,103 @@
import { Injectable } from '@angular/core';
import { ElectronService } from 'ngx-electron';

import { Headers, Http } from '@angular/http';
import { AppService } from 'app/app.service';

const MAINNET_PORT = 51935;
const TESTNET_PORT = 51935;

const HOSTNAME = 'localhost';

@Injectable()
export class RpcService {
export class RPCService {
private hostname: String = HOSTNAME; // TODO: URL Flag / Settings
private port: number = TESTNET_PORT; // TODO: Mainnet / testnet flag...

private username: string = 'test';
private password: string = 'test';

private _appService: AppService;
private _callOnBlock: Array<any> = [];
private _callOnTransaction: Array<any> = [];

private _pollTimout: NodeJS.Timer;

constructor(private http: Http, public electronService: ElectronService) { }

postConstruct(appService: AppService) { // Gets rid of circular dependency.. We could possibly handle this better..
this._appService = appService;
}

call(instance: Injectable, method: string, params: Array<any> | null, callback: Function): void {
const postData = JSON.stringify({
method: method,
params: params,
id: 1
});
const headers = new Headers();

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

if (this._appService.isElectron) {
// TODO: electron.ipcCall
} else {
this.http
.post(`http://${this.hostname}:${this.port}`, postData, { headers: headers })
.subscribe(
response => {
callback.call(instance, response.json().result);
},
error => {
// TODO: Call error modal?
console.log('RPC Call returned an error', error);
});
}
}

register(instance: Injectable, method: string, params: Array<any> | Function | null,
callback: Function, when: string): void {
let valid = false;
const _call = {
instance: instance,
method: method,
params: params,
callback: callback
};
if (when.indexOf('block') !== -1 || when.indexOf('both') !== -1) {
this._callOnBlock.push(_call);
valid = true;
}
if (when.indexOf('tx') !== -1 || when.indexOf('both') !== -1) {
this._callOnTransaction.push(_call);
valid = true;
}
}

poll(): void {
// TODO: Actual polling... Check block height and last transaction
const _call = (element) => {
this.call(
element.instance,
element.method,
element.params && element.params.typeOf === 'function' ? element.params() : element.params,
element.callback);
};

this._callOnBlock.forEach(_call);
this._callOnTransaction.forEach(_call);
this._pollTimout = setTimeout(() => { this.poll(); }, 3000);
}

startPolling(): void {
clearTimeout(this._pollTimout);
this.poll();
}

constructor() { }
stopPolling(): void {
clearTimeout(this._pollTimout);
}

}

0 comments on commit ad7f011

Please sign in to comment.