2021-02-27 04:19:56 +07:00
|
|
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
|
|
|
import { Observable, combineLatest } from 'rxjs';
|
2021-03-14 02:42:14 +07:00
|
|
|
import { filter, map } from 'rxjs/operators';
|
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2021-03-05 15:38:46 +07:00
|
|
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
2021-02-27 04:19:56 +07:00
|
|
|
import { BisqApiService } from '../bisq-api.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bisq-dashboard',
|
|
|
|
templateUrl: './bisq-dashboard.component.html',
|
|
|
|
styleUrls: ['./bisq-dashboard.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
export class BisqDashboardComponent implements OnInit {
|
|
|
|
tickers$: Observable<any>;
|
2021-03-14 02:42:14 +07:00
|
|
|
allowCryptoCoins = ['usdc', 'l-btc', 'bsq'];
|
2021-02-27 04:19:56 +07:00
|
|
|
|
|
|
|
constructor(
|
2021-03-05 15:38:46 +07:00
|
|
|
private websocketService: WebsocketService,
|
2021-02-27 04:19:56 +07:00
|
|
|
private bisqApiService: BisqApiService,
|
2021-03-14 02:42:14 +07:00
|
|
|
private stateService: StateService,
|
2021-02-27 04:19:56 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-03-05 15:38:46 +07:00
|
|
|
this.websocketService.want(['blocks']);
|
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
this.tickers$ = combineLatest([
|
|
|
|
this.bisqApiService.getMarketsTicker$(),
|
2021-02-28 17:18:29 +07:00
|
|
|
this.bisqApiService.getMarkets$(),
|
2021-03-10 23:02:55 +07:00
|
|
|
this.bisqApiService.getMarketVolumesByTime$('7d'),
|
2021-02-27 04:19:56 +07:00
|
|
|
])
|
|
|
|
.pipe(
|
2021-02-28 17:18:29 +07:00
|
|
|
map(([tickers, markets, volumes]) => {
|
2021-03-14 02:42:14 +07:00
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
const newTickers = [];
|
|
|
|
for (const t in tickers) {
|
2021-03-14 02:42:14 +07:00
|
|
|
|
|
|
|
if (!this.stateService.env.OFFICIAL_BISQ_MARKETS) {
|
|
|
|
const pair = t.split('_');
|
|
|
|
if (pair[1] === 'btc' && this.allowCryptoCoins.indexOf(pair[0]) === -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
tickers[t].pair_url = t;
|
|
|
|
tickers[t].pair = t.replace('_', '/').toUpperCase();
|
|
|
|
tickers[t].market = markets[t];
|
2021-02-28 17:18:29 +07:00
|
|
|
tickers[t].volume = volumes[t];
|
2021-02-27 04:19:56 +07:00
|
|
|
newTickers.push(tickers[t]);
|
|
|
|
}
|
2021-02-28 17:18:29 +07:00
|
|
|
|
2021-03-10 23:02:55 +07:00
|
|
|
newTickers.sort((a, b) => (b.volume && b.volume.num_trades || 0) - (a.volume && a.volume.num_trades || 0));
|
2021-02-28 17:18:29 +07:00
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
return newTickers;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
trackByFn(index: number) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|