Skip to content

Commit

Permalink
Adds a new component to render all enabled currency tickers. Will sor…
Browse files Browse the repository at this point in the history
…t out later.

Reduces currency ticker to accept a ticker object so that it doesn't need to listen to events
  • Loading branch information
gloriousCode committed Sep 24, 2017
1 parent 67d7409 commit e0921a8
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 35 deletions.
9 changes: 5 additions & 4 deletions web/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import { DashboardComponent } from './pages/dashboard/dashboard.component';

import { NavbarComponent } from './shared/navbar/navbar.component';
import { ExchangeCurrencyTickerComponent } from './shared/exchange-currency-ticker/exchange-currency-ticker.component';


import { AllEnabledCurrencyTickersComponent } from './shared/all-enabled-currency-tickers/all-enabled-currency-tickers.component';
//services
import { WebsocketService } from './services/websocket/websocket.service';
import { WebsocketHandlerService } from './services/websocket-handler/websocket-handler.service';
import { ElectronService } from './providers/electron.service';

//Routing
import { AppRoutingModule } from './app-routing.module';

import * as Rx from 'rxjs/Rx';
Expand All @@ -48,7 +48,8 @@ import * as Rx from 'rxjs/Rx';
NavbarComponent,
SettingsComponent,
DashboardComponent,
ExchangeCurrencyTickerComponent
ExchangeCurrencyTickerComponent,
AllEnabledCurrencyTickersComponent
],
imports: [
BrowserModule,
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/pages/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<app-exchange-currency-ticker [exchange]="exchange" [currency]="currency"></app-exchange-currency-ticker>
<app-all-enabled-currency-tickers></app-all-enabled-currency-tickers>
2 changes: 0 additions & 2 deletions web/src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./dashboard.component.scss'],
})
export class DashboardComponent implements OnInit {
exchange:string = "LocalBitcoins";
currency:string = "BTCUSD";
constructor()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div style="width:1000px">
<md-grid-list cols="3" rowHeight="2:1" >
<md-grid-tile *ngFor="let ticker of tickerCards">
<app-exchange-currency-ticker [ticker]="ticker" ></app-exchange-currency-ticker>
</md-grid-tile>
</md-grid-list>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.example-form {
min-width: 150px;
width: 100%;
}

.example-full-width {
width: 100%;
}

.exchange-card {
margin-bottom: 20px;
width: 300px;
}

md-grid-tile {
width:300px;
padding:10px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { AllEnabledCurrencyTickersComponent } from './all-enabled-currency-tickers.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AllEnabledCurrencyTickersComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AllEnabledCurrencyTickersComponent);
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,82 @@
import { Component, OnInit } from '@angular/core';
import { WebsocketHandlerService } from './../../services/websocket-handler/websocket-handler.service';

@Component({
selector: 'app-all-enabled-currency-tickers',
templateUrl: './all-enabled-currency-tickers.component.html',
styleUrls: ['./all-enabled-currency-tickers.component.scss']
})
export class AllEnabledCurrencyTickersComponent implements OnInit {
private ws: WebsocketHandlerService;
allCurrencies:ExchangeCurrency[];
tickerCards: TickerUpdate[];



constructor(private websocketHandler: WebsocketHandlerService) {
this.ws = websocketHandler;
this.allCurrencies = <ExchangeCurrency[]>[];
this.tickerCards = <TickerUpdate[]>[];
this.ws.messages.subscribe(msg => {
if (msg.Event === 'ticker_update') {
var modal = <ExchangeCurrency>{};
modal.currencyPair = msg.data.CurrencyPair;
modal.exchangeName = msg.Exchange;
var found = false;

for(var i = 0; i< this.allCurrencies.length; i++) {
if(this.allCurrencies[i].currencyPair === msg.data.CurrencyPair &&
this.allCurrencies[i].exchangeName === msg.Exchange) {
found = true;
}
}
if(!found) {
//time to add
var ticker = <TickerUpdate>msg.data;
ticker.Exchange = msg.Exchange;
this.tickerCards.push(ticker);
this.allCurrencies.push(modal);
console.log(JSON.stringify(this.allCurrencies));
} else {
console.log('deleting');
for(var i = 0; i< this.tickerCards.length; i++) {
if(this.tickerCards[i].Exchange === msg.Exchange
&& this.tickerCards[i].CurrencyPair === msg.data.CurrencyPair) {
this.tickerCards.slice(this.tickerCards.indexOf(this.tickerCards[i]));
var ticker = <TickerUpdate>msg.data;
this.tickerCards.splice(i,0,ticker);
}
}
}
}
});
}

ngOnInit() {
}

}

export interface ExchangeCurrency {
currencyPair: string;
exchangeName:string;
}

export interface CurrencyPair {
delimiter: string;
first_currency: string;
second_currency: string;
}

export interface TickerUpdate {
Pair: CurrencyPair;
CurrencyPair: string;
Last: number;
High: number;
Low: number;
Bid: number;
Ask: number;
Volume: number;
PriceATH: number;
Exchange:string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

.exchange-card {
margin-bottom: 20px;
width: 500px;
width: 300px;
}

.md-fab {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
import { Component, OnInit, Input } from '@angular/core';
import { WebsocketHandlerService } from './../../services/websocket-handler/websocket-handler.service';


@Component({
selector: 'app-exchange-currency-ticker',
templateUrl: './exchange-currency-ticker.component.html',
styleUrls: ['./exchange-currency-ticker.component.scss'],
})
export class ExchangeCurrencyTickerComponent implements OnInit {
@Input('exchange') exchange: string;
@Input('currency') currency: string;
ticker: TickerUpdate;
private ws: WebsocketHandlerService;
@Input('ticker') ticker: TickerUpdate;

constructor() {}

constructor(private websocketHandler: WebsocketHandlerService) {
this.ws = websocketHandler;
this.ws.messages.subscribe(msg => {
if (msg.Event === 'ticker_update') {
if(msg.Exchange !== this.exchange || msg.data.CurrencyPair !== this.currency) {
console.log('Exg1:' + msg.Exchange + ' exg2:' + this.exchange);
console.log('Cur1:' + msg.data.CurrencyPair + ' Cur2:' + this.currency);
return;
}
console.log(msg);
console.log('Data:' + JSON.stringify(msg));
this.ticker = <TickerUpdate>msg.data;

this.ticker.Exchange = msg.Exchange;
}
});
}

ngOnInit() {
}
ngOnInit() { }

}


export interface CurrencyPair {
delimiter: string;
first_currency: string;
Expand All @@ -55,3 +32,4 @@ export interface TickerUpdate {
PriceATH: number;
Exchange:string;
}

0 comments on commit e0921a8

Please sign in to comment.