Sort table by number of trades as default sort option, make other columns sortable
This commit is contained in:
parent
2d4dff6de8
commit
04ec5e9564
@ -45,7 +45,7 @@ import { FeesBoxComponent } from './components/fees-box/fees-box.component';
|
|||||||
import { DashboardComponent } from './dashboard/dashboard.component';
|
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||||
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
|
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
|
||||||
import { faAngleDown, faAngleUp, faBolt, faChartArea, faCogs, faCubes, faDatabase, faExchangeAlt, faInfoCircle,
|
import { faAngleDown, faAngleUp, faBolt, faChartArea, faCogs, faCubes, faDatabase, faExchangeAlt, faInfoCircle,
|
||||||
faLink, faList, faSearch, faTachometerAlt, faThList, faTint, faTv, faAngleDoubleDown, faAngleDoubleUp } from '@fortawesome/free-solid-svg-icons';
|
faLink, faList, faSearch, faTachometerAlt, faThList, faTint, faTv, faAngleDoubleDown, faAngleDoubleUp, faSort, faChevronDown } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { ApiDocsComponent } from './components/api-docs/api-docs.component';
|
import { ApiDocsComponent } from './components/api-docs/api-docs.component';
|
||||||
import { TermsOfServiceComponent } from './components/terms-of-service/terms-of-service.component';
|
import { TermsOfServiceComponent } from './components/terms-of-service/terms-of-service.component';
|
||||||
import { StorageService } from './services/storage.service';
|
import { StorageService } from './services/storage.service';
|
||||||
@ -129,5 +129,6 @@ export class AppModule {
|
|||||||
library.addIcons(faExchangeAlt);
|
library.addIcons(faExchangeAlt);
|
||||||
library.addIcons(faAngleDoubleUp);
|
library.addIcons(faAngleDoubleUp);
|
||||||
library.addIcons(faAngleDoubleDown);
|
library.addIcons(faAngleDoubleDown);
|
||||||
|
library.addIcons(faChevronDown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@
|
|||||||
|
|
||||||
<table class="table table-borderless table-striped">
|
<table class="table table-borderless table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Currency</th>
|
<th>Currency <button [disabled]="(sort$ | async) === 'name'" class="btn btn-link btn-sm" (click)="sort('name')"><fa-icon [icon]="['fas', 'chevron-down']" [fixedWidth]="true"></fa-icon></button></th>
|
||||||
<th>Price</th>
|
<th>Price</th>
|
||||||
<th>Volume (7d)</th>
|
<th>Volume (7d) <button [disabled]="(sort$ | async) === 'volumes'" class="btn btn-link btn-sm" (click)="sort('volumes')"><fa-icon [icon]="['fas', 'chevron-down']" [fixedWidth]="true"></fa-icon></button></th>
|
||||||
<th>Trades (7d)</th>
|
<th>Trades (7d) <button [disabled]="(sort$ | async) === 'trades'" class="btn btn-link btn-sm" (click)="sort('trades')"><fa-icon [icon]="['fas', 'chevron-down']" [fixedWidth]="true"></fa-icon></button></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody *ngIf="tickers.value; else loadingTmpl">
|
<tbody *ngIf="tickers.value; else loadingTmpl">
|
||||||
<tr *ngFor="let ticker of tickers.value; trackBy: trackByFn;">
|
<tr *ngFor="let ticker of tickers.value; trackBy: trackByFn;">
|
||||||
<td><a [routerLink]="['/market' | relativeUrl, ticker.pair_url]">{{ ticker.market.rtype === 'crypto' ? ticker.market.lname : ticker.market.rname }} ({{ ticker.market.rtype === 'crypto' ? ticker.market.lsymbol : ticker.market.rsymbol }})</a></td>
|
<td><a [routerLink]="['/market' | relativeUrl, ticker.pair_url]">{{ ticker.name }})</a></td>
|
||||||
<td>
|
<td>
|
||||||
<app-fiat *ngIf="ticker.market.rtype === 'crypto'; else fiat" [value]="ticker.last * 100000000"></app-fiat>
|
<app-fiat *ngIf="ticker.market.rtype === 'crypto'; else fiat" [value]="ticker.last * 100000000"></app-fiat>
|
||||||
<ng-template #fiat>
|
<ng-template #fiat>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||||
import { Observable, combineLatest } from 'rxjs';
|
import { Observable, combineLatest, BehaviorSubject, of } from 'rxjs';
|
||||||
import { map, share } from 'rxjs/operators';
|
import { map, share, switchMap } from 'rxjs/operators';
|
||||||
import { SeoService } from 'src/app/services/seo.service';
|
import { SeoService } from 'src/app/services/seo.service';
|
||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
import { WebsocketService } from 'src/app/services/websocket.service';
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
||||||
@ -17,6 +17,7 @@ export class BisqDashboardComponent implements OnInit {
|
|||||||
tickers$: Observable<any>;
|
tickers$: Observable<any>;
|
||||||
volumes$: Observable<any>;
|
volumes$: Observable<any>;
|
||||||
trades$: Observable<Trade[]>;
|
trades$: Observable<Trade[]>;
|
||||||
|
sort$ = new BehaviorSubject<string>('trades');
|
||||||
|
|
||||||
allowCryptoCoins = ['usdc', 'l-btc', 'bsq'];
|
allowCryptoCoins = ['usdc', 'l-btc', 'bsq'];
|
||||||
|
|
||||||
@ -81,12 +82,21 @@ export class BisqDashboardComponent implements OnInit {
|
|||||||
mappedTicker.pair = t.replace('_', '/').toUpperCase();
|
mappedTicker.pair = t.replace('_', '/').toUpperCase();
|
||||||
mappedTicker.market = markets[t];
|
mappedTicker.market = markets[t];
|
||||||
mappedTicker.volume = volumes[t];
|
mappedTicker.volume = volumes[t];
|
||||||
|
mappedTicker.name = `${mappedTicker.market.rtype === 'crypto' ? mappedTicker.market.lname : mappedTicker.market.rname} (${mappedTicker.market.rtype === 'crypto' ? mappedTicker.market.lsymbol : mappedTicker.market.rsymbol}`;
|
||||||
newTickers.push(mappedTicker);
|
newTickers.push(mappedTicker);
|
||||||
}
|
}
|
||||||
|
|
||||||
newTickers.sort((a, b) => (b.volume && b.volume.num_trades || 0) - (a.volume && a.volume.num_trades || 0));
|
|
||||||
|
|
||||||
return newTickers;
|
return newTickers;
|
||||||
|
}),
|
||||||
|
switchMap((tickers) => combineLatest([this.sort$, of(tickers)])),
|
||||||
|
map(([sort, tickers]) => {
|
||||||
|
if (sort === 'trades') {
|
||||||
|
tickers.sort((a, b) => (b.volume && b.volume.num_trades || 0) - (a.volume && a.volume.num_trades || 0));
|
||||||
|
} else if (sort === 'volumes') {
|
||||||
|
tickers.sort((a, b) => (b.volume && b.volume.volume || 0) - (a.volume && a.volume.volume || 0));
|
||||||
|
} else if (sort === 'name') {
|
||||||
|
tickers.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
}
|
||||||
|
return tickers;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -96,15 +106,20 @@ export class BisqDashboardComponent implements OnInit {
|
|||||||
])
|
])
|
||||||
.pipe(
|
.pipe(
|
||||||
map(([trades, markets]) => {
|
map(([trades, markets]) => {
|
||||||
return trades.map((trade => {
|
return trades.map((trade => {
|
||||||
trade._market = markets[trade.market];
|
trade._market = markets[trade.market];
|
||||||
return trade;
|
return trade;
|
||||||
}));
|
}));
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
trackByFn(index: number) {
|
trackByFn(index: number) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort(by: string) {
|
||||||
|
this.sort$.next(by);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user